Hello ST,
I have fixed this with support from IAR. dlib_lock_glue.c from STM32CubeMX is at fault.
ST: please can you update the dlib locking code as generated in CubeMX?
To fix this issue requires the following steps,
- Linker -> Extra Options -> --manual_dynamic_initialization
- Refactor "__attribute__ ((constructor)) void __dlib_thread_safety_init()" to "void __dlib_thread_safety_init()"
- Early in main(), beofre any C++ code is called,
- Declared “extern void __dlib_thread_safety_init();”
- Called the following at the beginning on main,
- __dlib_thread_safety_init();
- __iar_cstart_tls_init(NULL);
- __iar_dynamic_initialization();
Also, the mutex lock/unlock functions in dlib_lock_glue are wrong, the ones generated for the STM32CubeIDE are correct, but the IAR ones are out-of-date.
References to "static_system_list_lock" and "static_file_list_lock" in the following functions (and only the following functions) should be deleted/commented out,
- __iar_system_Mtxlock
- __iar_system_Mtxunlock
- __iar_file_Mtxlock
- __iar_file_Mtxunlock
I hope this helps someone facingteh same issues we have been facing.
H.