cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader STM32L476

wh
Associate III
Posted on October 19, 2016 at 13:47

Dear all,

I'm working with a Nucleo-64 board and want to start the system boot loader from source code in combination with the Flash Loader Demonstrator, currently I'm trying the boot loader in combination with USART3 (PC4,PC5) The ST-link bridge to UART2 is disconnected by removal of SB14/SB14. I watched a few videos on youtube and tried the following startup code:

&sharpdefine BOOTLOADER_START_ADDR 0x1FFF0000

int main()

{

 HAL_RCC_DeInit();

 HAL_DeInit();

 

 __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();

 

 SysTick->CTRL = 0;

 SysTick->LOAD = 0;

 SysTick->VAL  = 0;

 

 uint16 id = *((uint32_t *)0x1FFF6FFE);

 

 __set_PRIMASK(1);       /// Disable Interrupts 

 

 uint32 map = *(__IO uint32_t*) 0x0;

 

 __set_MSP(0x20000000); /// Set main stack pointer

// __set_MSP(*(__IO uint32_t*) 0x20003100); /// Set main stack pointer

// __set_MSP(*(__IO uint32_t*) BOOTLOADER_START_ADDR); /// Set main stack pointer

// __set_MSP(*(__IO uint32_t*) 0x0); /// Set main stack pointer

 

// void(*bootloader)(void) = (void(*)(void)) *((uint32_t *)(BOOTLOADER_START_ADDR + 4)); 

 void(*bootloader)(void) = (void(*)(void)) *((uint32_t *)0x04);

 bootloader();

 

 while (1);

}

I tried different combination of setting the stack pointer and so but nothing seems to work. Does anyone have a working example in combination with the Nucleo-64 Dev Env? 

Any help is highly appreciated.

Best regards,

Wim 

#bootloader #bootloader #bootloader-stm32l476-nucleo-64
7 REPLIES 7
slimen
Senior
Posted on October 19, 2016 at 16:51

Hello,

Refer to the  to make sure that you've configured the right pins in the right mode, in the ''Table 100. STM32L476xx/486xx configuration in system memory boot mode''.

- USART3_RX : PC11 

- USART3_TX : PC10

Regards

Posted on October 19, 2016 at 17:07

Use a Debugger! Confirm you can actually step into the loader properly, and things are where they need to be.

Make sure the SYSCFG clock is enabled, otherwise it won't work.

The stack *descends* setting it to 0x20000000 will have it auto-decrement and FAULT. Use the value specified in the vector table for the loaded or pick some valid address in the middle or top of RAM, not the floor.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
wh
Associate III
Posted on October 24, 2016 at 16:36

Still no luck,

I changed the code as you suggested. The Stack pointer is pointing to address 200030D0 now. I'm trying to use the internal MSI clock. Using the debugger I can run al the way up to the boot loader call.  After that I can see the debugger running some code in assembler mode (no boot loader source code). The final while loop after the boot loader call is never reached. The only thing I'm not sure about is whether the system clock is running or not. Anyway, I still cannot connect using the Flash Loader. I also added some external pullup lines as suggested in one of the documents.

Best regards,

Wim

wh
Associate III
Posted on October 24, 2016 at 16:36

Still no luck,

I changed the code as you suggested. The Stack pointer is pointing to address 200030D0 now. I'm trying to use the internal MSI clock. Using the debugger I can run al the way up to the boot loader call.  After that I can see the debugger running some code in assembler mode (no boot loader source code). The final while loop after the boot loader call is never reached. The only thing I'm not sure about is whether the system clock is running or not. Anyway, I still cannot connect using the Flash Loader. I also added some external pullup lines as suggested in one of the documents.

Best regards,

Wim

wh
Associate III
Posted on October 24, 2016 at 16:37

Still no luck,

I changed the code as you suggested. The Stack pointer is pointing to address 200030D0 now. I'm trying to use the internal MSI clock. Using the debugger I can run al the way up to the boot loader call.  After that I can see the debugger running some code in assembler mode (no boot loader source code). The final while loop after the boot loader call is never reached. The only thing I'm not sure about is whether the system clock is running or not. Anyway, I still cannot connect using the Flash Loader. I also added some external pullup lines as suggested in one of the documents.

Best regards,

Wim

wh
Associate III
Posted on October 24, 2016 at 16:39

tried to attach a file. Did not work

void StartBootloader()

{

 HAL_RCC_DeInit();

 HAL_DeInit();

 __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();

 SysTick->CTRL = 0;

 SysTick->LOAD = 0;

 SysTick->VAL  = 0;

 uint32 addr = *(__IO uint32_t*)0;

 

 __set_PRIMASK(1);    /// Disable Interrupts

 __set_MSP(*(__IO uint32_t*)0); /// Set main stack pointer

 

 void(*bootloader)(void) = (void(*)(void)) *((uint32_t *)4); 

 

 __HAL_RCC_MSI_ENABLE();

 

 while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI);

 

 __GPIOC_CLK_ENABLE(); 

 bootloader();

 

 while (1);

}

Posted on October 24, 2016 at 17:55

This is a topic area I have repeatedly covered here, my view is that the best way to achieve transfer to System Loader is via a magic number based branch in the Reset_Handler where you *know* the system is in a reset state with no random peripherals, interrupts and clocks running.

Don't believe I've coded a specific example for the L4, it's not a part I'm using, but I'd entertain offers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..