cancel
Showing results for 
Search instead for 
Did you mean: 

Jump from application code to system memory bootloader on STM32WB15CC

Coco
Associate II

Hello, I'm trying to flash my STM32WB15CC using UART1 without using pin BOOT0(PH3). I'm using a NUCLEO-WB15CC. For that I know that I've to set some bits in OPTR register and jump from application code to memory system bootloader and then connect to UART1.
I've found how to do it using STM32CubeProgrammer by setting the bits SWBOOT0 = 0, BOOT0 = 0 and BOOT1 = 1.

But when I'm trying to jump from application code to the system memory bootloader by setting these bits that doesn't work and I can't find a way to do it. Anybody know how to do that ?

This is my code

 

FLASH->OPTKEYR = FLASH_KEY1;
FLASH->OPTKEYR = FLASH_KEY2;

//Clear OPTLOCK option lock bit
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTLOCK_Msk);

//Check Flash memory is not busy
while ((FLASH->SR & FLASH_SR_BSY) != 0) {}

//Write the desired options value in the options registers
CLEAR_BIT(FLASH->OPTR, FLASH_OPTR_nSWBOOT0_Msk);
CLEAR_BIT(FLASH->OPTR, FLASH_OPTR_nBOOT0_Msk);
SET_BIT(FLASH->OPTR, FLASH_OPTR_nBOOT1_Msk);

//Set the Options Start bit OPTSTRT
SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT_Msk);

//Check Flash memory is not busy
while ((FLASH->SR & FLASH_SR_BSY) != 0) {}

SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH_Msk);

 

Thank you in advance for your help
 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello Pierre, thanks for you answer and I had already read this application note.
In the meantime, I was able to resolve my issue by running the code below.

 

void goto_system_memory_bootloader() {
	/* Unlock the FLASH control register access */
	HAL_FLASH_Unlock();
	/* Unlocks the option bytes block access */
	HAL_FLASH_OB_Unlock();

	FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);

	FLASH_OBProgramInitTypeDef OBInitStruct;

	HAL_FLASHEx_OBGetConfig(&OBInitStruct);

	OBInitStruct.OptionType = OPTIONBYTE_USER;
	OBInitStruct.UserType = OB_USER_nSWBOOT0;

	CLEAR_BIT(OBInitStruct.UserConfig, FLASH_OPTR_nSWBOOT0);
	SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);

	/* Unlock the FLASH control register access */
	HAL_FLASH_Unlock();

	/* Unlock the option bytes block access */
	HAL_FLASH_OB_Unlock();

	HAL_FLASHEx_OBProgram(&OBInitStruct);

	FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);

	/* Launch the option byte loading */
	HAL_FLASH_OB_Launch();

	/* Locks the option bytes block access */
	HAL_FLASH_OB_Lock();
	/* Lock the FLASH control register access */
	HAL_FLASH_Lock();
}

 

View solution in original post

2 REPLIES 2
Pierre_Paris
ST Employee

Hello @Coco,

Thank you for your question.

Have you considered this article titled How to jump to system bootloader from application code on STM32 microcontrollers ?

Also, I advise you to read the STM32 microcontroller system memory boot mode -  Application note and particularly the chapter 72 on the STM32WB10xx/15xx bootloader.

Best Regards,

Pierre

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello Pierre, thanks for you answer and I had already read this application note.
In the meantime, I was able to resolve my issue by running the code below.

 

void goto_system_memory_bootloader() {
	/* Unlock the FLASH control register access */
	HAL_FLASH_Unlock();
	/* Unlocks the option bytes block access */
	HAL_FLASH_OB_Unlock();

	FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);

	FLASH_OBProgramInitTypeDef OBInitStruct;

	HAL_FLASHEx_OBGetConfig(&OBInitStruct);

	OBInitStruct.OptionType = OPTIONBYTE_USER;
	OBInitStruct.UserType = OB_USER_nSWBOOT0;

	CLEAR_BIT(OBInitStruct.UserConfig, FLASH_OPTR_nSWBOOT0);
	SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);

	/* Unlock the FLASH control register access */
	HAL_FLASH_Unlock();

	/* Unlock the option bytes block access */
	HAL_FLASH_OB_Unlock();

	HAL_FLASHEx_OBProgram(&OBInitStruct);

	FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);

	/* Launch the option byte loading */
	HAL_FLASH_OB_Launch();

	/* Locks the option bytes block access */
	HAL_FLASH_OB_Lock();
	/* Lock the FLASH control register access */
	HAL_FLASH_Lock();
}