cancel
Showing results for 
Search instead for 
Did you mean: 

Same code for CubeIDE and Keil uVision

regjoe
Senior

Hello,

first, this is my first try on Keil uVision & MDK toolchain.

My goal is to compile and run the same source using ST CubeIDE and Keil uVision.

For this a generate code and 2 project files, one for CubeIDE and one for Keil, for a demo project with FreeRTOS and LWIP.

I can sucessfully compile and run the project on CubeIDE. But if I compile the same code on Keil MDK, I get the following errors:

Error: L6218E: Undefined symbol errno (referred from if_api.o).

FreeRTOS.h(71): error:  #5: cannot open source input file "reent.h": No such file or directory

 

I googled around and I found out that I have to tweak some settings in CubeMx which dependent on choosen toolchain. But my intention is to use the same source and CubeMx configuration files for both toolchains. So I choose patching two configuration files.

 

The 1st patch I added to the user code part of FreeRTOSConfig.h:

/* The following flag must be enabled only when using newlib */
#define configUSE_NEWLIB_REENTRANT          1
:
/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
#if defined   (__ARMCC_VERSION)
/* Temporary workaround to avoid compile error due missing reent.h  */
/* override configUSE_NEWLIB_REENTRANT configured by cubemx in freertos.h */
#undef configUSE_NEWLIB_REENTRANT
#endif // ()__ARMCC_VERSION
/* USER CODE END Defines */

For GNU toolchain, IMHO reentrant code shall be generated/used (for NewLib) by default. This requires the file "reent.h", which is included in FreeRTOS.h:

 

/* Required if struct _reent is used. */
#if ( configUSE_NEWLIB_REENTRANT == 1 )
	#include <reent.h>
#endif

 

For MDK toolchain, the file "reent.h" is missing and therefore configUSE_NEWLIB_REENTRANT must be undefined. I choose the compiler directive __ARMCC_VERSION because __GCC__ is present in both toolchains.

 

The 2nd patch is in the user code part of lwipopts.h:

:
/* STM32CubeMX Specific Parameters (not defined in opt.h) ---------------------*/
/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
/*----- WITH_RTOS enabled (Since FREERTOS is set) -----*/
#define WITH_RTOS 1
/* Temporary workaround to avoid conflict on errno defined in STM32CubeIDE and lwip sys_arch.c errno */
#undef LWIP_PROVIDE_ERRNO
:

/* USER CODE BEGIN 1 */
#if defined   (__ARMCC_VERSION)
/* Temporary workaround to avoid compile error due missing reent.h  */
/* override configUSE_NEWLIB_REENTRANT configured by cubemx in freertos.h */
#undef configUSE_NEWLIB_REENTRANT
/* Temporary workaround to declare errno variable as required by FreeRTOS */
/* override LWIP_PROVIDE_ERRNO hard coded above */
#define LWIP_PROVIDE_ERRNO
#elif defined   (__GNUC__)        /* GNU Compiler */
/* Temporary workaround to avoid conflict on errno defined in NewLib and lwip sys_arch.c */
/* override LWIP_PROVIDE_ERRNO hard coded in cc.h */
//#undef LWIP_PROVIDE_ERRNO (already done above)
#endif // ()__ARMCC_VERSION
/* USER CODE END 1 */

For GNU toolchain, variable errno is provided by NewLib. In this case LWIP_PROVIDE_ERRNO must be undefined because it is already "hard" defined in cc.h:

#define LWIP_PROVIDE_ERRNO

CubeMx does this during code generation for CubeIDE setup in the upper part of code, commented as "Temporary workaround...."

For MDK toolchain, the variable errno is not present and must be provided by LWIP via sys_arch.c:

#if defined(LWIP_PROVIDE_ERRNO)
int errno;
#endif

To do so, LWIP_PROVIDE_ERRNO must be defined in the user code section as shown above.

 

Q: Is patching configuration files a suitable method or is there a better way to go? Am I missing something?

Thanks,

Jochen


IDE-Version: STM32F1 Series
µVision V5.38.0.0
Tool Version Numbers:
Toolchain: MDK-ARM Professional Version: 5.38.0.0
Toolchain Path: C:\Keil_v5\ARM\Arm_Compiler_5.06u7\Bin
C Compiler: Armcc.exe V5.06 update 7 (build 960)
Assembler: Armasm.exe V5.06 update 7 (build 960)
Linker/Locator: ArmLink.exe V5.06 update 7 (build 960)
Library Manager: ArmAr.exe V5.06 update 7 (build 960)
Hex Converter: FromElf.exe V5.06 update 7 (build 960)
CPU DLL: SARMCM3.DLL V5.38.0.0
Dialog DLL: TCM.DLL V1.56.4.0
Target DLL: ULP2CM3.DLL V2.215.21.0
Dialog DLL: TCM.DLL V1.56.4.0

 

5 REPLIES 5
jumman_JHINGA
Senior III

While re generating through Cube MX for MDKARM make sure USE_NEWLIB_REENTRANT should be disabled in the advance settings of FreeRTOS.

md1.PNG

 

in the Keil IDE you must select ARM Compiler version 5 ... if it is not installed you must intalled it.

MD2.PNG

 

Hello @jumman_JHINGA 

I already followed these steps in order to generate the project files for uVision. This is how I found out the code diffs.

I know that I can generate and use different lwipopts.h and FreeRTOSConfig.h files for each toolchain but I'd prefer to generate and use the same files for both toolchains. Therefore I use compiler directives in config files.

What about compiler V6, it seems there is no support for it in CubeMx?


@regjoe wrote:

What about compiler V6, it seems there is no support for it in CubeMx?


for V6 we need to do futher settings.

we use (CubeIDE, IAR and MDKARM) for devlopment. i generally take care of those two steps that i mentioned before.. and it works without any issue. 

My colleagues are shifting to MDK V6, so it would be good to know if and when support in CubeMx will be available.

Found this Providing MDK-ARM V6 support - STMicroelectronics Community discussing the required modifications. Is this what you mean when saying "we need to do further settings"?