cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 CubeMX FatFs + uSD + DMA + RTOS Success

GreenGuy
Senior III
Posted on July 17, 2018 at 02:30

I have finally succeeded in replicating the functionality of the FatFs project for FatFs + uSD + DMA + RTOS in STM32Cube\Repository\STM32Cube_FW_H7_V1.2.0\Projects\STM32H743I_EVAL\Applications\FatFs\FatFs_uSD_DMA_RTOS.

I post this a a summary of the problems found and the fixes that needed to be made to the CubeMX generated project.

First the Build:

CubeMX V.4.26.0:  Project attached

This build also contains LWIP enabled.

Compiled with IAR V8.22.1

Things that needed to be fixed to get it to work:

1) Exclude from build, bsp_driver_sd.c

     Reason: The build for the Eval board uses stm32h743i_eval_sd.c which will duplicate the functions in bsp_driver_sd.c.   The eval board .c file is needed as the CubeMX bsp driver does not contain the needed reference to uSDHandle and code needed for the Mfx chip.  Also the CubeMX generated bsp_driver_sd.c file does not contain the function BSP_SD_DeInit which is a very minor point since the project application does not use it.

2) Fix stm32h7xx_hal_conf.h generated by CubeMX to include the line:

&sharpdefine  USE_SD_TRANSCEIVER           1U               /*!< use uSD Transceiver */

  Reason: The eval board uses the transceiver chip and if the define is missing then the stm32h7xx_hal_sd.c will compile correctly but will fail to run at the mount function.

3) Perform the changes as given in

https://community.st.com/0D50X00009XkZJxSAN

 

  Reason: The file stm32h7xx_hal_rcc_ex.c is not correctly setting the peripheral clocks correctly and the clock default clock assignment of ADC-PPL2 and SDMMC-PLL2 will cause the SDMMC clock to freeze.  Not sure what happens to the ADC clock as I did not look at the ADC.

4) Add the EXTI9_5 IRQ handler to stm32h7xx_it.c generated by CubeMX like:

void EXTI9_5_IRQHandler(void)

{

  SD_DetectIRQHandler();

}

  Reason: If missing, the expander IO chip will not pick up on SD card insertions or removals.

5) Change the argument in the SDMMC1_IRQHandler function in stm32h7xx_it.c when it calls HAL_SD_IRQHandler from &hsd1 to &uSdHandle so the call should look like:

  HAL_SD_IRQHandler(&uSdHandle);

  Reason: If left alone, the open following the mount will fail (if the mount was called with 0, no force) since the fopen will get a structure that has not been initialized to the correct values which will cause the fopen to timeout after 30 seconds.

Note: once the above changes are made you will have to protect against CubeMX re-generations since many of the changes are made to sections that have no USER AREA protection.

I suggest that updates are needed to support the FatFs functionality.  Some recommendations are:

1) Have CubeMX add the appropriate STM32H743I_EVAL files to the BSP folder since the user has already specified that in CubeMX when the eval board was chosen and refrain from placing a bsp_driver_sd.c in the User source area.

2) Fix the USE_TRANSCEIVER omission in CubeMX when generating the stm32h7xx_hal_config.

3) Update the repository for stm32H7 to fix the _hal_rcc_ex.c according to Amel's errata link.

4) Fix CubeMX to add the the IRQ handler for the Mfx chip.

4) Fix the argument in the   HAL_SD_IRQHandler(&uSdHandle); call in stm32h7xx_it.c to match what the stm32h743i_eval BSP files are expecting.

null
0 REPLIES 0