A bootloader program takes 17K. So my main program starts at address 0x5000.
In the linker file I configure
MEMORY {
m_interrupts (RX) : ORIGIN = 0x00005000, LENGTH = 0x000001E8
m_text (RX) : ORIGIN = 0x00005410, LENGTH = 0x000FABF0
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_data_20000000 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
/*m_cfmprotrom (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010*/
}
And generate a bin file (in KDS). When I open the file I see the main program starts at address 0x5000 in the file. So I cut out the block 0-0x4FFF and write the bin file starting at address 0x5000.
But when I exit the bootloader my main program doesn’t run.
I was trying to burn the file as is - the same result.
What is wrong?
In MCUXpresso bin file generated at address 0. What should I set in KDS?
I need to understand - if I generate a bin file and I see my program starts at 0x5000 in the file - should I start burning the file from this line?
Cause I burn from the offset but my program doesn't start. When I read back the data burned on the page - say at address 0x5000 - and compare with the bin file - I see the same data.
I really cannot answer your questions, as they are too generic. It all depends on your device used, what bootloader you use, how you have architected your application.
Just looking at the address or the bin file or the memory does not say much: you have to understand what your bootloader does and what your application does. Best for this is if you step with the debugger through your bootloader and check what it is doing: then you will know what and why it is failing.
First I erase all pages
case FC_STATE_EREASE:
{
m_pRecFrame[m_uiRecCount++] = uiReadData;
if( m_uiRecCount >= sizeof(uint32_t) )
{
// check the address validity
if ( (m_RecFrame.uiAddress < RELOCATION_VERTOR_ADDR) || (m_RecFrame.uiAddress > (USER_FLASH_END_ADDR-ERASE_BLOCK_SIZE)) )
{
UART_Send(FC_CMD_NACK);
}
else
{
if(!Flash_EraseSector(m_RecFrame.uiAddress))
{
erase_count++;
UART_Send(FC_CMD_ACK);
}
else
UART_Send(FC_CMD_NACK);
}
g_ucFC_State = FC_STATE_WORKING;
}
}
break;
And I see erase_count equals the pages I need to erase (bin_file_size / page_size) + 1.
Next I write all pages by write chunks (64 bytes)
case FC_STATE_WRITE_DATA:
{
m_pRecFrame[m_uiRecCount++] = uiReadData;
if( m_uiRecCount > (m_RecFrame.Length + sizeof(uint32_t) ))
{
Memcpy_Byte((uint8_t *)&m_ucDataBuff[0], (uint8_t *)&m_RecFrame.DataBuff[0], m_RecFrame.Length);
uiNumberCount ++;
// check address is valid
if ( (m_RecFrame.uiAddress < RELOCATION_VERTOR_ADDR) || (m_RecFrame.uiAddress > (USER_FLASH_END_ADDR-ERASE_BLOCK_SIZE)) )
{
UART_Send(FC_CMD_NACK);
}
else
{
if( !Flash_Write(m_RecFrame.uiAddress, (uint8_t *)&m_ucDataBuff[0], m_RecFrame.Length) )
{
write_count++;
UART_Send(FC_CMD_ACK);
}
else
UART_Send(FC_CMD_NACK);
}
g_ucFC_State = FC_STATE_WORKING;
}
}
break;
And I see write_count equals number of chunks I sent.
So I pretty sure the burn process was successful. The same (official) bootloader burns srec file and the main program runs. So it seems like something wrong with the bin file.
Hello @john71,
The code that you attached is from your bootloader? If this is the case, how are you jumping to the application after loading the binary? Did you change the PSP, MSP and VTOR before jumping?
Best Regards,
Alexis Andalon
I can jump to a user application by pressing the Quit button.
case FC_CMD_QUIT:
{
SCB_VTOR = RELOCATION_VERTOR_ADDR;
JumpToUserApplication(RELOCATION_VERTOR_ADDR);
}
break;
Or I can release the boot pin on power up
if ((cMAINT_GetVal()) && (cBOOT_GetVal()))
{
for(;;)
{
if( !FC_Communication() )
{
if( g_ucFC_State == FC_STATE_NULL)
{
uiNullCounter++;
if(uiNullCounter > 0xFFFF)
{
uiNullCounter = 0;
uiRepeatCount++;
UART_SendChar(0xFC);
}
}
}
}
}
else
{
#ifdef FLASH_LOCATION
SCB_VTOR = RELOCATION_VERTOR_ADDR;
JumpToUserApplication(RELOCATION_VERTOR_ADDR);
#endif
}
The code is the same that works with in Universal Bootloader (AN2295).
I created a bin file from a srec file (srec_cat.exe MK10.srec -o MK10.bin -binary). and I see the first line
00000000 FF FF FF FF FF FF FF FF FF FF FF FF 76 FF FF FF
then goes a zeros block and the code starts at offset
00005000 00 00 00 20 A9 FB 01 00 79 23 02 00 79 23 02 00 and so on.
Now I start to burn the srec file with the Universal Bootloader and set a break point at the first write to a flash.
And I see the burn data starts with FF FF FF FF FF FF FF FF FF FF FF FF 76 FF FF FF not with 00 00 00 20 A9 FB 01 00 79 23 02 00 79 23 02 00. Is there something I miss to understand?
Hello @john71,
The application note mention that the address to the new vector table is 0x4000, make sure that all the macros point to the new application address.
Also, if I'm understanding correctly, the first block is discarded but the first line of the discarded block is being written in the first position?
Best Regards,
Alexis Andalon
So what the binary file offset I should start to burn at address 0x4000 in the flash? If I understand correct at the address 0x4000 in the flash I should start to burn the line that starts at 0x4000 in the binary file?
Hello @john71,
The address should match the RELOCATION_VERTOR_ADDR mentioned in your bootloader, also, could you let me know which MCU are you using?
Best Regards,
Alexis Andalon