cancel
Showing results for 
Search instead for 
Did you mean: 

How can I update the software on STM32F7 ?

MMerc.1
Senior

Hi,

I want to update the software of the STM32F746BGT via a USB stick or Ethernet connexion.

Firstly, how can I use the USB stick to update the software inside the MCU ?

How can I use the Internet connexion (via UART : Lantronix XPORT) to update the software inside the MCU ?

Best regards

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

Partition your code into a bootloader and the real application. The bootloader normally just starts the real app. When some condition is set to true, the bootloader instead communicates with the peripheral(s), downloads + flashes a new version of the app into the flash and finally reboots.

View solution in original post

11 REPLIES 11
KnarfB
Principal III

Partition your code into a bootloader and the real application. The bootloader normally just starts the real app. When some condition is set to true, the bootloader instead communicates with the peripheral(s), downloads + flashes a new version of the app into the flash and finally reboots.

Hi,

Do you think the example of "STM32Cube_FW_F7_V1.16.0\Projects\STM32756G_EVAL\Applications\USB_Host\FWupgrade_Standalone" works ?

MMerc.1
Senior

Hi,

I try to use the example of "STM32Cube_FW_F7_V1.16.0\Projects\STM32756G_EVAL\Applications\USB_Host\FWupgrade_Standalone" but when I add "#include <usbh_def.h>" in order to use the structure for "extern USBH_HandleTypeDef hUsbHostFS" in main.h I have the following error :

make -j12 all 
arm-none-eabi-gcc "../USB_HOST/Target/usbh_conf.c" -mcpu=cortex-m7 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32F746xx -DDEBUG -c -I../TouchGFX/gui/include -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/STM32F7xx_HAL_Driver/Inc/Legacy -I../USB_HOST/App -I../TouchGFX/generated/fonts/include -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FreeRTOS/Source/include -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FatFs/src -I../TouchGFX/generated/texts/include -I../TouchGFX/generated/images/include -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1 -I"C:/Users/ozone/STM32CubeIDE/workspace_1.3.0/OZONEX_IHM_208/Components/ft5336" -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/STM32F7xx_HAL_Driver/Inc/Legacy -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc -I../Core/Inc -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/CMSIS/Include -I../TouchGFX/generated/gui_generated/include -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/STM32F7xx_HAL_Driver/Inc -I../FATFS/App -I"C:/Users/ozone/STM32CubeIDE/workspace_1.3.0/OZONEX_IHM_208/Components/Common" -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/CMSIS/Device/ST/STM32F7xx/Include -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/CMSIS/Device/ST/STM32F7xx/Include -I"C:/Users/ozone/STM32CubeIDE/workspace_1.3.0/OZONEX_IHM_208/STM32746G-Discovery" -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FatFs/src -IC:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc -I../Middlewares/ST/touchgfx/framework/include -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1 -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FreeRTOS/Source/include -I../TouchGFX/target/generated -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/STM32F7xx_HAL_Driver/Inc -I../FATFS/Target -I../TouchGFX/App -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../USB_HOST/Target -I../TouchGFX/target -IC:/Users/Stef/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"USB_HOST/Target/usbh_conf.d" -MT"USB_HOST/Target/usbh_conf.o" --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -o "USB_HOST/Target/usbh_conf.o"
In file included from ../Core/Inc/main.h:38:0,
                 from ../USB_HOST/Target/usbh_conf.h:33,
                 from C:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_core.h:28,
                 from ../USB_HOST/Target/usbh_conf.c:23:
C:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:280:44: error: 'USBH_MAX_NUM_ENDPOINTS' undeclared here (not in a function); did you mean 'USB_DESC_ENDPOINT'?
   USBH_EpDescTypeDef               Ep_Desc[USBH_MAX_NUM_ENDPOINTS];
                                            ^~~~~~~~~~~~~~~~~~~~~~
                                            USB_DESC_ENDPOINT
C:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:295:45: error: 'USBH_MAX_NUM_INTERFACES' undeclared here (not in a function); did you mean 'USBH_MAX_NUM_ENDPOINTS'?
   USBH_InterfaceDescTypeDef        Itf_Desc[USBH_MAX_NUM_INTERFACES];
                                             ^~~~~~~~~~~~~~~~~~~~~~~
                                             USBH_MAX_NUM_ENDPOINTS
C:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:422:49: error: 'USBH_MAX_SIZE_CONFIGURATION' undeclared here (not in a function); did you mean 'USB_REQ_SET_CONFIGURATION'?
   uint8_t                           CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION];
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                 USB_REQ_SET_CONFIGURATION
C:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:423:42: error: 'USBH_MAX_DATA_BUFFER' undeclared here (not in a function); did you mean 'USBH_MAX_PIPES_NBR'?
   uint8_t                           Data[USBH_MAX_DATA_BUFFER];
                                          ^~~~~~~~~~~~~~~~~~~~
                                          USBH_MAX_PIPES_NBR
