3 flash调试常见问题¶
3.1 The process of debugging Nand Flash for SF32LB551’s Flash3;?¶
SF32LB551 Flash3连接在QSPI3,调试Nand flash注意点:
1,Ensure that QSPI Controller 3 Enable is turned on and the memory size is set;,
下图为128MB(1G bit/)
2,Since QSPI3 will occupy PA49 and PA51, the log of hcpu must be changed to segger output;,具体方法参考 2.2.1 。
3, Check the mode settings of PA44, PA45, PA47, PA49, PA51, PA55 used by QSPI3 as follows, and confirm that these Pins are not used elsewhere;,确认方法,在Hcpu的shell平台分别用:pin status 44 命令查看各个pin状态是否设置正确。
4,Open the macro #define DRV_SPI_FLASH_TEST to support the test shell command for spi_flash read and write flash;。
5,用如下命令测试Flash读写是否正确。
具体命令参考函数int cmd_spi_flash(int argc, char *argv[])
spi_flash -id 0 2 /*显示flash3的ID,读操作发生在开机初始化,需要上电抓波形 */
spi_flash -read 0 2048 2 /*从flash3 十进制0的地址,读取2048个byte数据*/
spi_flash -read 4096 4096 2 /*从flash3 十进制4096的地址,读取4096个byte数据*/
spi_flash -write 4096 4096 0 2 /*从flash3 十进制地址4096,写4096个byte数据*/<
spi_flash -erase 0x20000 0x20000 2 /*从flash3 十六进制0x20000的地址,擦除0x20000个byte数据,注意只能按块擦除,地址和大小只能0x20000倍数 */<br>
注意:
Current NAND Flash read/write needs to be done in a page, but must be erased in block size;,见下图:
Each page has 2176 units, so each page is 2048Byte + 128Byte (SA);。
Each Block consists of 64 pages, so the capacity of each Block is 2048x64=131,072 (0x20000), which is 131,072Byte + 8KByte (SA);
6,The new flash is not in the nand_cmd_id_pool list, using the spi_flash -id 0 2 command to read the id of flash3 will return 0xff;,
Note: If the logic analyzer captures the timing of reading ID, it needs to be captured when powering on, the operation of reading ID occurs when powering on;,
spi_flash -id 0 2命令只是打印出上电初始化时读到的ID。
7,The ID read back by the spi_flash -id 0 2 command, the read back value is as follows;:
msh >spi_flash -id 0 2
spi_flash -id 0 2
rt_flash_read_id_addr: 0x68000000,id:2,value:7fa5a1
The elf driver of the new jlink, uart3 currently has added a log for printing ID when downloading at address 0x68000000;,
如下图:
Add the corresponding group into the nand_cmd_id_pool list in nand_table.c according to the command method;,如下图:
{0xa1, 0xa5, 0x7f, 0, 0x8000000}, //FM25LS01_RDID
如果命令跟type2的命令一样,就能读写正常,通常修改nand_table.c文件
nand_cmd_id_pool和nand_cmd_table_list后,就能进行读擦写操作了。
8,If among the four Types, the timing captured by the logic analyzer does not match with any of the several groups of type timings for the debugged Nand Flash, then another Type needs to be defined to send the timing;。
3.2 The process of mounting Flash4 for SF32LB555 Lcpu;¶
以A3芯片的\watch\sifli\project\ec-lb555_lcpu工程支持挂载flash4为例,参考如下附件差分包,相关修改差分都已经加上:
需要将\middleware\sifli_lib\lib下面的相关rom lib(A3芯片为sifli_rom_a3.lib,其他版本A0\A1\A2为sifli_rom.lib)文件里面flash相关函数拿掉,不要用rom里面的函数,采用代码中的函数,客户手中的rom lib文件可能版本不一,需要重点检查里面的FLASH相关函数。
Modify the bf0_pm_a0.c file under \middleware\system;
Modify the drv_spi_flash.c file under \rtos\rtthread\bsp\sifli\drivers;
修改\watch\sifli\project\ec-lb555_lcpu\linker_scripts下面的
link_lcpu_ram.sct分区文件,将一些算法放进flash4中
Modify the menuconfig of \watch\sifli\project\ec-lb555_lcpu, open QSPI FLASH4 support;
Modify the postbuild.bat file under \watch\sifli\project\ec-lb555_lcpu, add new compilation file bin;
Modify the SConstruct file under \watch\sifli\project\ec-lb555_lcpu, add new compilation file bin;
PS:编译的时候需要将ec-lb555_lcpu下的build手动删除掉,如果之前已经存在了bin
文件,可能会出现编译不过的情况,编译成功之后请检查
\watch\sifli\project\ec-lb555_lcpu\build\watch_l.bin下是否增加了ER_IROM2文件:
3.3 读Flash内SN/MAC接口¶
SN and MAC are written into the device in the production line download version, saved in TLV format;,
TLV is a commonly used data encoding format, it consists of three parts: tag (Type), length (Length) and value (Value), that is, arranged according to ID+LEN+DATA;。
数据格式可以参考章节:
5.6 55X查看芯片工厂校准区OTP/Flash数据方法
type |
length |
value |
---|---|---|
1byte |
1byte |
<=256byte |
The type number of SN is: FACTORY_CFG_ID_SN, the corresponding value is 2;。
The composition of value: descriptor + serial number (8byte) such as: sifli_00000001;
Get sn sample code;:
{
int res = 0;
char sn[300] = {0};
res = rt_flash_config_read(FACTORY_CFG_ID_SN, (uint8_t) *)&sn[0], 256);
}
rt_flash_config_read(FACTORY_CFG_ID_SN, (uint8_t *)mac, sizeof(mac));
//Get MAC address method;
rt_flash_config_read(FACTORY_CFG_ID_MAC, (uint8_t *)&mac[0], 6);