Skip to content

Commit dbaeeaf

Browse files
committed
Replace RawSerial instances as it has been deprecated
1 parent de798c4 commit dbaeeaf

File tree

23 files changed

+140
-126
lines changed

23 files changed

+140
-126
lines changed

TESTS/mbed_drivers/flashiap/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#else
2121

2222
#include "utest/utest.h"
23-
#include "utest/utest_serial.h"
23+
#include "utest/utest_print.h"
2424
#include "unity/unity.h"
2525
#include "greentea-client/test_env.h"
2626
#include "FlashIAP.h"

TESTS/mbed_hal/trng/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "base64b.h"
4444
#include "pithy.h"
4545
#include <stdio.h>
46+
#include <string.h>
4647
#include "mbedtls/config.h"
4748
#include "mbedtls/platform.h"
4849

TESTS/psa/entropy_inject/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "entropy.h"
2929
#include "entropy_poll.h"
3030
#include "psa/crypto.h"
31+
#include <string.h>
3132

3233
/* MAX value support macro */
3334
#if !defined(MAX)

TESTS/psa/spm_smoke/COMPONENT_NSPE/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "utest.h"
2828
#include "psa/client.h"
2929
#include "psa_manifest/sid.h"
30+
#include <string.h>
3031

3132
#if defined(TARGET_TFM)
3233
#define PSA_MAX_IOVEC 4

TEST_APPS/device/nanostack_mac_tester/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545

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

