STM32F042 Nucleo-32 dev board which has STM32F042K6T6 MCU of 32pin QFP
KEIL ARM MDK v5
Host Windows 10 OS
The BOOT0 pin PB8 is not available on the CN3 or CN4 connector.
I've used the below code and it is handing over the control to system memory bootloader successfully. However the bootloader code hands over the control to the user flash application within few mSecs. According to the datasheet of MCU, the bootloader code looks for the BOOT0 pin if the BOOTSEL option bit is not explicitly set to don't check for BOOT0 pin. This presents two solutions. First one is programming the BOOTSEL to skip checking the BOOT0 pin in the bootloader start routine.This will allow the BOOT0 pin to be used as normal GPIO pin for any other operations. The other one is setting the BOOT0 pin through code using the internal pullup and to HIGH. I've used the second solution in the below posted code
So then I've created a new function that explicitly sets the BOOT0 pin to HIGH before making the jump to the system memory. This change fixed the loop of moving from bootloader to user flash application. The MCU stays in bootloader code.
//File : main.c
gp.Pin = GPIO_PIN_8; //BOOT0 pin
gp.Mode = GPIO_MODE_OUTPUT_PP;
gp.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, (GPIO_PinState) 1);
//File : startup_stm32f042x6.s
; Reset handler routine
EXPORT Reset_Handler [WEAK]
LDR R0, =0x200017F0
LDR R1, =0xDEADDEAD
LDR R2, [R0, #0]
STR R0, [R0, #0] ; Invalidate
CMP R2, R1
LDR R0, =SystemInit
LDR R0, =__main
LDR R0, =SetBoot0Pin
LDR R0, =0x40021018 ; RCC_APB2ENR (+0x18)
LDR R1, =0x00000001 ; ENABLE SYSCFG CLOCK
STR R1, [R0, #0]
LDR R0, =0x40010000 ; SYSCFG_CFGR1 (+0x00)
LDR R1, =0x00000001 ; MAP ROM AT ZERO
STR R1, [R0, #0]
LDR R0, =0x1FFFC400 ; ROM BASE (STM32F04x)
LDR R1, [R0, #0] ; SP @ +0
MOV SP, R1
LDR R0, [R0, #4] ; PC @ +4
Snapshot when the code is jumped to system memory bootloader. Notice the jump to the code location 0x1FFFCB45 as per the memory window showing the value at the reset vector address.
Allowed the code to run for some time. Notice the change in PC register shown in the registers window
Hold on. The story is not ended.Next is to ensure that the device is available/detected as USB DFU device in device manager. This is where my setup is not working. The device is not re-enumerated and no entries of USB DFU device in device manager and so the Dfuse demo tool is not listing the device. what could be the problem?
I've used a small break-out-board to takeout usb signals to the host machine. As I could not see usb enumeration happening, I've also used FTDI usb to serial cable and connected it to the nucleo board. See below for connection details.
Also I've tried using the test app that was posted in other thread to find the device is in DFU mode. That application is not receiving any data that confirms that the USB DFU is not running. Notice that it is for STM32F072 but I hope that this should work for STM32F042 as well.
How do you jump to the bootloader (DFU mode) in software on the STM32 F072? - Stack Overflow
The test app is not receiving any characters back from the device. Someone please guide me on what could be the problem?