详细记录更新winc1500固件及其网络配置页面(provisioning webpage)过程

        在我之前的文章中,详细讲解了如何移植winc1500驱动到IMX1020单片机,想了解的朋友可以点击下面链接,

采用IMXRT1020驱动ATWINC1500模块_宇宸宇宸的博客-CSDN博客

在实际使用wifi模块时我们经常需要通过一个页面配置wifi的ssid和密码,然后wifi模块就可以连接到这个网络上了。这个页面的英文名是provisioning webpage。winc1500固件中自带的配置页面如下,

 我们做产品当然希望这个配置页面上有自己公司的logo,所以这个页面往往需要进行修改,那么如何修改它呢?

        这里我们需要参考第一个官方手册,链接如下,

https://community.atmel.com/sites/default/files/forum_attachments/Atmel-Firmware-Update-Procedure-for-WINC-Module-using-a-SAM-Xplained-Pro.pdf

这个手册有如下一句话,

 也就是说provisioning webpage是winc1500固件的一部分,如果我们要更改配置页面就需要重新烧写固件!通过阅读这篇文档我们知道有三种方法可以更新固件,Serial Bridge,Built-in UART 和OTA。我们首先看Serial Bridge,这种更新方式官方介绍如下,

这个文档在稍后我们下载ASF中,路径如下,

 

 也就是说我们的1020单片机作为一个桥梁,一边用SPI接口访问winc1500中的flash,一边用串口和电脑通信,这样电脑就可以通过串口把新的固件再经过SPI接口烧到1500中,这个方式还有一个好处就是,不论1500中是否有固件以及固件是否好使,都可以通过这种方法进行烧写!并且不需要额外接线!这也是我采用它的原因。

        Built-in UART介绍如下,是通过1500自带的串口进行烧写,这种方式需要额外接线,所以不考虑,

         OTA是先将固件上传到一个文件服务器,然后wifi模块联网,从这个文件服务器中下载固件。我先按照这种方式进行更新固件,但是配置页面并没有更改,不知道什么原因。所以最终选择用Serial Bridge方式进行固件更新。

        这里我们参考另一个官方手册

 链接如下,

https://www.microchip.com/en-us/product/ATWINC1500

这里对serial bridge的描述不多,但它指向另一个文档,integrated serial flash memory download procedure。我们打开它。

        在这个文档中是基于一个firmwaire update project,而这个工程是在ASF中,所以我们需要下载ASF,

         ASF的下载页面如下,

Advanced Software Framework (ASF) for SAM Devices | Microchip Technology

 

大家下载完成解压, firmwaire update project在如下路径,

 我们进入该路径下firmware文件夹,

在该文件夹中我们能够看到很多批处理文件,从名字我们可以看出download_all_uart是采用串口进行固件更新的文件,这里我们需要对它进行更改,用记事本打开它,

FOR /L %%H IN (1,1,5) DO (
	echo ** Programming attempt %%H of 5...
	echo call download_all.bat UART %TGTCHIP% 0 %PRGPORTNUM%
	call download_all.bat UART %TGTCHIP% 0 %PRGPORTNUM% && goto okout
)

从上面代码可以知道这个脚本调用了download_all.bat,并且在调用的时候我们需要指定串口号,而确定串口号的代码如下,

set PRTIN=%1
if a%PRTIN%a==aa (
  call test_edbg.cmd comport.txt
  set /p PRGPORTNUM=<comport.txt
) else (
  set PRGPORTNUM=%PRTIN%
)
echo Using COM port %PRGPORTNUM%

这个确定过程很麻烦,我们直接根据实际的串口号修改以上代码如下,

set PRTIN=%1
set PRGPORTNUM=6
echo Using COM port %PRGPORTNUM%

查看设备管理器,我们的串口是COM6,所以这里赋值6,保存,关闭。

        接下来我们打开download_all,这里很关键的是下面代码,

:: winc_programmer_uart.exe -d wincXX00 -e -i m2m_image_XX00.bin -if prog -w -r -p \\.\COM73 -pfw ..\programmer_firmware\releaseXX00\programmer_firmware.bin
echo Call %ptool% -d winc%CHPFAM% -i m2m_image_%VARIANT%.bin -if prog -e -w -r -pfw ..\programmer_firmware\release%VARIANT%\%PFW%
%ptool% -d winc%CHPFAM% -i m2m_image_%VARIANT%.bin -if prog -e -w -r -pfw ..\programmer_firmware\release%VARIANT%\%PFW%

从上面代码中我们可以看出,这个脚本实际是调用winc_programmer_uart的一个应用程序来和单片机进行通信的,进而烧写固件的。而winc_programmer_uart是在firmware文件夹下,在该文件夹中,我们打开cmd,并且输入winc_programmer_uart.exe -h,如下,查看它的帮助信息,

 这里有一个很关键的选项,如下,

 在我们调用winc_programmer_uart时,它首先会工作在115200的波特率下,但是紧接着它会将波特率调整到500000,而我们单片机一般指定了一个波特率后就不会再变了,所以这里我们不能让波特率变,也就是波特率一直保持在115200,所以,上面调用winc_programmer_uart的代码做如下更改,

