RPC over Serial with read line interrupt tested on LPC1768 and mac minicom terminal. Baudrate 115200
Dependencies: mbed-rpc-stmfork mbed-src
Fork of rpc_over_serial by
Revision 3:4ed0d32d3b38, committed 2014-08-04
- Comitter:
- mosi
- Date:
- Mon Aug 04 16:51:10 2014 +0000
- Parent:
- 2:94d791a36afe
- Child:
- 4:07a0f1bfb64d
- Commit message:
- Added and tested blinking support for STM32 nucleo F103RB
Changed in this revision
--- a/main.cpp Fri Aug 01 21:54:31 2014 +0000 +++ b/main.cpp Mon Aug 04 16:51:10 2014 +0000 @@ -1,7 +1,13 @@ #include "mbed.h" #include "mbed_rpc.h" +#include "stmbed.h" -Serial pc(USBTX, USBRX); +//Serial pc(USBTX, USBRX); +//Serial pc(p29, p30); // stm32f103b +Serial pc(SERIAL_TX, SERIAL_RX); // stm32f103b PA_2 PA_3 +DigitalOut ld1(PA_5); +DigitalOut myled(LED1); + void Tx_interrupt(); void Rx_interrupt(); void send_line(); @@ -24,11 +30,25 @@ char rx_line[80]; - +void blink(){ + myled = 1; // LED is ON + wait(0.5); // 200 ms + myled = 0; // LED is OFF + wait(1.0); // 1 sec + } + int main() { - + ld1=0; + blink(); + blink(); + blink(); + char buf[256], outbuf[256]; - pc.baud(115200); + //pc.baud(115200); + pc.baud(9600); // nucleo F103RB + + // receive commands, and send back the responses + pc.printf(" ************** Serial RPC example starting ************************* \r\n"); // setup the classes that can be created dynamically // RPC::add_rpc_class<RpcAnalogIn>(); @@ -40,14 +60,14 @@ RPC::add_rpc_class<RpcTimer>(); RPC::add_rpc_class<RpcSPI>(); RPC::add_rpc_class<RpcSerial>(); + // receive commands, and send back the responses + pc.printf(" ************** 1 \r\n"); - // receive commands, and send back the responses - pc.printf(" ************** Serial RPC example starting ************************* \r\n"); // Setup a serial interrupt function to receive data pc.attach(&Rx_interrupt, Serial::RxIrq); // Setup a serial interrupt function to transmit data //pc.attach(&Tx_interrupt, Serial::TxIrq); - + pc.printf(" ************** 2 \r\n"); while(1) { // Read a line from the large rx buffer from rx interrupt routine @@ -80,17 +100,17 @@ bool empty; i = 0; // Start Critical Section - don't interrupt while changing global buffer variables - NVIC_DisableIRQ(UART1_IRQn); + NVIC_DisableIRQ(USART2_IRQn); empty = (tx_in == tx_out); while ((i==0) || (tx_line[i-1] != '\n')) { // Wait if buffer full if (((tx_in + 1) % buffer_size) == tx_out) { // End Critical Section - need to let interrupt routine empty buffer by sending - NVIC_EnableIRQ(UART1_IRQn); + NVIC_EnableIRQ(USART2_IRQn); while (((tx_in + 1) % buffer_size) == tx_out) { } // Start Critical Section - don't interrupt while changing global buffer variables - NVIC_DisableIRQ(UART1_IRQn); + NVIC_DisableIRQ(USART2_IRQn); } tx_buffer[tx_in] = tx_line[i]; i++; @@ -103,7 +123,7 @@ pc.putc(temp_char); } // End Critical Section - NVIC_EnableIRQ(UART1_IRQn); + NVIC_EnableIRQ(USART2_IRQn); return; } @@ -113,24 +133,24 @@ int i; i = 0; // Start Critical Section - don't interrupt while changing global buffer variables - NVIC_DisableIRQ(UART1_IRQn); + NVIC_DisableIRQ(USART2_IRQn); // stm32: USART2_IRQn lpc nxp: UART1_IRQn // Loop reading rx buffer characters until end of line character while ((i==0) || (rx_line[i-1] != '\r')) { // Wait if buffer empty if (rx_in == rx_out) { // End Critical Section - need to allow rx interrupt to get new characters for buffer - NVIC_EnableIRQ(UART1_IRQn); + NVIC_EnableIRQ(USART2_IRQn); while (rx_in == rx_out) { } // Start Critical Section - don't interrupt while changing global buffer variables - NVIC_DisableIRQ(UART1_IRQn); + NVIC_DisableIRQ(USART2_IRQn); } rx_line[i] = rx_buffer[rx_out]; i++; rx_out = (rx_out + 1) % buffer_size; } // End Critical Section - NVIC_EnableIRQ(UART1_IRQn); + NVIC_EnableIRQ(USART2_IRQn); rx_line[i-1] = 0; return; }
--- a/mbed-rpc.lib Fri Aug 01 21:54:31 2014 +0000 +++ b/mbed-rpc.lib Mon Aug 04 16:51:10 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rpc/#4490a0d9cb2a +http://mbed.org/users/mbed_official/code/mbed-rpc/#279476428ecf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Mon Aug 04 16:51:10 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#ccdf646660f2
--- a/mbed.bld Fri Aug 01 21:54:31 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stmbed.h Mon Aug 04 16:51:10 2014 +0000 @@ -0,0 +1,41 @@ +#ifndef STMBED_H +#define STMBED_H + +#define p5 PB_15 +#define p6 PB_14 +#define p7 PB_13 +#define p8 PC_0 +#define p9 PB_10 +#define p10 PB_11 +#define p11 PC_2 +#define p12 PC_3 +#define p13 PA_0 +#define p14 PA_1 +#define p15 PA_2 +#define p16 PA_3 +#define p17 PA_4 +#define p18 PA_5 +#define p19 PA_6 +#define p20 PA_7 + +#define p21 PC_4 +#define p22 PC_5 +#define p23 PB_0 +#define p24 PB_1 +#define p25 PC_7 +#define p26 PC_8 +#define p27 PB_6 +#define p28 PB_7 +#define p29 PA_9 +#define p30 PA_10 +#define p31 PA_15 +#define p32 PC_10 +#define p33 PC_11 +#define p34 PC_12 + +#endif + + //{PB_15, PB_14, PB_13, PC_0, PB_10, PB_11, PC_2, + // PC_3, PA_0,PA_1,PA_2,PA_3,PA_4,PA_5,PA_6,PA_7, + // PC_4, PC_5, PB_0, PB_1, PC_7, PC_8, PB_6, PB_7, + // PA_9,PA_10,PA_15,PC_10,PC_11,PC_12}; \ No newline at end of file