5.6.1 Execution
main.c - Initialize the device and set the server information. It then connects to the OTA download server.
- Set your OTA download server.
- Upload the OTA firmware binary to
the root folder in your server. (ATWINC15x0: e.g.
http://192.168.0.137/m2m_ota.bin
, ATWINC3400: e.g.http://192.168.1.11/m2m_ota_3400.bin
). - Code summary:
- Configure the network and
OTA parameters in main.h. The default port number
is 80. If the user application uses a different port number, update it
in the URL.
"http://192.168.0.137/m2m_ota.bin"
.#define MAIN_WLAN_SSID "DEMO_AP" #define MAIN_WLAN_AUTH M2M_WIFI_SEC_WPA_PSK #define MAIN_WLAN_PSK "12345678" #define MAIN_OTA_URL "http://192.168.0.137/m2m_ota.bin"
- Connect to the AP.
/* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
- Initialize the OTA
function.
m2m_ota_init(OtaUpdateCb, OtaNotifCb);
- After the device is
connected to the AP, the
m2m_ota_start_update()
function will be executed in thewifi_cb()
function.static void wifi_cb(uint8_t u8MsgType, void *pvMsg) { ... case M2M_WIFI_REQ_DHCP_CONF: m2m_ota_start_update((uint8_t *)MAIN_OTA_URL);
- If successfully
downloaded, the
m2m_ota_switch_firmware()
function will be called throughOtaUpdateCb()
.
After that and if no errors occur, a message will display: “OTA success. Press reset your board.”static void OtaUpdateCb(uint8_t u8OtaUpdateStatusType, uint8_t u8OtaUpdateStatus) { m2m_ota_switch_firmware(); }
- Configure the network and
OTA parameters in main.h. The default port number
is 80. If the user application uses a different port number, update it
in the URL.
- Build the program and download it into the board.
- Start the application.
When you receive the IP address, then the OTA update will start.
- You can find the firmware version
and the build time information.
(3)NMI M2M SW VERSION xx.xx.xx (3)NMI MIN DRV VERSION xx.xx.xx (3)Built at xxx xx xxxx xx:xx:xx
- Once connected to the OTA server,
the following text will appear on the terminal window:
(770)(M2M)(OTA) Invalidate RB Image Start Writing.. at 40000 Size 204380 (809)STATS 0 0 5 25 0, err: 16 - stuck: 0 (809)!@#$ Rate DN (48.0 Mbps) !@#$ (910)!@#$ Rate DN (MCS-4) !@#$ (1079)(M2M)Verification OK 204380 (1080)(M2M)(OTA) Update image done successfully (1080)(M2M)Socket 6 Closed (1083)(M2M)(OTA) Swap image done successfully (1084)(M2M)(OTA) Switching firmware done.
- After the successful OTA firmware
upgrade, the following text will appear on the terminal window:
Wi-Fi IP is xxx.xxx.xxx.xxx OtaUpdateCb 1 0 OtaUpdateCb m2m_ota_switch_firmware start. OtaUpdateCb 2 0 OTA Success. Press reset your board.
- The application reads data from
the serial interface.
(1)Chip ID = 1502b1 (1)Flash ID = c21320c2, Size = 4 MBit (1)Working Image offset = 0x3000 Rollback = 0x40000 (2)(M2M)(Efuse) successfully loaded from bank 1. (2)EFUSE:MAC (2)(M2M)MAC_ADDR = xx:xx:xx:xx:xx:xx (3)NMI M2M SW VERSION xx.xx.xx (3)NMI MIN DRV VERSION xx.xx.xx (3)Built at xxx xx xxxx xx:xx:xx (3)__ROM_FIRMWARE__
The OTA download procedure for WINC15x0 is:
- Download the ATWINC15x0 driver version 19.4.4 OTA application from ASF.
- Use any HTTP server or hfs.exe from http://www.rejetto.com/hfs/
- Run the hfs.exe
- Add the OTA firmware from the “\src\Tools\firmware\ota_firmware\m2m_ota_3a0.bin” 19.5.3 release package to the root folder in the hfs.exe tool.
- Change the MAIN_OTA_URL "http://192.168.1.138/m2m_ota.bin" to the IP address in the hfs tool. The IP address is the HTTP server IP address and the user can use their own port number or port number 80.
- Program the MCU with the OTA application available in the ASF (19.4.4) after compiling these changes.
- Run the application and wait for it to complete.
The OTA download procedure for ATWINC3400 is:
- Download the ATWINC3400 driver version 1.0.8 OTA application from ASF.
- Use any HTTP server or hfs.exe from http://www.rejetto.com/hfs/
- Run the hfs.exe
- Add the OTA firmware from the “\src\firmware\m2m_ota_3400.bin” 1.2.2 release package to the root folder in the hfs.exe tool.
- Change the MAIN_OTA_URL "http://192.168.1.11/m2m_ota_3400.bin" to the IP address in the hfs tool. The IP address is the HTTP server IP address and the user can use their own port number or port number 80.
- Program the MCU with the OTA application available in the ASF (1.2.1) after compiling these changes.
- Run the application and wait for it to complete.