Cannot get STM32F446 into USB DFU mode to upload new firmware
I am trying to get my STM32F446RE (using STM32CubeIde) into USB DFU mode via firmware rather than using the RST and BOOT0 inputs which are going to switches on the board. I know this is doable but for some reason it is not working for me
whenever I go into JumpToDFUBootloader(void); the windows host computer does nothing looking at windows device manager I should see "STM32 BOOTLOADER" under USB Devices but I do not see this which means the correct process
to go into DFU mode is not happening, I notice that if I jump the BOOT0 pin high and execute JumpToDFUBootloader() it does go into USB DFU mode and I can see the "STM32 BOOTLOADER" but unfortunately I DO NOT want to rely
on my BOOT0 or RST input pins I just want to go into DFU mode upload new firmware and repower the system to re-initialize into normal operating mode afte a firmware update.
Any suggestions or help with this would be greatly apprciated
My code is below:
/*
///////These below are before and when entering my main() function /////////
#define BOOTLOADER_ADDR 0x1FFF0000U
extern USBD_HandleTypeDef hUsbDeviceFS;
BooterFlag = Read_ext_uint8_eeprom(BOOTFLAG_LOC); /// I am reading a location on I2C EEPROM to see if my bootload flag is active
HAL_Delay(50);
printf("\nBooterFlag = %u\n",BooterFlag); // for debug
if((BooterFlag != 0) && (BooterFlag != 1))
{ BooterFlag = 0;
Write_ext_8bit_eeprom(BOOTFLAG_LOC,BooterFlag);
}
else if(BooterFlag == 1)
{
printf("Jumping to Boot-loader\n\r");
Write_ext_8bit_eeprom(BOOTFLAG_LOC,0);
HAL_Delay(100);
JumpToDFUBootloader();
}
*/
////////////// Here is my function to get me to DFU Boot-Loader //////////
void JumpToDFUBootloader(void) {
void (*SysMemBootJump)(void);
// Disable interrupts
__disable_irq();
// Stop USB device
USBD_Stop(&hUsbDeviceFS);
USBD_DeInit(&hUsbDeviceFS);
// Disable USB interrupt
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
// Reset USB OTG FS
__HAL_RCC_USB_OTG_FS_FORCE_RESET();
HAL_Delay(10);
__HAL_RCC_USB_OTG_FS_RELEASE_RESET();
// Enable USB OTG FS clock for system bootloader
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
// De-init HAL and peripherals
HAL_RCC_DeInit();
HAL_DeInit();
// Disable SysTick
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// Remap system memory
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
// Set MSP and jump to system memory
__set_MSP(*((volatile uint32_t *) BOOTLOADER_ADDR));
SysMemBootJump = (void (*)(void)) (*((volatile uint32_t *)(BOOTLOADER_ADDR + 4)));
// Jump
SysMemBootJump();
// Should never reach here
while (1);
}
