cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS + DMA + FreeRTOS on STM32F446 Fixed

NMan.11
Associate II

Hi guys i was trying to get the FATFS + DMA + FreeRTOS on STM32F446 working and you have a small error in your code.

In order to get the SD Card to work, the HAL_SD_TxCpltCallback and HAL_SD_RxCpltCallback functions in bsp_driver_sd.c should not have the __weak macro on them. The linker linked with the default callback functions in the stm32F4xx_hal_sd.c file. They are just placeholder functions and dont do anything.

Once i removed the __weak from the functions in the bsp_driver_sd.c, it all worked fine.

Could you please update it in a next revision of CubeMX and CubeIDE.

5 REPLIES 5
Khouloud ZEMMELI
ST Employee

​Hello @NMan.1​ , Thanks for your feedback

Well, to allow users to replace such generated code by the right ones (if, for instance, he copies files from the FW pack in the project generated by Mx), it would be better to generate functions in the bsp_*.c files as "weak"  and it could then be overwritten by user code.

Best Regards,

Khouloud

NMan.11
Associate II

Hi @Khouloud ZEMMELI​ , Thank you for the answer.

Yes that is right, but for callbacks from interrupts that already have a "weak" equivalent somewhere else in the code, it can cause problems.

For now i will just removed the weak attribute from those two functions and it works like a charm.

"If multiple weak definitions are available, the linker generates an error message, unless the linker option --muldefweak is used. In this case, the linker chooses one for use by all calls."

http://www.keil.com/support/man/docs/armcc/armcc_chr1359124970859.htm

And the developer can't control which one...

From a HAL's perspective the BSP is the "user" code. If you want the BSP functions to also be overridable, you must do it with preprocessor definitions.

I'm using it with the default linker flags that STM32CubeIDE V1.2.0 generates the project with. The flag is not present there, but there is no error. It links properly. I had to debug the interrupt handling in order to find that it was linking with the empty function.

​Hi @NMan.1​ ,

Yes you're right , HAL_SD_AbortCallback , HAL_SD_TxCpltCallback  and HAL_SD_RxCpltCallback functions are now generated as weak, while they are already "weak" in stm32f4xx_hal_sd.c (used in the same project generated by CubeMx), So  the __weak will be removed in the next release.

Thanks for your feedback,

Best Regards,

Khouloud