6969
static void rx_interrupt(void)
7070
{
71-
uint8_t c = pc.getc();
71+
uint8_t c;
72+
pc.read(&c, 1);
7273
rx_buffer.push(c);
7374
if (main_thread != NULL) {
7475
osThreadFlagsSet(main_thread, 1);

components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort;
540540

541541
#if DEVICE_SERIAL
542542
#if DEVICE_SERIAL_FC
543+
#include "hal/serial_api.h"
543544
struct UARTMaps {
544545
static const PinMap *maps[];
545546
static const char *const pin_type_names[];

drivers/RawSerial.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#include <cstdarg>
2828

2929
namespace mbed {
30-
/** \defgroup drivers-public-api-uart UART
31-
* \ingroup drivers-public-api
32-
*/
3330

3431
/**
3532
* \defgroup drivers_RawSerial RawSerial class

drivers/UnbufferedSerial.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131

3232
namespace mbed {
33+
/** \defgroup drivers-public-api-uart UART
34+
* \ingroup drivers-public-api
35+
*/
3336

3437
/**
3538
* \defgroup drivers_UnbufferedSerial UnbufferedSerial class
@@ -152,6 +155,12 @@ class UnbufferedSerial:
152155
*/
153156
virtual short poll(short events) const;
154157

158+
using SerialBase::readable;
159+
using SerialBase::writeable;
160+
using SerialBase::format;
161+
using SerialBase::attach;
162+
using SerialBase::baud;
163+
155164
#if DEVICE_SERIAL_FC
156165
// For now use the base enum - but in future we may have extra options
157166
// such as XON/XOFF or manual GPIO RTSCTS.

features/FEATURE_BLE/targets/TARGET_CORDIO/driver/H4TransportDriver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
5353
while (i < len + 1) {
5454
uint8_t to_write = i == 0 ? type : pData[i - 1];
5555
while (uart.writeable() == 0);
56-
uart.putc(to_write);
56+
uart.write(&to_write, 1);
5757
++i;
5858
}
5959
return len;
@@ -62,8 +62,10 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
6262
void H4TransportDriver::on_controller_irq()
6363
{
6464
while (uart.readable()) {
65-
uint8_t char_received = uart.getc();
66-
on_data_received(&char_received, 1);
65+
uint8_t char_received;
66+
if (uart.read(&char_received, 1)) {
67+
on_data_received(&char_received, 1);
68+
}
6769
}
6870
}
6971

features/FEATURE_BLE/targets/TARGET_CORDIO/driver/H4TransportDriver.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ class H4TransportDriver : public CordioHCITransportDriver {
6969
private:
7070
void on_controller_irq();
7171

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

features/frameworks/greentea-client/greentea-client/greentea_serial.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

features/frameworks/greentea-client/greentea-client/test_env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void greentea_send_kv(const char * key, const char * val);
117117
int greentea_parse_kv(char * key, char * val,
118118
const int key_len, const int val_len);
119119
int greentea_getc();
120+
void greentea_putc(int c);
121+
void greentea_write_string(const char *str);
120122

121123
#ifdef __cplusplus
122124
}

features/frameworks/greentea-client/source/greentea_serial.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

features/frameworks/greentea-client/source/greentea_test_env.cpp

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18-
#if DEVICE_SERIAL
19-
2018
#include <ctype.h>
2119
#include <cstdio>
2220
#include <string.h>
2321
#include "greentea-client/test_env.h"
24-
#include "greentea-client/greentea_serial.h"
2522
#include "greentea-client/greentea_metrics.h"
2623
#include "mbed_trace.h"
24+
#include "platform/mbed_retarget.h"
2725

2826
/**
2927
* Generic test suite transport protocol keys
@@ -59,7 +57,6 @@ static void greentea_notify_timeout(const int);
5957
static void greentea_notify_hosttest(const char *);
6058
static void greentea_notify_completion(const int);
6159
static void greentea_notify_version();
62-
static void greentea_write_string(const char *str);
6360

6461
/** \brief Handle the handshake with the host
6562
* \details This is contains the shared handhshake functionality that is used between
@@ -212,55 +209,49 @@ void greentea_notify_coverage_end() {
212209
*
213210
* This function writes the preamble "{{" which is required
214211
* for key-value comunication between the target and the host.
215-
* This uses a Rawserial object, greentea_serial, which provides
216-
* a direct interface to the USBTX and USBRX serial pins and allows
217-
* the direct writing of characters using the putc() method.
212+
* This uses greentea_putc which allows the direct writing of characters
213+
* using the write() method.
218214
* This suite of functions are provided to allow for serial communication
219215
* to the host from within a thread/ISR.
220-
*
221216
*/
222-
inline void greentea_write_preamble()
217+
static void greentea_write_preamble()
223218
{
224-
greentea_serial->putc('{');
225-
greentea_serial->putc('{');
219+
greentea_putc('{');
220+
greentea_putc('{');
226221
}
227222

228223
/**
229224
* \brief Write the postamble characters to the serial port
230225
*
231226
* This function writes the postamble "{{\n" which is required
232227
* for key-value comunication between the target and the host.
233-
* This uses a Rawserial object, greentea_serial, which provides
234-
* a direct interface to the USBTX and USBRX serial pins and allows
235-
* the direct writing of characters using the putc() method.
228+
* This uses greentea_putc which allows the direct writing of characters
229+
* using the write() method.
236230
* This suite of functions are provided to allow for serial communication
237231
* to the host from within a thread/ISR.
238232
*
239233
*/
240-
inline void greentea_write_postamble()
234+
static void greentea_write_postamble()
241235
{
242-
greentea_serial->putc('}');
243-
greentea_serial->putc('}');
244-
greentea_serial->putc('\r');
245-
greentea_serial->putc('\n');
236+
greentea_putc('}');
237+
greentea_putc('}');
238+
greentea_putc('\r');
239+
greentea_putc('\n');
246240
}
247241

248242
/**
249243
* \brief Write a string to the serial port
250244
*
251245
* This function writes a '\0' terminated string from the target
252246
* to the host. It writes directly to the serial port using the
253-
* greentea_serial, Rawserial object.
247+
* the write() method.
254248
*
255249
* \param str - string value
256250
*
257251
*/
258-
inline void greentea_write_string(const char *str)
252+
void greentea_write_string(const char *str)
259253
{
260-
while (*str != '\0') {
261-
greentea_serial->putc(*str);
262-
str ++;
263-
}
254+
write(STDOUT_FILENO, str, strlen(str));
264255
}
265256

266257

@@ -270,21 +261,21 @@ inline void greentea_write_string(const char *str)
270261
* This function writes an integer value from the target
271262
* to the host. The integer value is converted to a string and
272263
* and then written character by character directly to the serial
273-
* port using the greentea_serial, Rawserial object.
264+
* port using the console.
274265
* sprintf() is used to convert the int to a string. Sprintf if
275266
* inherently thread safe so can be used.
276267
*
277268
* \param val - integer value
278269
*
279270
*/
280271
#define MAX_INT_STRING_LEN 15
281-
inline void greentea_write_int(const int val)
272+
static void greentea_write_int(const int val)
282273
{
283274
char intval[MAX_INT_STRING_LEN];
284275
unsigned int i = 0;
285276
sprintf(intval, "%d", val);
286277
while (intval[i] != '\0') {
287-
greentea_serial->putc(intval[i]);
278+
greentea_putc(intval[i]);
288279
i++;
289280
}
290281
}
@@ -304,7 +295,7 @@ extern "C" void greentea_send_kv(const char *key, const char *val) {
304295
if (key && val) {
305296
greentea_write_preamble();
306297
greentea_write_string(key);
307-
greentea_serial->putc(';');
298+
greentea_putc(';');
308299
greentea_write_string(val);
309300
greentea_write_postamble();
310301
}
@@ -327,7 +318,7 @@ void greentea_send_kv(const char *key, const int val) {
327318
if (key) {
328319
greentea_write_preamble();
329320
greentea_write_string(key);
330-
greentea_serial->putc(';');
321+
greentea_putc(';');
331322
greentea_write_int(val);
332323
greentea_write_postamble();
333324
}
@@ -351,9 +342,9 @@ void greentea_send_kv(const char *key, const char *val, const int result) {
351342
if (key) {
352343
greentea_write_preamble();
353344
greentea_write_string(key);
354-
greentea_serial->putc(';');
345+
greentea_putc(';');
355346
greentea_write_string(val);
356-
greentea_serial->putc(';');
347+
greentea_putc(';');
357348
greentea_write_int(result);
358349
greentea_write_postamble();
359350

@@ -384,11 +375,11 @@ void greentea_send_kv(const char *key, const char *val, const int passes, const
384375
if (key) {
385376
greentea_write_preamble();
386377
greentea_write_string(key);
387-
greentea_serial->putc(';');
378+
greentea_putc(';');
388379
greentea_write_string(val);
389-
greentea_serial->putc(';');
380+
greentea_putc(';');
390381
greentea_write_int(passes);
391-
greentea_serial->putc(';');
382+
greentea_putc(';');
392383
greentea_write_int(failures);
393384
greentea_write_postamble();
394385
}
@@ -417,9 +408,9 @@ void greentea_send_kv(const char *key, const int passes, const int failures) {
417408
if (key) {
418409
greentea_write_preamble();
419410
greentea_write_string(key);
420-
greentea_serial->putc(';');
411+
greentea_putc(';');
421412
greentea_write_int(passes);
422-
greentea_serial->putc(';');
413+
greentea_putc(';');
423414
greentea_write_int(failures);
424415
greentea_write_postamble();
425416
}
@@ -562,7 +553,21 @@ enum Token {
562553
*
563554
*/
564555
extern "C" int greentea_getc() {
565-
return greentea_serial->getc();
556+
uint8_t c;
557+
read(STDOUT_FILENO, &c, 1);
558+
return c;
559+
}
560+
561+
562+
/**
563+
* \brief Write character from stream of data
564+
*
565+
* \return The number of bytes written
566+
*
567+
*/
568+
extern "C" void greentea_putc(int c) {
569+
uint8_t _c = c;
570+
write(STDOUT_FILENO, &_c, 1);
566571
}
567572

568573
/**
@@ -786,5 +791,3 @@ static int HandleKV(char *out_key,
786791
getNextToken(0, 0);
787792
return 0;
788793
}
789-
790-
#endif

0 commit comments

Comments
 (0)