Test program for SoftSerial. TimerEvent function has bug for STM32 series Mbed. FRDM-64K works well without bug. This is a temporary solution avoid bug but not perfect.

Dependencies:   BufferedSoftSerial

Committer:
kenjiArai
Date:
Sun May 10 08:15:36 2020 +0000
Revision:
0:98865e300cd5
Tset program for SoftSerial library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:98865e300cd5 1 /*
kenjiArai 0:98865e300cd5 2 * Mbed Application program
kenjiArai 0:98865e300cd5 3 * SoftSerial(also BufferedSoftSerial) function test programs
kenjiArai 0:98865e300cd5 4 * UART 3 channels
kenjiArai 0:98865e300cd5 5 * (1) Mbed Serial communication line as "pc"
kenjiArai 0:98865e300cd5 6 * (2) CPU another UART channel as "ser"
kenjiArai 0:98865e300cd5 7 * (3) Software Serial channel as "dev"
kenjiArai 0:98865e300cd5 8 *
kenjiArai 0:98865e300cd5 9 * Copyright (c) 2020 Kenji Arai / JH1PJL
kenjiArai 0:98865e300cd5 10 * http://www7b.biglobe.ne.jp/~kenjia/
kenjiArai 0:98865e300cd5 11 * https://os.mbed.com/users/kenjiArai/
kenjiArai 0:98865e300cd5 12 * Created: May 9th, 2020
kenjiArai 0:98865e300cd5 13 * Revised: May 10th, 2020
kenjiArai 0:98865e300cd5 14 */
kenjiArai 0:98865e300cd5 15
kenjiArai 0:98865e300cd5 16 /*
kenjiArai 0:98865e300cd5 17 Tested board on OS5.15.3
kenjiArai 0:98865e300cd5 18 Nucleo-F446RE, Nucleo-L432KC
kenjiArai 0:98865e300cd5 19 */
kenjiArai 0:98865e300cd5 20
kenjiArai 0:98865e300cd5 21 // Pre-selection --------------------------------------------------------------
kenjiArai 0:98865e300cd5 22 #include "select_example.h"
kenjiArai 0:98865e300cd5 23 //#define EXAMPLE_3
kenjiArai 0:98865e300cd5 24 #ifdef EXAMPLE_3
kenjiArai 0:98865e300cd5 25 #warning "Select 3"
kenjiArai 0:98865e300cd5 26
kenjiArai 0:98865e300cd5 27 // Include --------------------------------------------------------------------
kenjiArai 0:98865e300cd5 28 #include "mbed.h"
kenjiArai 0:98865e300cd5 29 #include "BufferedSoftSerial.h"
kenjiArai 0:98865e300cd5 30
kenjiArai 0:98865e300cd5 31 // Definition -----------------------------------------------------------------
kenjiArai 0:98865e300cd5 32 #if (MBED_MAJOR_VERSION == 2)
kenjiArai 0:98865e300cd5 33 #error "Cannot run on OS2"
kenjiArai 0:98865e300cd5 34 #endif
kenjiArai 0:98865e300cd5 35
kenjiArai 0:98865e300cd5 36 // Constructor ----------------------------------------------------------------
kenjiArai 0:98865e300cd5 37 #if defined(TARGET_NUCLEO_L432KC)
kenjiArai 0:98865e300cd5 38 DigitalOut test_point(D12);
kenjiArai 0:98865e300cd5 39 Serial ser(D5, D4, 9600);
kenjiArai 0:98865e300cd5 40 BufferedSoftSerial dev(D6,D3);
kenjiArai 0:98865e300cd5 41 #elif defined(TARGET_NUCLEO_F446RE)
kenjiArai 0:98865e300cd5 42 DigitalOut test_point(A0);
kenjiArai 0:98865e300cd5 43 Serial ser(D8, D2, 9600);
kenjiArai 0:98865e300cd5 44 BufferedSoftSerial dev(D4,D3);
kenjiArai 0:98865e300cd5 45 #endif
kenjiArai 0:98865e300cd5 46 Serial pc(USBTX,USBRX, 9600);
kenjiArai 0:98865e300cd5 47
kenjiArai 0:98865e300cd5 48 // RAM ------------------------------------------------------------------------
kenjiArai 0:98865e300cd5 49
kenjiArai 0:98865e300cd5 50 // ROM / Constant data --------------------------------------------------------
kenjiArai 0:98865e300cd5 51
kenjiArai 0:98865e300cd5 52 // Function prototypes --------------------------------------------------------
kenjiArai 0:98865e300cd5 53 void pc2dev(void const *args);
kenjiArai 0:98865e300cd5 54 void dev2pc(void const *args);
kenjiArai 0:98865e300cd5 55
kenjiArai 0:98865e300cd5 56 //------------------------------------------------------------------------------
kenjiArai 0:98865e300cd5 57 // Control Program
kenjiArai 0:98865e300cd5 58 //------------------------------------------------------------------------------
kenjiArai 0:98865e300cd5 59 osThreadDef(pc2dev, osPriorityNormal,1024);
kenjiArai 0:98865e300cd5 60 osThreadDef(dev2pc, osPriorityNormal,1024);
kenjiArai 0:98865e300cd5 61
kenjiArai 0:98865e300cd5 62 int main()
kenjiArai 0:98865e300cd5 63 {
kenjiArai 0:98865e300cd5 64 // Start tasks
kenjiArai 0:98865e300cd5 65 osThreadCreate(osThread(pc2dev), NULL);
kenjiArai 0:98865e300cd5 66 osThreadCreate(osThread(dev2pc), NULL);
kenjiArai 0:98865e300cd5 67 // main routine
kenjiArai 0:98865e300cd5 68 int count = 0;
kenjiArai 0:98865e300cd5 69 while(true) {
kenjiArai 0:98865e300cd5 70 ser.printf( "Time passed %4d [sec]\r\n", count++);
kenjiArai 0:98865e300cd5 71 ThisThread::sleep_for(1000);
kenjiArai 0:98865e300cd5 72 }
kenjiArai 0:98865e300cd5 73 }
kenjiArai 0:98865e300cd5 74
kenjiArai 0:98865e300cd5 75 void pc2dev(void const *args)
kenjiArai 0:98865e300cd5 76 {
kenjiArai 0:98865e300cd5 77 while(true) {
kenjiArai 0:98865e300cd5 78 if (pc.readable()) {
kenjiArai 0:98865e300cd5 79 dev.putc(pc.getc());
kenjiArai 0:98865e300cd5 80 } else {
kenjiArai 0:98865e300cd5 81 ThisThread::yield();
kenjiArai 0:98865e300cd5 82 }
kenjiArai 0:98865e300cd5 83 }
kenjiArai 0:98865e300cd5 84 }
kenjiArai 0:98865e300cd5 85
kenjiArai 0:98865e300cd5 86 void dev2pc(void const *args)
kenjiArai 0:98865e300cd5 87 {
kenjiArai 0:98865e300cd5 88 while(true) {
kenjiArai 0:98865e300cd5 89 if (dev.readable()) {
kenjiArai 0:98865e300cd5 90 pc.putc(dev.getc());
kenjiArai 0:98865e300cd5 91 } else {
kenjiArai 0:98865e300cd5 92 ThisThread::yield();
kenjiArai 0:98865e300cd5 93 }
kenjiArai 0:98865e300cd5 94 }
kenjiArai 0:98865e300cd5 95 }
kenjiArai 0:98865e300cd5 96
kenjiArai 0:98865e300cd5 97 #endif //#ifdef EXAMPLE_3