Hi dialog staff
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); // set P0_6 spi mosi (data out)
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); // Enable FLASH with High low transition
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
}
but when i try to boot 580 by uart, i found it doesn’t work, so i guess is firstBootloader restrict code size smaller than 32k?
and do a confirmation :
1. smartSnippets download secondaryBootloader by uart and it work
2.smartSnippets下载我的弗兰克-威廉姆斯uart 580 run secondaryBootloader, and this time, it work !!!!
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.
Regarding the 32K limitation of the primary bootloader, there isn't such kind of limitation, the bootaloder for the SPI and UART is the same and there is no limitation to none of them, the only thing that the primary bootloader checks is the crc at the end of each download.
Thanks MT_dialog
Hi dialog staff, thanks for your answer!
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.
The 32K limitation of the primary bootloader is exist when booting from flash, so i have to add a codeLoader() to finish the fw loading.
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!