echo Call %ptool% -uhr 115200 -d winc%CHPFAM% -i m2m_image_%VARIANT%.bin -if prog -e -w -r -pfw ..\programmer_firmware\release%VARIANT%\%PFW%
%ptool% -uhr 115200 -d winc%CHPFAM% -i m2m_image_%VARIANT%.bin -if prog -e -w -r -pfw ..\programmer_firmware\release%VARIANT%\%PFW%

也就是通过uhr选项,让波特率一直保持在115200!

        同样,download_all文件中又会调用update_pll_table.bat脚本,该脚本中,调用winc_programmer_uart时也需要添加uhr选项如下,

echo Updating PLL table in image for %UVARIANT% variant
echo %uptool% -uhr 115200 -d winc%UCHPFAM%  -r efuse -pfw programmer_firmware\release%UVARIANT%\%UPFW%

%uptool% -uhr 115200 -d winc%UCHPFAM%  -r efuse -pfw programmer_firmware\release%UVARIANT%\%UPFW% > efuse_tmp

        保存download_all和update_pll_table.bat,关闭,另外运行download_all_uart时,需要运行一个python脚本,如下, 

所以需要我们系统中安装python,这个安装过程大家自行百度,很简单。打开这个文件,其中调用print函数时没有加括号,这个在新版本python是会报错的,我们把print函数后面加上括号,如下,

def print_banks(banks):
    b = 0
    for bank in banks:
        print("BANK {}: ".format(b)),
        b += 1
        for word in bank:
            print("0x{0:08x} ".format(word)),
        print("")

保存,关闭。

        接下来我们打开单片机开发环境,这里我们用的是1020,所以打开MCUXpressoIDE,在工程中导入我们之前文章移植好的winc1500工程(文章最开始的链接),打开demo_config.h文件,解除USING_FW_UPDATE_OVER_SERIAL屏蔽,如下,

//#define USING_HTTP_DOWNLOAD
//#define USING_SEND_EMAIL
//#define USING_OTA_UPDATE
//#define USING_WEATHER_CLIENT
//#define USING_PROVISION_AP
//#define USING_PUBNUB
//#define USING_SIMPLE_GROWL
//#define USING_SSL_CONNECT
#define USING_FW_UPDATE_OVER_SERIAL

也就是说这里我们采用串口更新固件的例程,打开该例程(winc1500_fw_update_over_serial.c),该例程中有两个函数是我们在之前移植中没有实现的,分别是m2m_wifi_console_write_data和m2m_wifi_console_read_data,也就是串口读写的函数,这里我们实现如下,

uint8_t m2m_wifi_console_read_data(void){
	return (uint8_t)GETCHAR();
}

void    m2m_wifi_console_write_data(uint16_t length, uint8_t *p_buf){
	for(int i=0;i<length;i++){
		PUTCHAR(p_buf[i]);
	}
}

也就是我们利用调试用的GETCHAR和PUTCHAR函数实现,然后保存、编译、下载并且让代码跑起来。之后我们在电脑端直接双击download_all_uart,就可以开始更新固件了,如下,

call download_all.bat UART 3A0 0 6
Mode UART
Chip 3A0
Mode UART
Chip 1500
Checking for Python support:
D:\python\python.exe
C:\Users\39017\AppData\Local\Microsoft\WindowsApps\python.exe
OK

Updating PLL table in image for 3A0 variant
firmware\winc_programmer_uart.exe  -p \\.\COM6 -uhr 115200 -d winc1500  -r efuse -pfw programmer_firmware\release3A0\programmer_release_text.bin
XO Offset is 0x0185
firmware\image_tool.exe -c firmware\flash_image.config -c Tools\gain_builder\gain_sheets\new_gain.config -o firmware\m2m_image_3A0.bin -of prog  -cs "[pll table]\r\nfrequency offset is 0x0185"
Device Image Creation Tool 1.0.2 [r708] (Jul 28 2020)
Copyright (C) Microchip Technology Inc. 2020

