Skip to main content
NMan.11
Associate II
February 1, 2020
Question

FATFS + DMA + FreeRTOS on STM32F446 Fixed

  • February 1, 2020
  • 5 replies
  • 2552 views

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.

This topic has been closed for replies.

5 replies

Khouloud ZEMMELI
ST Employee
February 6, 2020

​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

Piranha
Principal III
February 7, 2020

"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.

NMan.11
NMan.11Author
Associate II
February 7, 2020

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.

NMan.11
NMan.11Author
Associate II
February 7, 2020

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.

Khouloud ZEMMELI
ST Employee
February 10, 2020

​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