Transfer data between UART ports and Ethernet.
Transfer data between UART ports and Ethernet.
- Support multiple UART ports.
- Support fixed IP address and DHCP.
- Support TCP server and TCP client modes.
- Support a simple web server for UART and Ethernet configuration.
Revision 8:e9248126f512, committed 2021-02-26
- Comitter:
- morgandu
- Date:
- Fri Feb 26 06:30:37 2021 +0000
- Parent:
- 7:cbb5a2a2a0d2
- Commit message:
- Fix code to compliant Mbed OS 6 but still set to Mbed OS 5 as default.; Remove BufferedSerial library if switch to Mbed OS 6 before compile.
Changed in this revision
--- a/BufferedSerial.lib Wed Feb 26 07:55:51 2020 +0000 +++ b/BufferedSerial.lib Fri Feb 26 06:30:37 2021 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/sam_grove/code/BufferedSerial/#7e5e866edd3d +https://os.mbed.com/users/sam_grove/code/BufferedSerial/#7e5e866edd3d
--- a/NuMaker-mbed-SD-driver.lib Wed Feb 26 07:55:51 2020 +0000 +++ b/NuMaker-mbed-SD-driver.lib Fri Feb 26 06:30:37 2021 +0000 @@ -1,1 +1,1 @@ -https://github.com/OpenNuvoton/NuMaker-mbed-SD-driver/#56406071a4468a8302c0717a4467a241d152ade2 +https://github.com/OpenNuvoton/NuMaker-mbed-SD-driver/#8027c2c886a6bb2d850d3121ec3e2e179450e41c
--- a/README.md Wed Feb 26 07:55:51 2020 +0000 +++ b/README.md Fri Feb 26 06:30:37 2021 +0000 @@ -23,6 +23,11 @@ ## Configuration +* Mbed OS version + +The template set Mbed OS 5 as defalut but it has been updated for Mbed OS 6. +Because BufferedSerial has built in Mbed OS 6, the BufferedSerial library in the template has to be removed if you switch Mbed OS to version 6 to avoid conflict. + * Following configurations are set in ste_config.h ENABLE_WEB_CONFIG
--- a/main.cpp Wed Feb 26 07:55:51 2020 +0000
+++ b/main.cpp Fri Feb 26 06:30:37 2021 +0000
@@ -5,10 +5,8 @@
*
*
*/
-
#include "ste_config.h"
-
/* If choose static IP, specify the default IP address here. */
#if 0
// private IP address for general purpose
@@ -27,14 +25,26 @@
S_NET_CONFIG net_config = {IP_STATIC_MODE, IP_ADDRESS, NETWORK_MASK, GATEWAY_ADDRESS};
#if defined (TARGET_NUMAKER_PFM_M487) || defined(TARGET_NUMAKER_IOT_M487)
+#if MBED_MAJOR_VERSION <= 5
BufferedSerial serial_0(PB_3, PB_2, 256, 4); // UART1
BufferedSerial serial_1(PA_5, PA_4, 256, 4); // UART5
//BufferedSerial serial_2(PB_13, PB_12, 256, 4); // UART0, Debug
+#else
+BufferedSerial serial_0(PB_3, PB_2); // UART1
+BufferedSerial serial_1(PA_5, PA_4); // UART5
+//BufferedSerial serial_2(PB_13, PB_12); // UART0, Debug
+#endif
#elif defined (TARGET_NUMAKER_PFM_NUC472)
+#if MBED_MAJOR_VERSION <= 5
BufferedSerial serial_0(PH_1, PH_0, 256, 4); // UART4
BufferedSerial serial_1(PG_2, PG_1, 256, 4); // UART0
BufferedSerial serial_2(PC_11, PC_10, 256, 4); // UART2
+#else
+BufferedSerial serial_0(PH_1, PH_0); // UART4
+BufferedSerial serial_1(PG_2, PG_1); // UART0
+BufferedSerial serial_2(PC_11, PC_10); // UART2
+#endif
#elif defined (TARGET_NUMAKER_PFM_M453) || defined(TARGET_NUMAKER_PFM_NANO130) || defined(TARGET_NUMAKER_PFM_M2351)
#error The board has no Ethernet.
@@ -123,8 +133,17 @@
/*** Serial to Network ***/
// try to get more data from serial port
+#if MBED_MAJOR_VERSION <= 5
for(; s_index < sizeof(s_buf) && pmap->pserial->readable(); s_index++)
s_buf[s_index] = pmap->pserial->getc();
+#else
+ if (pmap->pserial->readable())
+ {
+ s_len = pmap->pserial->read(s_buf+s_index, sizeof(s_buf)-s_index);
+ if (s_len > 0)
+ s_index += s_len;
+ }
+#endif
if (s_index >= 240 || (s_index != 0 && ++eth_tx_count >= 5))
{
@@ -162,7 +181,7 @@
printf("Thread %x in TCP client mode.\r\n", (unsigned int)pmap);
- if ((err=socket.open(ð)) < 0)
+ if ((err=socket.open(ð)) != NSAPI_ERROR_OK)
{
printf("TCP socket can't open (%d)(%x).\r\n", err, (unsigned int)pmap);
return;
@@ -194,12 +213,12 @@
printf("Thread %x in TCP server mode.\r\n", (unsigned int)pmap);
- if ((err=tcp_server.open(ð)) < 0)
+ if ((err=tcp_server.open(ð)) != NSAPI_ERROR_OK)
{
printf("TCP server can't open (%d)(%x).\r\n", err, (unsigned int)pmap);
return;
}
- if ((err=tcp_server.bind(pmap->port)) < 0)
+ if ((err=tcp_server.bind(pmap->port)) != NSAPI_ERROR_OK)
{
printf("TCP server can't bind address and port (%d)(%x).\r\n", err, (unsigned int)pmap);
return;
@@ -213,7 +232,7 @@
while(1)
{
client_socket = tcp_server.accept(&err);
- if (err < 0) // && err != NSAPI_ERROR_WOULD_BLOCK)
+ if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_WOULD_BLOCK)
{
printf("TCP server fail to accept connection (%d)(%x).\r\n", err, (unsigned int)pmap);
return;
@@ -295,8 +314,13 @@
printf("Configure UART ports...\r\n");
for(int i=0; i<MAX_UART_PORTS; i++)
{
+#if MBED_MAJOR_VERSION <= 5
port_config[i].pserial->baud(port_config[i].baud);
port_config[i].pserial->format(port_config[i].data, port_config[i].parity, port_config[i].stop);
+#else
+ port_config[i].pserial->set_baud(port_config[i].baud);
+ port_config[i].pserial->set_format(port_config[i].data, port_config[i].parity, port_config[i].stop);
+#endif
}
/* Configure network IP address */
--- a/mbed-os.lib Wed Feb 26 07:55:51 2020 +0000 +++ b/mbed-os.lib Fri Feb 26 06:30:37 2021 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#c12b433026beae5b3b769c27941bc6d7fe5d4b27 +https://github.com/ARMmbed/mbed-os/#b114a9c878519d6489ac3426697196bbea34c8ea
--- a/mbed_app.json Wed Feb 26 07:55:51 2020 +0000
+++ b/mbed_app.json Fri Feb 26 06:30:37 2021 +0000
@@ -12,10 +12,10 @@
"*": {
"platform.stdio-baud-rate" : 115200,
"platform.stdio-convert-newlines" : true,
- "lwip.socket-max": 8,
- "lwip.tcp-socket-max": 8,
- "lwip.tcp-server-max": 8,
- "lwip.udp-socket-max": 8
+ "lwip.socket-max" : 8,
+ "lwip.tcp-socket-max" : 8,
+ "lwip.tcp-server-max" : 8,
+ "lwip.udp-socket-max" : 8
}
}
}
--- a/ste_config.h Wed Feb 26 07:55:51 2020 +0000
+++ b/ste_config.h Fri Feb 26 06:30:37 2021 +0000
@@ -10,10 +10,13 @@
#include "mbed.h"
#include "EthernetInterface.h"
-#include "BufferedSerial.h"
#include "FATFileSystem.h"
#include "NuSDBlockDevice.h"
+#if MBED_MAJOR_VERSION <= 5
+#include "BufferedSerial.h"
+#endif
+
/* A simple web server for network and UART configuration
0: Disable the web server.
1: Enable the web server
@@ -76,7 +79,7 @@
unsigned short server_port; // Server port for TCP client mode
} S_PORT_CONFIG;
-extern RawSerial output; // for debug output
+//extern RawSerial output; // for debug output
extern EthernetInterface eth;
extern S_PORT_CONFIG port_config[MAX_UART_PORTS];
extern S_NET_CONFIG net_config;
--- a/uweb_server.cpp Wed Feb 26 07:55:51 2020 +0000
+++ b/uweb_server.cpp Fri Feb 26 06:30:37 2021 +0000
@@ -504,7 +504,7 @@
if (http_server.open(ð) < 0)
{
- printf("http server can't open.\r\n");
+ printf("http server can't be created.\r\n");
return;
}
if (http_server.bind(80) < 0)