cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in updating option bits for USB DFU bootloader

vishwadn
Associate

Hi,

  We are using STM32G0B1 MCU for our project. We need to use USB DFU for application reprogramming. I tried to to set option bits and then connect through USB DFU, everytime I set option bits through software and  flashing through debugger , USB DFU is connected only once. Once I disconnect debugger and restart the board, USB DFU is not getting connected even though I am Jumping to system bootloader from application. Its again coming back to application and running. In my test software, I am jumping to bootloader after application is run for defined time for ex., 10seconds. Please let me know is there anything to be done so that USB DFU is connected everytime after jumping to bootloader from application.

3 REPLIES 3
TDK
Super User

Show what you're doing. What option bytes are you changing, how are you jumping to bootloader, etc.

USB bootloader needs interrupts enabled.

If you feel a post has answered your question, please click "Accept as Solution".

I tried two methods:

1) https://github.com/olikraus/stm32g031/tree/main/enable_boot0

First method as mentioned in this link.

 

2) Second method by building below code, flashing on MCU , reset it and then run the application. From application, I am jumping to system bootloader and it works only once after flashing below code and with debugger connected. Second time when I restart the board without debugger, application runs and it jumps to bootloader when it is called but it again jumps back to application. I am not able to connect in USB DFU mode through STMCubeProgrammer.

FLASH_OBProgramInitTypeDef OBInit;

HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();

HAL_FLASHEx_OBGetConfig(&OBInit);

OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_nBOOT0 | OB_USER_nBOOT_SEL;

// Set nBOOT_SEL = 1 (ignore BOOT0 pin)
// Set nBOOT0 = 0 (boot from system memory = USB DFU)
OBInit.USERConfig |= OB_nBOOT_SEL;
OBInit.USERConfig &= ~OB_nBOOT0;

HAL_FLASHEx_OBProgram(&OBInit);
HAL_FLASH_OB_Launch(); // Triggers reset

HAL_FLASH_OB_Lock();
HAL_FLASH_Lock()

 

My requirement is I need to jump into system bootloader from application whenever there is reprogramming request and I need to reprogram through USB DFU.

The bootloader has no mechanism to spontaneously jump to the application. If you have a watchdog enabled, the chip will reset. Perhaps this is happening. If not, recheck your assumptions here.

The nBOOT1 bit also needs set.

 

If you feel a post has answered your question, please click "Accept as Solution".