processing region '[boot firmware]'
WINCFirmwareImageBuild: opening firmware file 'boot_firmware/release3A0/boot_firmware.bin'
written 1304 of 4096 bytes to image (32%)
processing region '[control sector]'
WINC1500ControlSectorBuild: creating control sector
written 64 of 8192 bytes to image (1%)
processing region '[pll table]'
Creating WiFi channel lookup table for PLL with xo_offset = 6.0781.
written 456 of 1024 bytes to image (45%)
processing region '[gain table]'
WINC1500GainBuildV2: creating gain tables
written 1600 of 3072 bytes to image (53%)
processing region '[root certificates]'
found certificate: Baltimore CyberTrust Root
found certificate: DigiCert High Assurance EV Root CA
found certificate: DigiCert SHA2 High Assurance Server CA
found certificate: Entrust Root Certification Authority
found certificate: GeoTrust Global CA
found certificate: GlobalSign Root CA
found certificate: GlobalSign
found certificate: Google Internet Authority G3
found certificate: QuoVadis Root CA 2
found certificate: VeriSign Class 3 Public Primary Certification Authority - G5
found certificate: Amazon Root CA 1
written 3620 of 4096 bytes to image (89%)
processing region '[tls certificates]'
written 0 of 8192 bytes to image (0%)
processing region '[http files]'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/default.html'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/style.css'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/favicon.ico'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/logo.png'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/error.json'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/scanresults.json'
HTTPFileSystemAddFile: opening HTTP file 'provisioning_webpage/ok.json'
written 7548 of 8192 bytes to image (93%)
processing region '[connection parameters]'
written 0 of 4096 bytes to image (0%)
processing region '[downloader firmware]'
WINCFirmwareImageBuild: opening firmware file 'downloader_firmware/release3A0/downloader_firmware.bin'
written 4628 of 241664 bytes to image (2%)
processing region '[wifi firmware]'
WINCFirmwareImageBuild: opening firmware file 'firmware/wifi_v111/ASIC_3A0/wifi_firmware.bin'
written 235286 of 237036 bytes to image (100%)
processing region '[ate firmware]'
WINCFirmwareImageBuild: opening firmware file 'ate_firmware/burst_tx_firmware_winc1500.bin'
written 76736 of 765952 bytes to image (11%)
Successful
Downloading Image...
Call winc_programmer_uart.exe  -p \\.\COM6 -uhr 115200 -d winc1500 -i m2m_image_3A0.bin -if prog -e -w -r -pfw ..\programmer_firmware\release3A0\programmer_release_text.bin
WINC Programming Tool 1.0.3 [r708] (Jul 28 2020)
Copyright (C) Microchip Technology Inc. 2020

software WINC serial bridge found, baud rate changes supported
chip ID is 0x001503a0
programming firmware file: ..\programmer_firmware\release3A0\programmer_release_text.bin
starting device
reinitialise serial bridge to 115200
waiting for firmware to run
flash ID 0xc21320c2
flash size is 4 Mb

begin erase operation

 0x000000:[eeeeeeee] 0x008000:[eeeeeeee] 0x010000:[eeeeeeee] 0x018000:[eeeeeeee]
 0x020000:[eeeeeeee] 0x028000:[eeeeeeee] 0x030000:[eeeeeeee] 0x038000:[eeeeeeee]
 0x040000:[eeeeeeee] 0x048000:[eeeeeeee] 0x050000:[eeeeeeee] 0x058000:[eeeeeeee]
 0x060000:[eeeeeeee] 0x068000:[eeeeeeee] 0x070000:[eeeeeeee] 0x078000:[eeeeeeee]

begin write operation

 0x000000:[ww.ww..w] 0x008000:[w.wwwwww] 0x010000:[wwwwwwww] 0x018000:[wwwwwwww]
 0x020000:[wwwwwwww] 0x028000:[wwwwwwww] 0x030000:[wwwwwwww] 0x038000:[wwwwwwww]
 0x040000:[wwwwwwww] 0x048000:[wwwwwwww] 0x050000:[wwwwwwww] 0x058000:[........]
 0x060000:[........] 0x068000:[........] 0x070000:[........] 0x078000:[........]

begin read operation

 0x000000:[rrrrrrrr] 0x008000:[rrrrrrrr] 0x010000:[rrrrrrrr] 0x018000:[rrrrrrrr]
 0x020000:[rrrrrrrr] 0x028000:[rrrrrrrr] 0x030000:[rrrrrrrr] 0x038000:[rrrrrrrr]
 0x040000:[rrrrrrrr] 0x048000:[rrrrrrrr] 0x050000:[rrrrrrrr] 0x058000:[rrrrrrrr]
 0x060000:[rrrrrrrr] 0x068000:[rrrrrrrr] 0x070000:[rrrrrrrr] 0x078000:[rrrrrrrr]

verify range 0x000000 to 0x080000
begin verify operation

 0x000000:[pp.pp..v] 0x008000:[p.vvvvvv] 0x010000:[vvvvvvvv] 0x018000:[vvvvvvvv]
 0x020000:[vvvvvvvv] 0x028000:[vvvvvvvv] 0x030000:[vvvvvvvv] 0x038000:[vvvvvvvv]
 0x040000:[vvvvpvvv] 0x048000:[vvvvvvvv] 0x050000:[vvvvvvvp] 0x058000:[........]
 0x060000:[........] 0x068000:[........] 0x070000:[........] 0x078000:[........]

verify passed
*************** Download worked *****************
请按任意键继续. . .

大家可以看到,这里的更新固件,也会更新配置页面,为了验证效果,我把配置页面的背景改成了红色,

 烧写完成后,运行USING_PROVISION_HTTP例程,出现上面页面,说明固件更新成功!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值