STM32L072 Jumping to embedded bootloader from application code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-12-26 12:22 AM
Hi,
MCU version 20KB RAM, 128 KB FLASH category 5. I tried solutions on the web available for different STM32 MCU with no success. BOOT0 pin is fixed to GND in my custom PCB.
My final code flow is like below:
- Reset Handler
- Sytem init
- MSI as a system clock, reset all other clock settings
- and does something like below
SCB -> VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector table relocation in Internal Flash*/
- Main Function
int main(){
HAL_RCC_DeInit();
Systick -> CTRL = 0;
Systick -> LOAD =0;
Systick -> VAL =0;
__disable_irq();
HAL_FLASH_Unlock();
void (*foo)(void) = 0x00000004;
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
SCB -> VTOR = 0;
__set_MSP(0x20005000);
foo();
while(1);
}
When i debug, code jumps to the location 0x00000004 but after some instructions device jumps again to reset handler.
Can you correct me to make embedded USBDFU bootloader work ?
Thanks in advance,
- Labels:
-
Bootloader
-
STM32L0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-12-26 5:01 AM
Pretty sure there is no code at 4
And nothing on the other side enables the processor's IRQ again. ​
Unlocking the flash does not enable.the syscfg clock.​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-12-26 5:50 AM
Please note that i remapped the system memory. So 0x1FF00004(AN2606 says system memory start address is 0x1FF00000) is mapped to 4 actually. I could see it from debugger's disassembly section. I tried to enable syscfg clock with __HAL_RCC_SYSCFG_CLK_ENABLE() also, No success. Please help with more detailed comments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-12-26 8:22 AM
> So 0x1FF00004(AN2606 says system memory start address is 0x1FF00000) is mapped to 4 actually.
4 is not the address to jump to. It is address of address to jump to.
-- pa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-12-27 2:38 AM
((void (*)(void)) *((uint32_t*) 0x00000004))();
I observed same behavior with the above jump too. I mean, It jumps back to reset handler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-12-27 3:57 AM
Also, don't forget to set the stack pointer. The value is *(NULL) :)
-- pa
