cancel
Showing results for 
Search instead for 
Did you mean: 

Having trouble booting from Bank2 and jumping to Bank1 on STM32G474

TKuhn.1
Associate

Hello,

I'm working on an a project that uses an ST32G474, and it needs to run two different/independent applications. The project requires that from a reset, the device boots from Bank2 every time. The application in Bank2 will then decide if it is ok to then jump to, and start running the application that is stored in Bank1.

The dual-boot example from ST isn't exactly what is needed, because it flips the BFB2 option bit during each boot, to toggle between banks. My application requires to always boot from Bank2, and then jump to Bank1, without going through a reset operation.

From reset, I'm able to get App1 to run from Bank1 when BFB2 is cleared, and also from reset, I'm able to get App2 to start and run from Bank2 when BFB2 is set. However, when I try to jump from App2 to App1, I'm not succeeding. Through various different tests, it looks as though App2 somehow either jumps to itself, or I jump somewhere and just crash.

I've tried to figure this out reading various different posts about jumping to the system bootloader, etc., and the code below contains various things I've tried, some commented. I think when the BFB2 bit is set, the processor is remapping the memory, so that the start of Bank2 is at memory address zero. And I've tried jumping to 0x08000000, and to 0x08040000, but doesn't work in either case.

Just trying to figure out what I'm missing. Hardware guy here trying to get some firmware to work. Thanks for any insight.

void jump_to_App1(void)
{
	void (*app_reset_handler)(void);
	volatile uint32_t addr = 0x8000000UL;
	//HAL_RCC_DeInit();
	HAL_DeInit();
	//SysTick->CTRL = 0;
	//SysTick->LOAD = 0;
	//SysTick->VAL = 0;
	__disable_irq();
	SCB->VTOR = addr;//FLASH_BASE;
	app_reset_handler = (void*)(*(__IO uint32_t *)(addr + 4));
	__set_MSP(*(uint32_t *)addr);
	//HAL_DeInit();
	app_reset_handler();
}

1 ACCEPTED SOLUTION

Accepted Solutions
Imen.D
ST Employee

Hello @TKuhn.1​ and welcome to the STM32 Community =)

Are using the bootloader version v13.3 ? It seems there is a jumping problem between banks with the bootloader v13.3

As stating on the AN2606: the dual boot from bank 2 is not working on the bootloader V13.3

0693W000008zMh6QAE.jpg 

To be ensure that the bootloader version used is v13.3 please folow these steps:

  • connect the board to STM32Cubeprogrammer
  • read the address 0x1FFF6FFE
  • the first bytes must have value 0xD3:

D ==> 13

3 ==> .3

For more details on how to identify the bootloader version - this is described in AN2606 application note - in chapter "4.2 Bootloader identification".

Otherwise, it is noted in the AN2606:

"For STM32 devices having the Dual Bank Boot feature, to jump to system memory from user code the user has first to remap the System Memory bootloader at address 0x00000000 using SYSCFG register (except for STM32F7 Series), then jump to bootloader.."

Maybe to jump, try to add this line in your code just before jumping:

SYSCFG->MEMRMP = 0x1;

Hope this helps ! Please, let me know about your progress on this issue.

Please mark my answer as best by clicking on the "Select as Best" button if it helped =)

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

View solution in original post

2 REPLIES 2
Imen.D
ST Employee

Hello @TKuhn.1​ and welcome to the STM32 Community =)

Are using the bootloader version v13.3 ? It seems there is a jumping problem between banks with the bootloader v13.3

As stating on the AN2606: the dual boot from bank 2 is not working on the bootloader V13.3

0693W000008zMh6QAE.jpg 

To be ensure that the bootloader version used is v13.3 please folow these steps:

  • connect the board to STM32Cubeprogrammer
  • read the address 0x1FFF6FFE
  • the first bytes must have value 0xD3:

D ==> 13

3 ==> .3

For more details on how to identify the bootloader version - this is described in AN2606 application note - in chapter "4.2 Bootloader identification".

Otherwise, it is noted in the AN2606:

"For STM32 devices having the Dual Bank Boot feature, to jump to system memory from user code the user has first to remap the System Memory bootloader at address 0x00000000 using SYSCFG register (except for STM32F7 Series), then jump to bootloader.."

Maybe to jump, try to add this line in your code just before jumping:

SYSCFG->MEMRMP = 0x1;

Hope this helps ! Please, let me know about your progress on this issue.

Please mark my answer as best by clicking on the "Select as Best" button if it helped =)

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
TKuhn.1
Associate

Thanks Imen!

The bootloader on the part I have is 13.4, so that part is OK.

Thank you for your suggestion of looking at the SYSCFG register...looking there helped me figure out what to do. When the BFB2 bit is set, and you boot from bank-2, the FB_MODE bit in the SYSCFG register gets set to '1'. I found this out by loading a simple application to bank-2 (loading to 0x0804 0000), setting BFB2 to '1', then booting the processor and using CubeProgrammer to connect in "Hot Plug" mode, and look at the SYSCFG register.

This picture, from AN4767 shows that when FB_MODE is set, the addresses are remapped:

0693W00000AM84fQAD.png 

So, with BFB2 set, and FB_MODE set, when I want to jump to the application that resides in Bank-1, I need to jump to the address: 0x0804 0000

Also, one thing I needed to do that I hadn't done before, was to alter the linker script for the application in Bank-1, and change the FLASH ORIGIN to 0x0804 0000, as opposed to 0x0800 0000. After building that, load the .bin to location 0x0800 0000, and jumping to application-1 in bank-1 worked!