cancel
Showing results for 
Search instead for 
Did you mean: 

Custom bootloader STM32F405VG

abarrotes
Associate II
Posted on November 26, 2016 at 00:33

Hello,

I'm working in a custom bootloader. I have follow many discussions here and then i end up with this code.

commenting the function PerformFirmwareUpdate() the code works ok!  

pFunction appEntry;

uint32_t appStack;

HAL_Init();

/* Get the application stack pointer (First entry in the application vector table) */

appStack = (uint32_t) *((__IO uint32_t*)EXEC_ZONE_ADDR);

/* Get the application entry point (Second entry in the application vector table) */

appEntry = (pFunction) *(__IO uint32_t*) (EXEC_ZONE_ADDR);// + 4);

if (CheckFirmwareUpdate)

//PerformFirmwareUpdate();

HAL_DeInit();

/* Reconfigure vector table offset register to match the application location */

SCB->VTOR = EXEC_ZONE_ADDR;

/* Set the application stack pointer */

__disable_irq();

__set_MSP(appStack);

__DSB();

/* Start the application */

appEntry();

when i uncomment the function which copies the program in the execution sector (5), then i get the problem:

the 

appEntry gets the value of sector 6 instead of sector 5 which is the real value assigned.

void PerformFirmwareUpdate(void)

{

if (FlashErase(FLASH_SECTOR_5))//(FLASH_SECTOR_5);

{

uint32_t *data_ptr = (uint32_t *)PROG_ZONE_ADDR;

HAL_FLASH_Unlock();

for(uint32_t i = 0; i < (SECTOR_SIZE); i += sizeof(uint32_t), data_ptr++ )

{

if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EXEC_ZONE_ADDR + i, *data_ptr) != HAL_OK)

{ //WORD = 32bits

break;

}

FLASH_WaitForLastOperation (4000); //in ms, max time to erase whole sector; see datasheet

}

HAL_FLASH_Lock();

}

return;

}

Thanks to all, I hope someone could help me with this!

#stm2 #bootloader #stm32f4 #!stm32-!bootloader #c
14 REPLIES 14
abarrotes
Associate II
Posted on November 28, 2016 at 03:11

Not, I plan to run the code at 0x08020000.

The code in 0x08040000 will be flashed from the firmware application and then reset, start the boot and copy from 0x08040000 to 0x0802 and finally run in 0x0802. 

obviously, this is my start point because I also have to validate the code.

Thanks for the source, I'm reading it.

Posted on November 28, 2016 at 04:17

Ok, so why build it for 0x08040000? If you have it as a binary blob you can write it at any address you want. I wouldn't need a .HEX file

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 28, 2016 at 04:23

Build the code for 0x08020000, I'd take that either as an .ELF/AXF or .HEX, convert that to a binary image suitable for flashing, with a CRC added on the end to ensure the integrity of the image.  The loader could check this prior to jumping to the new image, or copying from 0x08040000 to 0x08020000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
abarrotes
Associate II
Posted on November 30, 2016 at 02:26

abarrotes
Associate II
Posted on December 02, 2016 at 03:03

Clive the problem was solved, thanks for your help!

1) My hextobin.exe was not converting properly! 

I'm using the keil tool fromelf.exe instead and right now things are working.

2) I'm using the STM u-link utility to load the bin directly