cancel
Showing results for 
Search instead for 
Did you mean: 

USB DFU enumeration is not happening in STM32F042 nucleo-32 board

Posted on July 17, 2017 at 09:24

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 pin

gp.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 PROC

EXPORT Reset_Handler [WEAK]

LDR R0, =0x200017F0

LDR R1, =0xDEADDEAD

LDR R2, [R0, &sharp0]

STR R0, [R0, &sharp0] ; Invalidate

CMP R2, R1

BEQ Reboot_Loader

IMPORT __main

IMPORT SystemInit

LDR R0, =SystemInit

BLX R0

LDR R0, =__main

BX R0

ENDP

Reboot_Loader PROC

EXPORT Reboot_Loader

IMPORT SetBoot0Pin

LDR R0, =SetBoot0Pin

BLX R0

LDR R0, =0x40021018 ; RCC_APB2ENR (+0x18)

LDR R1, =0x00000001 ; ENABLE SYSCFG CLOCK

STR R1, [R0, &sharp0]

LDR R0, =0x40010000 ; SYSCFG_CFGR1 (+0x00)

LDR R1, =0x00000001 ; MAP ROM AT ZERO

STR R1, [R0, &sharp0]

LDR R0, =0x1FFFC400 ; ROM BASE (STM32F04x)

LDR R1, [R0, &sharp0] ; SP @ +0

MOV SP, R1

LDR R0, [R0, &sharp4] ; PC @ +4

BX R0

ENDP ;

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.

0690X00000607WdQAI.png

Allowed the code to run for some time. Notice the change in PC register shown in the registers window

0690X00000607bcQAA.png

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.

0690X00000603u8QAA.jpg

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?

0690X00000603teQAA.jpg

#stm32f042
0 REPLIES 0