Skip to content

Replace RawSerial as it has been deprecated #12109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TESTS/mbed_drivers/flashiap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#else

#include "utest/utest.h"
#include "utest/utest_serial.h"
#include "utest/utest_print.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"
#include "FlashIAP.h"
Expand Down
1 change: 1 addition & 0 deletions TESTS/mbed_hal/trng/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "base64b.h"
#include "pithy.h"
#include <stdio.h>
#include <string.h>
#include "mbedtls/config.h"
#include "mbedtls/platform.h"

Expand Down
1 change: 1 addition & 0 deletions TESTS/psa/entropy_inject/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "entropy.h"
#include "entropy_poll.h"
#include "psa/crypto.h"
#include <string.h>

/* MAX value support macro */
#if !defined(MAX)
Expand Down
1 change: 1 addition & 0 deletions TESTS/psa/spm_smoke/COMPONENT_NSPE/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "utest.h"
#include "psa/client.h"
#include "psa_manifest/sid.h"
#include <string.h>

#if defined(TARGET_TFM)
#define PSA_MAX_IOVEC 4
Expand Down
5 changes: 3 additions & 2 deletions TEST_APPS/device/nanostack_mac_tester/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#endif

extern mac_api_s *mac_interface;
RawSerial pc(USBTX, USBRX);
UnbufferedSerial pc(USBTX, USBRX);
osThreadId_t main_thread;
static CircularBuffer<uint8_t, RX_BUFFER_SIZE> rx_buffer;
static uint8_t ns_heap[HEAP_FOR_MAC_TESTER_SIZE];
Expand All @@ -68,7 +68,8 @@ static void app_heap_error_handler(heap_fail_t event)

