2021-09-21 01:52 AM
I have a working firmware that reads from a SD card on a STM32L476RG using CubeIDE 1.6.1.
In the past I have downloaded CubeIDE updates and after migrating the project to the new version the firmware still works fine, until I updated cubeIDE from version 1.6.1 to version 1.7. After migrating the project to cubeIDE 1.7 the function f_opendir returns a error number 1 (other FATFS functions like reading or writing to a file or creating a directory works fine). In addition, the MCU hangs up when trying to read the MCU temperature and an additional Analog input that I programmed for reading voltage. Fortunately I did a backup of the working folder so I can go back to the previous version, but I was wondering if this is a bug or if there is something else I'm missing. I compared the main.c builds between two versions and I see only differences in some of the clock configurations (not related to the SD Card) but the rest looks the same. Thanks.
2021-09-23 06:41 AM
Hello @DAbi .1 ,
This issue has been internally raised. I will keep you posted.
Thanks for your contribution.
BeST Regards,
Walid
2021-09-23 06:43 AM
Internal ticket number: 114180 (PS: This is an internal tracking number and is not accessible or usable by customers)
2021-10-18 02:21 AM
Hi,
Were you able to resolve the issue?
The symptoms you describe sounds quite random. My first thought is whether there could be an issue related to thread-safety / re-entrance.
If you have a multi-threaded application, and different threads makes to C library functions like malloc, printf, strtok, ... Then you have to make sure that these C library functions calls are safe to make. malloc as an example contains a critical section. If an IRQ were to fire while you execute malloc AND the ISR also makes a call to malloc, there is a chance that both malloc calls will point to the same memory address. This will likely lead to memory corruption sooner or later --> random crashes...
There is a thread-safe solution provided with CubeIDE/MX which will lock a subset of the C library functions and thereby protect your application against this type of issues. Re-entrant related issues are however still a headache that you need to be careful with. For example parallel calls to strtok and management of reent structs.
The thread-safe solution is described in CubeIDE User Guide. In case of CubeIDE 1.7.0, look at chapter 2.7: Thread-safe wizard for empty projects and CDT™ projects
2021-10-18 04:09 AM
Thank you for your detailed answer. Indeed the problem might be related to what yo mentioned. I was able to solve the issue with the ADC read by following the ADC example in the repository which uses low level methods mixed with HAL methods. I yet haven't tried solving the f_opendir issue since I'm still using the CubeIDE 1.6.1 version. My application does not use RTOS and I do use strok. Unless you close the tread, I'll provide a follow up answer if a find the problem causing the f_opendir issue.
2021-10-18 11:46 PM
Thanks - could be interesting for other community members. Keep us updated!
2021-10-18 11:59 PM
Some further pointers, that may help you troubleshoot and feel more confident about the issue:
Have a look here as a source of inspiration: https://sourceware.org/newlib/libc.html#Reentrancy