AnsweredAssumed Answered

USB DFU detection works in STM32F407 Discovery but dosenot work with STM32F439xx after calling from user application

Question asked by TRIVEDI.RUTVIJ on Jan 28, 2016
Latest reply on Jun 14, 2018 by waclawek.jan
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 for STM32F439XX 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 !






Outcomes