嗨对话人员
i develop my application on 14580 base sdk5.0.3 and my code size is about 32.4K, biger than otp 32K limit.
so i modified the scatter to support it (use UM-B-011),
and add a “coderLoader” call when sysinit, i burn the fw into flash and found it work well!
##### the code i add
"coderLoader" in system_ARMCM0.c and call it after systemInit fun
//#define BOOT_FROM_FLASH
#ifdef BOOT_FROM_FLASH
#define SYSRAM_CODE_START_ADDR 0x20008000L
#define sysram_code_stop_addr 0x20009200L.
#define SYSRAM_CODE_SPI_ADDR 0x8008
void CodeLoader(void)
{
unsigned char *p_code;
if ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP)
return;
SetWord16(P0_SET_DATA_REG,1<<3); // set P0_3 to high
SetBits16(SYS_CTRL_REG,PAD_LATCH_EN,1); // open pad latches
SetBits16(PMU_CTRL_REG,PERIPH_SLEEP,0); // exit power down peripheral
SetWord16(CLK_PER_REG, SPI_ENABLE);
SetWord16(P03_MODE_REG,PID_SPI_EN+OUTPUT); // set P0_3 spi cs (master mode, output)
SetWord16(P00_MODE_REG,PID_SPI_CLK+OUTPUT); // set P0_0 spi clk (master mode, output)
setword16(p06_mode_reg,pid_spi_do);//设置P0_6 SPI MOSI(数据出版)
SetWord16(P05_MODE_REG,PID_SPI_DI+INPUT_PULLUP); // set P0_5 spi miso (data in)
SetWord16(P0_SET_DATA_REG,1<<3); // Deactivate,
p_code = (unsigned char *)(SYSRAM_CODE_START_ADDR);
//init SPI for master, mode 3
SetWord16(SPI_CTRL_REG,0);
SetWord16(SPI_CTRL_REG,SPI_POL+SPI_PHA);
SetWord16(SPI_CTRL_REG,SPI_POL+SPI_PHA+SPI_ON+0x0100);
setword16(p0_reset_data_reg,1 << 3);//启用高转换的闪光灯
SetWord16(SPI_RX_TX_REG1, 0x0300); // SPI_RX_TX_REG1 0x50001204
setword16(spi_rx_tx_reg0,sysram_code_spi_addr);// spi_rx_tx_reg0 0x50001202 // sysram_code_spi_addr 0x8008
而(GetBits16 (SPI_CTRL_REG SPI_INT_BIT) = = 0);//polling to wait for spi have data
SetWord16(SPI_CLEAR_INT_REG, 0x01); // clean pending flag
SetWord16(SPI_CTRL_REG,SPI_POL+SPI_PHA+SPI_ON); //SPI_CTRL_REG 0x50001200
while(p_code < (unsigned char *)SYSRAM_CODE_STOP_ADDR) //SYSRAM_CODE_STOP_ADDR 0x20009800L
{
setword16(spi_rx_tx_reg0,0x00);// spi_rx_tx_reg0(0x50001202)/ * spi rx / tx register0 * /
而(GetBits16 (SPI_CTRL_REG SPI_INT_BIT) = = 0);//polling to wait for spi have data
*p_code++ = GetWord16(SPI_RX_TX_REG0); // read byte from SPI
SetWord16(SPI_CLEAR_INT_REG, 0x01); // clean pending flag
}
SetWord16(P0_SET_DATA_REG,1<<3); // Deactivate,
SetWord16(SPI_CTRL_REG, 0); // Reset SPI
}
但是当我尝试通过UART启动580时,我发现它不起作用,所以我猜是FirstBootloader限制代码大小小于32K?
and do a confirmation :
1. smartSnippets download secondaryBootloader by uart and it work
2. SmartSnippets在580运行SecondaryBootloader时通过UART下载我的FW,这次工作!!!!
can you explan it ?
Hi orient,
To see if i got thinks correctly you managed to have a fw that is larger than 32K, when you place it in the flash your program works correctly but when you download the code via UART
using Smart Snippets it doesn't.
1) So in order to debug this you try to run the secondary bootloader via UART from smart snippets and the secondary bootloader worked (as it should be).
2) And then you try to download your fw while the secondary bootloader was allready running via Smart Snippets ? I cant see how this is possible, i mean that when a fw is running and you try to download code via the Smart Snippets over UART the tool requests to hit the reset button in order for the primary bootloader to run and download the fw. So as far as can see the fw was downloaded in the 580 by the primary bootloader since the secondary bootloader after reset wasn't actually running.
关于主引导加载程序的32k限制,没有这样的限制,SPI和UART的Bootaloder是相同的,并且没有限制它们,主引导加载程序检查的唯一是CRC每个下载结束。
Thanks MT_dialog
嗨对话人员,谢谢你的答案!
I run the secondary bootloader via UART from smart snippets and the secondary bootloader worked . And then download my fw while the secondary bootloader was allready running via Smart Snippets. i hit the download button but do no hit the reset button, And I think Smart Snippets over UART the tool requests to hit the reset button because it need to receive the start byte from device.
so, inded, my fw is download via secondary bootloader not primary bootloader.
从Flash启动时,主引导加载程序的32K限制存在,因此我必须添加Codeloader()以完成FW加载。
Hi orient,
I wasn't aware for this limitation, but indeed there this kind of restriction in the bootrom, it seems that its not the bootrom code itself that has the limitation but how the bootrom code runs in the memory, if you start to provide more than 32K of data you overwrite variables of the bootcode itself so you will need the secondary bootloader for loading an image larger than 32K. In case you dont want to use the secondary bootloader, and you want to use this custom code loader scheme you will have to tweek the generated binary. You will have to provide a length that is equal to 32K in order for the bootrom to download into the sysram start executing and then run the code so that the CodeLoader to copy the rest of the image into your Sysram.
Thanks MT_dialog
Thank you!