2024-04-08 12:15 PM
Is the STM32CubeIDE defaults 64 bits in unix time? if not, how/where to put gcc command line option in STM32CubeIDE "gcc -D_TIME_BITS=64". Supposedly, this will redirect unix time to be 64 bit instead of traditional 32 bit that will overflow in year 2038. TIA
Solved! Go to Solution.
2024-04-26 11:51 AM - edited 2024-04-26 11:58 AM
You can test number of bits of time_t in the standard C library with sizeof(time_t).
The underlying type for time_t that has been used for compilation of the newlib (the C runtime library of the ARM toolchain, bundled with CubeIDE) is defined in newlib.h
#include <newlib-nano/newlib.h>
#ifndef _WANT_USE_LONG_TIME_T
// time_t likely is LONGLONG = 64 bit. this is default.
#else
// time_t likely is LONG (32 bit)
#endif
Usually located in [STM32CubeIDE]/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.xxxxxxxxxx/tools/arm-none-eabi/include/newlib-nano/newlib.h
You cannot redefine this size in your project with any macro or C option, as the library has already been built and available for you in object form.
If you want different number of bits for time, you can define any typedef and your own time functions.
2024-04-26 10:00 AM
Hello @David_
Can you give more details about your question. I'm not understanding this very well.
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-04-26 11:22 AM
Sorry my question not clear.
I believe STM32Cube use (unix for ARM) gcc compiler and make file.
If one execute gcc compiler on (unix) command prompt CLI, after gcc, there is a string of 'switches' or 'options' to tell the compiler to do something, like where is source file, where to save the compiled file, c optimization level, etc.
I was told the "-D_TIME_BITS=64" switch direct compiler to use 64 bits to hold the unix epoch time instead of the original design that use 32 bits and will overflow at year 2038.
I am seeking advises on where to put that "-D_TIME_BITS=64" in many 'configuration' tab in STM32Cube so that it will pass onto gcc compiler during the IDE/Make process.
Many thanks
2024-04-26 11:51 AM - edited 2024-04-26 11:58 AM
You can test number of bits of time_t in the standard C library with sizeof(time_t).
The underlying type for time_t that has been used for compilation of the newlib (the C runtime library of the ARM toolchain, bundled with CubeIDE) is defined in newlib.h
#include <newlib-nano/newlib.h>
#ifndef _WANT_USE_LONG_TIME_T
// time_t likely is LONGLONG = 64 bit. this is default.
#else
// time_t likely is LONG (32 bit)
#endif
Usually located in [STM32CubeIDE]/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.xxxxxxxxxx/tools/arm-none-eabi/include/newlib-nano/newlib.h
You cannot redefine this size in your project with any macro or C option, as the library has already been built and available for you in object form.
If you want different number of bits for time, you can define any typedef and your own time functions.