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 Suga koubou

Revision:
3:4ed0d32d3b38
Parent:
2:94d791a36afe
--- 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;
 }