cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401 USB memory stick bootloader

PRobe
Associate II

Hi,

I need to write a bootloader which will load the new program from a USB memory stick.

Unfortunately I cannot use the ROM based DFU bootloader.

The bootloader would need to be held in FLASH and protected against update. Easy enough.

I believe that the CubeMx USB library uses interrupts however so I will need two vector table, know where the application vector table is and swap to it.

VTOR looks the ticket but am looking for a 'quick start' example illustration linker script changes.

I am using TrueStudio so that or a convertible project would be ideal.

Thanks

6 REPLIES 6

There should be assorted IAP (In Application Programming) examples under the F4 HAL trees.

Definitely a USB MSC Host IAP example for the STM32F4-DISCO board which would likely port.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
PRobe
Associate II

Thanks. I found AN3990 but where is the software? Not in STM32Cube_FW_F4_V1.23.0...

PRobe
Associate II

Found: https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-library-expansion/stsw-stm32068.license=1548347548746.product=STSW-STM32068.version=1.1.0.html

This application example is prebuilt however. Section 2.3) says that I can relocate vectorr table using VECT_TAB_OFFSET in system_stm32f4xx.c (I have system_stm32f401xc.s). Neither do I have NVIC_SetVectorTable().

So I still need help with the application's start address & vector table voodoo.

The original one for the F4-DISCO was in the SPL/DSP

STM32F4-Discovery_FW_V1.1.0\Project\FW_upgrade

STM32F429I-Discovery_FW_V1.0.1\Projects\FW_upgrade

In HAL trees,

STM32Cube_FW_F4_V1.23.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDisk\readme.txt

STM32Cube_FW_F4_V1.23.0\Projects\STM32F429I-Discovery\Applications\USB_Host\FWupgrade_Standalone\readme.txt

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

For GNU/GCC

>>Relocate the vector table (define the VECT_TAB_SRAM in system_stm32f1xx.c)

The more efficient method is to let the Linker do the work and use the symbol for the vector table as built

extern void *g_pfnVectors;

SCB->VTOR = &g_pfnVectors;

void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
  #endif
  /* Reset the RCC clock configuration to the default reset state ------------*/
  /* Set HSION bit */
  RCC->CR |= (uint32_t)0x00000001;
 
  /* Reset CFGR register */
  RCC->CFGR = 0x00000000;
 
  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= (uint32_t)0xFEF6FFFF;
 
  /* Reset PLLCFGR register */
  RCC->PLLCFGR = 0x24003010;
 
  /* Reset HSEBYP bit */
  RCC->CR &= (uint32_t)0xFFFBFFFF;
 
  /* Disable all interrupts */
  RCC->CIR = 0x00000000;
 
  /* Configure the Vector Table location add offset address -------FIX THIS-----------*/
#ifdef VECT_TAB_SRAM
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..