2016-01-28 02:27 AM
Hello all,
I am working to call the ROM residing USB DFU bootloader in STM32F439XX. I have made a sample code and tested into the STM32f407 - Discovery KIT and it works fine and sucfully jumps to the location of ROM and finds the USB DFU device into Device manager and i also can upload binaries in this configuration, but same thing dos not work forSTM32F439XX MCU. However in IAR debugging it can be seen that it enters into the ROM bootloader but device manager dose not detects any USB Device. my sample code is as per below,#include ''stm32f4xx.h''
#include ''stm32f4_discovery.h''
/*================================Macro definitions=================*/
#define BOOTLOADER_ADDRESS 0x1fff0004
#define __SP 0x20001000
/*Below stack pointer is taken after debugging into IAR assembly mode and found 0x1fff0004
location to contain valid stack pointer which has been taken here,but even after commenting below line it dose not work */
//#define __SP 0x20002d40
/*================================Function declarations =================*/
typedef void (*pFunction)(void);
pFunction Jump_To_Bootloader;
__IO uint32_t JumpAddress ;
void Delay(__IO uint32_t nCount) ;
void BootLoaderinit();
void Hal_init();
void Hal_Deinit();
/*================================MAIN=================*/
int main()
{
//Enable LEDs and Buttons
Hal_init();
while (1)
{
//Wait for button to be pressed to proceed into bootloader mode
if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET)
{
//LEDs to indicate bootloader mode
STM_EVAL_LEDOff(LED4);
Delay(0x7FFFFF);
STM_EVAL_LEDOn(LED4);
Delay(0x7FFFFF);
BootLoaderinit();
}
// If button is not pressed do continue work in user application
STM_EVAL_LEDOn(LED3);
Delay(0x7FFFFF);
STM_EVAL_LEDOff(LED3);
Delay(0x7FFFFF);
}
// return 0;
}
/*================================S/W delay =================*/
void Delay(__IO uint32_t nCount)
{
while(nCount--)
{
}
}
/*================================Jump to bootloader=================*/
void BootLoaderinit()
{
// deinit LEDs and buttons
Hal_Deinit();
/**
* @brief Resets the RCC clock configuration to the default reset state.
* @note The default reset state of the clock configuration is given below:
* - HSI ON and used as system clock source
* - HSE, PLL and PLLI2S OFF
* - AHB, APB1 and APB2 prescaler set to 1.
* - CSS, MCO1 and MCO2 OFF
* - All interrupts disabled
* @note This function doesn't modify the configuration of the
* - Peripheral clocks
* - LSI, LSE and RTC clocks
* @param None
* @retval None
*/
RCC_DeInit();
//Remap ROM (System memory) to ZERO
SYSCFG_MemoryRemapConfig(((uint8_t)0x01));
//Reset systick counts
SysTick->CTRL =0;
SysTick->LOAD=0;
SysTick->VAL=0;
/* Jump to user application */
JumpAddress = *(__IO uint32_t*)(BOOTLOADER_ADDRESS);
Jump_To_Bootloader = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) __SP);
Jump_To_Bootloader();
while(1)
{
// should not land up here
}
}
void Hal_init()
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
}
void Hal_Deinit()
{
STM_EVAL_LEDDeInit(LED3);
STM_EVAL_LEDDeInit(LED4);
STM_EVAL_PBDeInit(BUTTON_USER, BUTTON_MODE_GPIO);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,DISABLE);
}
My clock configurations are as per below, SystemCoreClock = 168000000; #define PLL_M 24 #define PLL_N 336 #define PLL_P 2 #define PLL_Q 7 // #define HSE_VALUE ((uint32_t)25000000) //for 25MHz Now i don't understand what happening here , as its works fine in Discovery board and not in my custom(STM3F439xx) board, To make sure its not hardware issue i tried to pull up the Boot0 pin into my STM3F439xx but then it detects USB in DFU mode. So what is there which being done by Boot0 pin and is not there in my software code.? Requested to guide me here. Any help in this topic would be greatly appreciated. Thank you ! #dfu #stm32 #usb
Note: this post was migrated and contained many threaded conversations, some content may be missing.
2018-06-10 03:42 AM
Sorry, read somewhere that clock disable is reset and did not look further.
Still the same end result, though.
&sharpdefine __HAL_RCC_USB_OTG_FS_FORCE_RESET ( ) (RCC->AHB2RSTR |= (RCC_AHB2RSTR_OTGFSRST))2018-06-10 03:44 AM
I believe you need also to release that reset (i.e. set then clear that bit).
JW
2018-06-10 03:50 AM
:)
I am ready to throw the towel. Given that this is just a convenience function....
This is the latest incarnation of the code related to shutdown. Same USB error.
USBD_Stop(&hUsbDeviceFS);
HAL_Delay(5000);USBD_DeInit(&hUsbDeviceFS);__HAL_RCC_USB_OTG_FS_FORCE_RESET();HAL_Delay(5000);__HAL_RCC_USB_OTG_FS_RELEASE_RESET();HAL_RCC_DeInit();HAL_DeInit();2018-06-10 04:10 AM
I am ready to throw the towel.
What? This is not even round 3! (That would be serious debugging of the bootloader).
AFAIK these resources are used by USB:
- clock
- DP/DM pins and -if used - VBUS pin, as set in GPIO
- module itself
Please correct me if I forgot anything.
The bootloader expects them to be in default state. The last one should be resolved by the reset. The pins should be resolved by resetting the GPIO modules (or by manually putting all of their registers into reset state). The first one may be most tricky - you should perhaps make sure before jumping to bootloader that the RCC registers are in their reset state, and if not, make corrective action.
The bootloader may perhaps be also fooled by something else to fall into some of the non-USB states (e.g. USART); that depends on the particularities of your circuit.
JW
2018-06-14 11:48 AM
One more thing: is DM/DP of the 'F429 on your board connected directly to the USB connector, or is there something in between?
JW