Webserver only w/o any other functions, single thread. Running on STM32F013+W5500
Dependencies: NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed
Fork of F103-Serial-to-Ethernet by
Revision 8:64848959adb9, committed 2014-09-21
- Comitter:
- olympux
- Date:
- Sun Sep 21 20:25:35 2014 +0000
- Parent:
- 7:d45bd480e90f
- Child:
- 9:d2534ecf88c6
- Commit message:
- Added first run flag (0xA5A5 at 15th variable in eeprom)
Changed in this revision
eeprom.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/eeprom.lib Sun Sep 21 20:00:21 2014 +0000 +++ b/eeprom.lib Sun Sep 21 20:25:35 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/olympux/code/eeprom/#30f2f413f549 +http://mbed.org/users/olympux/code/eeprom/#5da14988d0e5
--- a/main.cpp Sun Sep 21 20:00:21 2014 +0000 +++ b/main.cpp Sun Sep 21 20:25:35 2014 +0000 @@ -23,13 +23,14 @@ Serial uart(USBTX,USBRX); // Variables' number -#define NumbOfVar ((uint8_t)0x0E) // REMEMBER: update this variable in eeprom.h too +#define NumbOfVar ((uint8_t)0x0F) // REMEMBER: update this variable in eeprom.h too // Virtual address defined by the user: 0xFFFF value is prohibited uint16_t VirtAddVarTab[NumbOfVar] = {0x1212, 0x1313, 0x1414, 0x1515, // IP_Addr 0x2212, 0x2313, 0x2414, 0x2515, // IP_Subnet 0x3212, 0x3313, 0x3414, 0x3515, // IP_Gateway 0x4212, // TCP server port, not used - 0x5212 // UDP server port, not used + 0x5212, // UDP server port, not used + 0x8888 // 1st run? }; extern "C" uint16_t EE_Init(void); extern "C" uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data); @@ -45,6 +46,10 @@ //#define UDP_CLIENT //#define NTP +#define DEFAULT_IP_ADDRESS "192.168.0.249" +#define DEFAULT_IP_SUBNET "255.255.255.0" +#define DEFAULT_IP_GATEWAY "192.168.0.1" + #define TCP_SERVER_WAIT_CLIENT_TIMEOUT 200 #define TCP_SERVER_RECEIVE_TIMEOUT 3000 #define UDP_SERVER_RECEIVE_TIMEOUT 200 @@ -115,7 +120,7 @@ ret = eth.connect(); if (!ret) { - //uart.printf("IP: %s, MASK: %s, GW: %s\n", eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); + uart.printf("IP: %s, MASK: %s, GW: %s\n", eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); } else { uart.printf("Error eth.connect() - ret = %d\n", ret); return -1; @@ -152,38 +157,53 @@ //EE_WriteVariable(VirtAddVarTab[12], *buffer++); //// UDP server port //EE_WriteVariable(VirtAddVarTab[13], *buffer++); + + // erase first_run flag + EE_WriteVariable(VirtAddVarTab[14], 0xA5A5); FLASH_Lock(); } void load_eeprom(void) { - // Load IP adddress uint16_t u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4]; - //FLASH_Unlock(); + uint16_t first_run = 0; + EE_Init(); - // IP address - EE_ReadVariable(VirtAddVarTab[0], &u16ip_addr[0]); - EE_ReadVariable(VirtAddVarTab[1], &u16ip_addr[1]); - EE_ReadVariable(VirtAddVarTab[2], &u16ip_addr[2]); - EE_ReadVariable(VirtAddVarTab[3], &u16ip_addr[3]); - // IP subnet - EE_ReadVariable(VirtAddVarTab[4], &u16ip_subnet[0]); - EE_ReadVariable(VirtAddVarTab[5], &u16ip_subnet[1]); - EE_ReadVariable(VirtAddVarTab[6], &u16ip_subnet[2]); - EE_ReadVariable(VirtAddVarTab[7], &u16ip_subnet[3]); - // IP gateway - EE_ReadVariable(VirtAddVarTab[8], &u16ip_gateway[0]); - EE_ReadVariable(VirtAddVarTab[9], &u16ip_gateway[1]); - EE_ReadVariable(VirtAddVarTab[10], &u16ip_gateway[2]); - EE_ReadVariable(VirtAddVarTab[11], &u16ip_gateway[3]); - //// TCP server port - //EE_ReadVariable(VirtAddVarTab[12], &tcp_server_port); - //// UDP server port - //EE_ReadVariable(VirtAddVarTab[13], &udp_server_port); - //FLASH_Lock(); - sprintf(ip_addr, "%d.%d.%d.%d", (uint8_t)u16ip_addr[0], (uint8_t)u16ip_addr[1], (uint8_t)u16ip_addr[2], (uint8_t)u16ip_addr[3]); - sprintf(ip_subnet, "%d.%d.%d.%d", (uint8_t)u16ip_subnet[0], (uint8_t)u16ip_subnet[1], (uint8_t)u16ip_subnet[2], (uint8_t)u16ip_subnet[3]); - sprintf(ip_gateway, "%d.%d.%d.%d", (uint8_t)u16ip_gateway[0], (uint8_t)u16ip_gateway[1], (uint8_t)u16ip_gateway[2], (uint8_t)u16ip_gateway[3]); + + // check if 1st run + EE_ReadVariable(VirtAddVarTab[14], &first_run); + // if not first run, load network config + if (first_run == 0xA5A5) { + // IP address + EE_ReadVariable(VirtAddVarTab[0], &u16ip_addr[0]); + EE_ReadVariable(VirtAddVarTab[1], &u16ip_addr[1]); + EE_ReadVariable(VirtAddVarTab[2], &u16ip_addr[2]); + EE_ReadVariable(VirtAddVarTab[3], &u16ip_addr[3]); + // IP subnet + EE_ReadVariable(VirtAddVarTab[4], &u16ip_subnet[0]); + EE_ReadVariable(VirtAddVarTab[5], &u16ip_subnet[1]); + EE_ReadVariable(VirtAddVarTab[6], &u16ip_subnet[2]); + EE_ReadVariable(VirtAddVarTab[7], &u16ip_subnet[3]); + // IP gateway + EE_ReadVariable(VirtAddVarTab[8], &u16ip_gateway[0]); + EE_ReadVariable(VirtAddVarTab[9], &u16ip_gateway[1]); + EE_ReadVariable(VirtAddVarTab[10], &u16ip_gateway[2]); + EE_ReadVariable(VirtAddVarTab[11], &u16ip_gateway[3]); + //// TCP server port + //EE_ReadVariable(VirtAddVarTab[12], &tcp_server_port); + //// UDP server port + //EE_ReadVariable(VirtAddVarTab[13], &udp_server_port); + //FLASH_Lock(); + sprintf(ip_addr, "%d.%d.%d.%d", (uint8_t)u16ip_addr[0], (uint8_t)u16ip_addr[1], (uint8_t)u16ip_addr[2], (uint8_t)u16ip_addr[3]); + sprintf(ip_subnet, "%d.%d.%d.%d", (uint8_t)u16ip_subnet[0], (uint8_t)u16ip_subnet[1], (uint8_t)u16ip_subnet[2], (uint8_t)u16ip_subnet[3]); + sprintf(ip_gateway, "%d.%d.%d.%d", (uint8_t)u16ip_gateway[0], (uint8_t)u16ip_gateway[1], (uint8_t)u16ip_gateway[2], (uint8_t)u16ip_gateway[3]); + } + // if 1st run, use default addresses + else { + sprintf(ip_addr, DEFAULT_IP_ADDRESS); + sprintf(ip_subnet, DEFAULT_IP_SUBNET); + sprintf(ip_gateway, DEFAULT_IP_GATEWAY); + } //printf("IP: %s\n", ip_addr); //printf("MASK: %s\n", ip_subnet); //printf("GW: %s\n", ip_gateway);