C:/Users/ozone/STM32Cube/Repository/STM32Cube_FW_F7_V1.16.0/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/usbh_def.h:460:32: error: 'USBH_MAX_NUM_SUPPORTED_CLASS' undeclared here (not in a function); did you mean 'USBH_NOT_SUPPORTED'?
   USBH_ClassTypeDef    *pClass[USBH_MAX_NUM_SUPPORTED_CLASS];
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                USBH_NOT_SUPPORTED
make: *** [USB_HOST/Target/subdir.mk:18: USB_HOST/Target/usbh_conf.o] Error 1
"make -j12 all" terminated with exit code 2. Build might be incomplete.
 
09:16:05 Build Failed. 6 errors, 0 warnings. (took 13s.12ms)

Do you have any idea about this error ?

Best regards

Frak.1
Associate II

For me it is too less information. Can you share your project or this library? How this variables are declared? For example "USBH_MAX_NUM_ENDPOINTS". Are they as #define? Looks like the compiler can't find their declarations.

Hi,

I fixed the error. But now, I am trying to figure out how it works.

I call the function "HCD_Port_IRQHandler" and I have to call the function "HAL_HCD_PortEnabled_Callback". Unfortunately, the variable "hprt0" does not have a "USB_OTG_HPRT_PENA" bit... So function "HAL_HCD_PortEnabled_Callback" is never called.

Do you know why ?

Edit 1 :

I fixed the error. Now in case "HOST_CHECK_CLASS" in the function "USBH_Process", I don't have "USBH_OK" when I use "phost->pActiveClass->Init(phost)".

Do you know why ?

Edit 2 :

The problem is in the function "static USBH_StatusTypeDef USBH_MSC_InterfaceInit(USBH_HandleTypeDef *phost)" :

phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc(sizeof(MSC_HandleTypeDef));
  MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;

MSC_Handle return NULL value.

From this little part of the code I conclude that USBH_malloc can't allocate memory. Malloc returns NULL when it can't allocate enough space.

Hi,

How can I solve this problem ?

How can I know the memory needed for this malloc ?

How can I know the remaining memory when the program is running?

Edit :

Here is the memory used :

0693W000006EImtQAG.pngHow to manage the variables to move them on the QSPI ?

It's not the problem of the free memory. There are few problems that can occur. For example your stack can be not enough. Malloc allocate memory on the stack. You can check the stack before allocation.

Check also https://community.st.com/s/question/0D53W0000056nEJ/stm32f7-usbhmalloc-fails-despite-8-kb-heap

How you asked: "how can I know the memory needed to malloc?"

You pass size of the region to allocate to the malloc function. Assign it to variable and debug..

Thanks a lot, after replacing stack_ptr with 0x2003c000, everything works fine.

I have another question... As you know, I am using the example of "STM32Cube_FW_F7_V1.16.0\Projects\STM32756G_EVAL\Applications\USB_Host\FWupgrade_Standalone" for my custom board based on STM32F746BGTx. In the "FW_UPGRADE_Process" function, I cannot register the file system ("FATFS_LinkDriver" returns 0).

Do you know why ?

Edit :

It works fine, the USB stick is detected and mounted but... the file to update the system is bigger than the size of the flash :

  • File size : 31.1 Mo (.hex)
  • Flash size : 1 015 804 bytes
/* Define the flash memory start address */
#define USER_FLASH_STARTADDRESS    ((uint32_t)0x08000000)
 
/* Define the address from where user application will be loaded.
Note: the 1st and the second sectors are reserved for the Firmware upgrade code */
#define APPLICATION_ADDRESS          (uint32_t)0x08008000
 
/* Last Page Address */
#define USER_FLASH_LAST_PAGE_ADDRESS  (0x080FFFFF - 4)
 
/* Define the user application size */
#define USER_FLASH_SIZE   (USER_FLASH_LAST_PAGE_ADDRESS - APPLICATION_ADDRESS + 1)
 
/* Base address of the Flash sectors */
#define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base @ of Sector 0, 32 Kbytes */
#define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08008000) /* Base @ of Sector 1, 32 Kbytes */
#define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08010000) /* Base @ of Sector 2, 32 Kbytes */
#define ADDR_FLASH_SECTOR_3     ((uint32_t)0x08018000) /* Base @ of Sector 3, 32 Kbytes */
#define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08020000) /* Base @ of Sector 4, 128 Kbytes */
#define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08040000) /* Base @ of Sector 5, 256 Kbytes */
#define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08080000) /* Base @ of Sector 6, 256 Kbytes */
#define ADDR_FLASH_SECTOR_7     ((uint32_t)0x080C0000) /* Base @ of Sector 7, 256 Kbytes */

 It contains the QSPI but I don't need to update it. How can I "delete" it ?

When I use STM32CubeProgrammer, it downloads internal memory (Flash) and after external memory (QSPI).

How can I do the same procedure?