static void rx_interrupt(void)
{
uint8_t c = pc.getc();
uint8_t c;
pc.read(&c, 1);
rx_buffer.push(c);
if (main_thread != NULL) {
osThreadFlagsSet(main_thread, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort;

#if DEVICE_SERIAL
#if DEVICE_SERIAL_FC
#include "hal/serial_api.h"
struct UARTMaps {
static const PinMap *maps[];
static const char *const pin_type_names[];
Expand Down
3 changes: 0 additions & 3 deletions drivers/RawSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include <cstdarg>

namespace mbed {
/** \defgroup drivers-public-api-uart UART
* \ingroup drivers-public-api
*/

/**
* \defgroup drivers_RawSerial RawSerial class
Expand Down
9 changes: 9 additions & 0 deletions drivers/UnbufferedSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@


namespace mbed {
/** \defgroup drivers-public-api-uart UART
* \ingroup drivers-public-api
*/

/**
* \defgroup drivers_UnbufferedSerial UnbufferedSerial class
Expand Down Expand Up @@ -152,6 +155,12 @@ class UnbufferedSerial:
*/
virtual short poll(short events) const;

using SerialBase::readable;
using SerialBase::writeable;
using SerialBase::format;
using SerialBase::attach;
using SerialBase::baud;

#if DEVICE_SERIAL_FC
// For now use the base enum - but in future we may have extra options
// such as XON/XOFF or manual GPIO RTSCTS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
while (i < len + 1) {
uint8_t to_write = i == 0 ? type : pData[i - 1];
while (uart.writeable() == 0);
uart.putc(to_write);
uart.write(&to_write, 1);
++i;
}
return len;
Expand All @@ -62,8 +62,10 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
void H4TransportDriver::on_controller_irq()
{
while (uart.readable()) {
uint8_t char_received = uart.getc();
on_data_received(&char_received, 1);
uint8_t char_received;
if (uart.read(&char_received, 1)) {
on_data_received(&char_received, 1);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ class H4TransportDriver : public CordioHCITransportDriver {
private:
void on_controller_irq();

// Use RawSerial as opposed to Serial as we don't require the locking primitives
// provided by the Serial class (access to the UART should be exclusive to this driver)
// Furthermore, we access the peripheral in interrupt context which would clash
// with Serial's locking facilities
RawSerial uart;
// Use UnbufferedSerial as we don't require locking primitives.
// We access the peripheral in interrupt context.
UnbufferedSerial uart;
PinName cts;
PinName rts;
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void greentea_send_kv(const char * key, const char * val);
int greentea_parse_kv(char * key, char * val,
const int key_len, const int val_len);
int greentea_getc();
void greentea_putc(int c);
void greentea_write_string(const char *str);

#ifdef __cplusplus
}
Expand Down
27 changes: 0 additions & 27 deletions features/frameworks/greentea-client/source/greentea_serial.cpp

This file was deleted.

83 changes: 43 additions & 40 deletions features/frameworks/greentea-client/source/greentea_test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
* limitations under the License.
*/

#if DEVICE_SERIAL

#include <ctype.h>
#include <cstdio>
#include <string.h>
#include "greentea-client/test_env.h"
#include "greentea-client/greentea_serial.h"
#include "greentea-client/greentea_metrics.h"
#include "mbed_trace.h"
#include "platform/mbed_retarget.h"

/**
* Generic test suite transport protocol keys
Expand Down Expand Up @@ -59,7 +57,6 @@ static void greentea_notify_timeout(const int);
static void greentea_notify_hosttest(const char *);
static void greentea_notify_completion(const int);
static void greentea_notify_version();
static void greentea_write_string(const char *str);

/** \brief Handle the handshake with the host
* \details This is contains the shared handhshake functionality that is used between
Expand Down Expand Up @@ -212,55 +209,49 @@ void greentea_notify_coverage_end() {
*
* This function writes the preamble "{{" which is required
* for key-value comunication between the target and the host.
* This uses a Rawserial object, greentea_serial, which provides
* a direct interface to the USBTX and USBRX serial pins and allows
* the direct writing of characters using the putc() method.
* This uses greentea_putc which allows the direct writing of characters
* using the write() method.
* This suite of functions are provided to allow for serial communication
* to the host from within a thread/ISR.
*
*/
inline void greentea_write_preamble()
static void greentea_write_preamble()
{
greentea_serial->putc('{');
greentea_serial->putc('{');
greentea_putc('{');
greentea_putc('{');
}

/**
* \brief Write the postamble characters to the serial port
*
* This function writes the postamble "{{\n" which is required
* for key-value comunication between the target and the host.
* This uses a Rawserial object, greentea_serial, which provides
* a direct interface to the USBTX and USBRX serial pins and allows
* the direct writing of characters using the putc() method.
* This uses greentea_putc which allows the direct writing of characters
* using the write() method.
* This suite of functions are provided to allow for serial communication
* to the host from within a thread/ISR.
*
*/
inline void greentea_write_postamble()
static void greentea_write_postamble()
{
greentea_serial->putc('}');
greentea_serial->putc('}');
greentea_serial->putc('\r');
greentea_serial->putc('\n');
greentea_putc('}');
greentea_putc('}');
greentea_putc('\r');
greentea_putc('\n');
}

/**
* \brief Write a string to the serial port
*
* This function writes a '\0' terminated string from the target
* to the host. It writes directly to the serial port using the
* greentea_serial, Rawserial object.
* the write() method.
*
* \param str - string value
*
*/
inline void greentea_write_string(const char *str)
void greentea_write_string(const char *str)
{
while (*str != '\0') {
greentea_serial->putc(*str);
str ++;
}
write(STDOUT_FILENO, str, strlen(str));
}


Expand All @@ -270,21 +261,21 @@ inline void greentea_write_string(const char *str)
* This function writes an integer value from the target
* to the host. The integer value is converted to a string and
* and then written character by character directly to the serial
* port using the greentea_serial, Rawserial object.
* port using the console.
* sprintf() is used to convert the int to a string. Sprintf if
* inherently thread safe so can be used.
*
* \param val - integer value
*
*/
#define MAX_INT_STRING_LEN 15
inline void greentea_write_int(const int val)
static void greentea_write_int(const int val)
{
char intval[MAX_INT_STRING_LEN];
unsigned int i = 0;
sprintf(intval, "%d", val);
while (intval[i] != '\0') {
greentea_serial->putc(intval[i]);
greentea_putc(intval[i]);
i++;
}
}
Expand All @@ -304,7 +295,7 @@ extern "C" void greentea_send_kv(const char *key, const char *val) {
if (key && val) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_string(val);
greentea_write_postamble();
}
Expand All @@ -327,7 +318,7 @@ void greentea_send_kv(const char *key, const int val) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(val);
greentea_write_postamble();
}
Expand All @@ -351,9 +342,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_string(val);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(result);
greentea_write_postamble();

Expand Down Expand Up @@ -384,11 +375,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_string(val);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(passes);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(failures);
greentea_write_postamble();
}
Expand Down Expand Up @@ -417,9 +408,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
if (key) {
greentea_write_preamble();
greentea_write_string(key);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(passes);
greentea_serial->putc(';');
greentea_putc(';');
greentea_write_int(failures);
greentea_write_postamble();
}
Expand Down Expand Up @@ -562,7 +553,21 @@ enum Token {
*
*/
extern "C" int greentea_getc() {
return greentea_serial->getc();
uint8_t c;
read(STDOUT_FILENO, &c, 1);
return c;
}


/**
* \brief Write character from stream of data
*
* \return The number of bytes written
*
*/
extern "C" void greentea_putc(int c) {
uint8_t _c = c;
write(STDOUT_FILENO, &_c, 1);
}

/**
Expand Down Expand Up @@ -786,5 +791,3 @@ static int HandleKV(char *out_key,
getNextToken(0, 0);
return 0;
}

#endif
Loading