2017-07-17 12:24 AM
My Environment:
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
void SetBoot0Pin(void)
{__HAL_RCC_GPIOB_CLK_ENABLE();GPIO_InitTypeDef gp;gp.Pin = GPIO_PIN_8; //BOOT0 pingp.Mode = GPIO_MODE_OUTPUT_PP;gp.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOB, &gp);HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, (GPIO_PinState) 1);}//File : startup_stm32f042x6.s
; Reset handler routine
Reset_Handler PROCEXPORT Reset_Handler [WEAK]LDR R0, =0x200017F0LDR R1, =0xDEADDEADLDR R2, [R0, &sharp0]STR R0, [R0, &sharp0] ; InvalidateCMP R2, R1BEQ Reboot_LoaderIMPORT __mainIMPORT SystemInitLDR R0, =SystemInitBLX R0LDR R0, =__mainBX R0ENDPReboot_Loader PROC
EXPORT Reboot_LoaderIMPORT SetBoot0PinLDR R0, =SetBoot0PinBLX R0LDR R0, =0x40021018 ; RCC_APB2ENR (+0x18)LDR R1, =0x00000001 ; ENABLE SYSCFG CLOCKSTR R1, [R0, &sharp0]LDR R0, =0x40010000 ; SYSCFG_CFGR1 (+0x00)LDR R1, =0x00000001 ; MAP ROM AT ZEROSTR R1, [R0, &sharp0]LDR R0, =0x1FFFC400 ; ROM BASE (STM32F04x)LDR R1, [R0, &sharp0] ; SP @ +0MOV SP, R1LDR R0, [R0, &sharp4] ; PC @ +4BX R0ENDP ;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.
/external-link.jspa?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F28288453%2Fhow-do-you-jump-to-the-bootloader-dfu-mode-in-software-on-the-stm32-f072
The test app is not receiving any characters back from the device. Someone please guide me on what could be the problem?
#stm32f042