Hello all,
I'm using S32DS for my device S32K144.
I would like to access the project name from the current code.
Kindly suggest if any macros available or pragmas for accessing the filename.
Thanks in adavance,
Raju
已解决! 转到解答。
Hi
sounds really like a bug to me in the S32DS, and Jiri already created a ticket for it (thanks!).
I have found a workaround in the S32DS: just do it like this:
I hope this helps,
Erich
I'm using a very simply (and effective, imho) way: using Eclipse CDT variables which get passed to the compiler/application using -D (defines).
See How to Use Eclipse CDT Environment Variables in C/C++ Code | MCU on Eclipse
That way any CDT or environment variable or information can be passed to the application and used there, including the name of the project or other things like if it is a 'release' or 'build' targer, or informatinon about the host operating system.
It is possible of course to use external script extra make files, but the above approach has worked for me for a very long time.
I hope this helps,
Erich
PS: thanks to @BJ RAJENDRANATH for that question here which finally triggered me to write about the approach I'm using :-)
Hi Enrich,
Thanks for your response.
I moment I added the line __PROJECTNAME__=\"${ProjName}\" in preprocessor symbols I'm getting the errors as sjown in the below picture. Without that line I dont see any errors.
Do you think, there will be any additional settings to be made along with this. Kindly suggest
Raju
Hi Raju,
I doubt that the error messages are related to the -D addition. You must have changed/broken something else?
Please check (or post) the command line passed to the compiler and linker in the console view.
Erich
Hi Enrich,
The moment I erase the line __PROJECTNAME__=\"${ProjName}\" in -D, the build is successfull.
Also, I created a new project and checked. The result is same. Below shows the addition of CDT variables
Below is the console view during errors.
09:50:02 **** Incremental Build of configuration Debug_FLASH for project hello_world_s32k146 ****
make -j8 all
Building file: ../Generated_Code/Cpu.c
Building file: ../Generated_Code/clockMan1.c
Building file: ../Generated_Code/pin_mux.c
Executing target #1 ../Generated_Code/Cpu.c
Executing target #2 ../Generated_Code/clockMan1.c
Executing target #3 ../Generated_Code/pin_mux.c
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@Generated_Code/Cpu.args" -MMD -MP -MF"Generated_Code/Cpu.d" -MT"Generated_Code/Cpu.o" -o "Generated_Code/Cpu.o" "../Generated_Code/Cpu.c"
Invoking: Standard S32DS C Compiler
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@Generated_Code/pin_mux.args" -MMD -MP -MF"Generated_Code/pin_mux.d" -MT"Generated_Code/pin_mux.o" -o "Generated_Code/pin_mux.o" "../Generated_Code/pin_mux.c"
arm-none-eabi-gcc "@Generated_Code/clockMan1.args" -MMD -MP -MF"Generated_Code/clockMan1.d" -MT"Generated_Code/clockMan1.o" -o "Generated_Code/clockMan1.o" "../Generated_Code/clockMan1.c"
Building file: C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.c
Building file: C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/S32K146/startup/system_S32K146.c
Building file: C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c
Building file: C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/clock_manager.c
Building file: C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/interrupt/interrupt_manager.c
Executing target #7 C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.c
Executing target #5 C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/S32K146/startup/system_S32K146.c
Executing target #6 C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c
Executing target #8 C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/clock_manager.c
Executing target #9 C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/interrupt/interrupt_manager.c
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@SDK/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.args" -MMD -MP -MF"SDK/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.d" -MT"SDK/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.o" -o "SDK/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.o" "C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.c"
Invoking: Standard S32DS C Compiler
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@SDK/platform/devices/startup.args" -MMD -MP -MF"SDK/platform/devices/startup.d" -MT"SDK/platform/devices/startup.o" -o "SDK/platform/devices/startup.o" "C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c"
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@SDK/platform/drivers/src/clock/clock_manager.args" -MMD -MP -MF"SDK/platform/drivers/src/clock/clock_manager.d" -MT"SDK/platform/drivers/src/clock/clock_manager.o" -o "SDK/platform/drivers/src/clock/clock_manager.o" "C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/clock_manager.c"
arm-none-eabi-gcc "@SDK/platform/devices/S32K146/startup/system_S32K146.args" -MMD -MP -MF"SDK/platform/devices/S32K146/startup/system_S32K146.d" -MT"SDK/platform/devices/S32K146/startup/system_S32K146.o" -o "SDK/platform/devices/S32K146/startup/system_S32K146.o" "C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/S32K146/startup/system_S32K146.c"
Invoking: Standard S32DS C Compiler
arm-none-eabi-gcc "@SDK/platform/drivers/src/interrupt/interrupt_manager.args" -MMD -MP -MF"SDK/platform/drivers/src/interrupt/interrupt_manager.d" -MT"SDK/platform/drivers/src/interrupt/interrupt_manager.o" -o "SDK/platform/drivers/src/interrupt/interrupt_manager.o" "C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/interrupt/interrupt_manager.c"
<command-line>:0:17: warning: missing terminating " character
In file included from ../Generated_Code/clockMan1.h:57:0,
from ../Generated_Code/clockMan1.c:39:
../Generated_Code/Cpu.h:58:30: fatal error: device_registers.h: No such file or directory
#include "device_registers.h"
^
compilation terminated.
<command-line>:0:17: warning: missing terminating " character
In file included from ../Generated_Code/Cpu.c:53:0:
../Generated_Code/Cpu.h:58:30: fatal error: device_registers.h: No such file or directory
#include "device_registers.h"
^
compilation terminated.
make: *** [Generated_Code/subdir.mk:57: Generated_Code/clockMan1.o] Error 1
make: *** Waiting for unfinished jobs....
<command-line>:0:17: warning: missing terminating " character
../Generated_Code/pin_mux.c:42:30: fatal error: device_registers.h: No such file or directory
#include "device_registers.h"
^
compilation terminated.
make: *** [Generated_Code/subdir.mk:49: Generated_Code/Cpu.o] Error 1
make: *** [Generated_Code/subdir.mk:65: Generated_Code/pin_mux.o] Error 1
<command-line>:0:17: warning: missing terminating " character
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.c:51:30: fatal error: device_registers.h: No such file or directory
#include "device_registers.h"
^
compilation terminated.
make: *** [SDK/platform/drivers/src/clock/S32K1xx/subdir.mk:35: SDK/platform/drivers/src/clock/S32K1xx/clock_S32K1xx.o] Error 1
<command-line>:0:17: warning: missing terminating " character
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/clock/clock_manager.c:34:30: fatal error: device_registers.h: No such file or directory
#include "device_registers.h"
^
compilation terminated.
make: *** [SDK/platform/drivers/src/clock/subdir.mk:35: SDK/platform/drivers/src/clock/clock_manager.o] Error 1
<command-line>:0:17: warning: missing terminating " character
In file included from C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c:62:0:
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/device_registers.h:327:6: error: #error "No valid CPU defined!"
#error "No valid CPU defined!"
^~~~~
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c:69:38: error: 'NUMBER_OF_CORES' undeclared here (not in a function)
static volatile uint32_t * s_vectors[NUMBER_OF_CORES] = FEATURE_INTERRUPT_INT_VECTORS;
^~~~~~~~~~~~~~~
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c:69:57: error: 'FEATURE_INTERRUPT_INT_VECTORS' undeclared here (not in a function)
static volatile uint32_t * s_vectors[NUMBER_OF_CORES] = FEATURE_INTERRUPT_INT_VECTORS;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c: In function 'init_data_bss':
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/startup.c:212:23: warning: implicit declaration of function 'GET_CORE_ID' [-Wimplicit-function-declaration]
coreId = (uint8_t)GET_CORE_ID();
^~~~~~~~~~~
make: *** [SDK/platform/devices/subdir.mk:35: SDK/platform/devices/startup.o] Error 1
<command-line>:0:17: warning: missing terminating " character
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/devices/S32K146/startup/system_S32K146.c:63:30: fatal error: device_registers.h: No such file or directory
#include "device_registers.h"
^
compilation terminated.
make: *** [SDK/platform/devices/S32K146/startup/subdir.mk:35: SDK/platform/devices/S32K146/startup/system_S32K146.o] Error 1
<command-line>:0:17: warning: missing terminating " character
C:/NXP/S32DS_ARM_v2018.R1/S32DS/S32SDK_S32K14x_BETA_1.9.0/platform/drivers/src/interrupt/interrupt_manager.c:58:31: fatal error: interrupt_manager.h: No such file or directory
#include "interrupt_manager.h"
^
compilation terminated.
make: *** [SDK/platform/drivers/src/interrupt/subdir.mk:35: SDK/platform/drivers/src/interrupt/interrupt_manager.o] Error 1
09:50:10 Build Finished (took 7s.938ms)
Raju
Hi Raju,
the problem is the way the DS32 is passing parameters to the build process, and that it seems to handle escape sequences in a wrong way. Just use plain double quotes in that case.
I hope this helps,
Erich
Hi Enrich,
I tried keeping PROJECT_NAME="${ProjName}" in the -D and it built succesfully.
Now I tried using the accesing the project name using below.
static const char projectName[] = PROJECT_NAME;
Now If I build it shows an error as shown below.
Suggest where I went wrong in this
Raju
Hi Raju,
that's the very same error when I tried use IDE variable in preprocessor macro definition. I spend another time to figure out what's wrong - but no success.
May be Erich will have some comment. Here are expanded build command arguments:
-DPROJECT_NAME=\"S32K144_Project_HelloClocks\" -DCPU_S32K144HFT0VLLT -I"C:\Users\nxf24838\workspaceS32DS.ARM.2.2\S32K144_Project_HelloClocks/include" -I"C:\NXP\S32DS_ARM_v2.2\eclipse\../S32DS/build_tools/gcc_v4.9/arm_ewl2/EWL_C/include" -I"C:\NXP\S32DS_ARM_v2.2\eclipse\../S32DS/build_tools/gcc_v4.9/arm_ewl2/EWL_C/include/arm" -I"C:\NXP\S32DS_ARM_v2.2\eclipse\../S32DS/build_tools/gcc_v4.9/arm_ewl2/EWL_Runtime/include" -I"C:\NXP\S32DS_ARM_v2.2\eclipse\../S32DS/build_tools/gcc_v4.9/arm_ewl2/EWL_Runtime/include/arm" -O0 -g3 -Wall -c -fmessage-length=0 -mno-pic-data-is-text-relative -msingle-pic-base -mpic-register=r9 -v -ffunction-sections -fdata-sections -mcpu=cortex-m4 -mthumb -specs=ewl_c9x_hosted.specs --sysroot="C:\NXP\S32DS_ARM_v2.2\eclipse\../S32DS/build_tools/gcc_v4.9/arm_ewl2"
Jiri
I would say it is a bug (or glitch, whatever) how the DS32 build system is dealing with macro expansions and the way the build tools are intergrated. The issue is that the DS32 is placing the wrong content into the .args file.
So
PROJECT_NAME=\"${ProjName}\"
gets transformed into
(side note: the DS32 does use such args files as interface to the build tools instead passing that on the command line).
The solution for the DS32 is to use normal double quotes like this:
Then it gets correctly placed into the .args file:
I hope this helps,
Erich
Hi Erich,
it looks, not-escaped quotation marks also doesn't work - the quotation marks are ignored when passing to command:
This is definitely S32DS bug - I'll create JIRA ticket for that.
Jiri
Hi Raju,
I tried define macro for project name in Preprocessor macro definitions, but it looks, that macros based on IDE variables can't be expanded by preprocessor.
So, if you need project name - you have two options:
manually define it for example in your main.c file like
#define MY_PROJECT_NAME "MyProjectName"
if you need it updated automatically (when project name is changed or for different project) - you can use pre-build step and start some .bat script which will generate for example proj_name.h file with
#define MY_PROJECT_NAME "MyProjectName"
line.
"MyProjectName" can be get from filesystem (name of folder where project is) or by parsing .project xml file.
Anyway, for what purpose you need Project name in your code?
Jiri
Thanks Jiri for your response,
The intension of accessing the filename is to store this software image name within the device.
Do you have any .bat scripts which serve this purpose.
Raju.
Hi,
unfortunately don't have such batch file (actually - this is very first time when I met such requirement).
But writing such batch script should be easy. Here are some basics:
Output to file - How can I use a batch file to write to a text file? - Stack Overflow
Getting current directory - windows - Get current batchfile directory - Stack Overflow
Hope it helps.
Jiri
Hi Jiri,
I tried using the batch file with command %~p0, but it gives th complete location of the folder in which the batch file exists, but what exactly I need is the folder alone.
Any possible help in this regard.
Raju
Dear Jiri,
As suggested I created a batch file & it generates the header file as well if it's manualaly run the batch file.
But when I added in pre-build steps it generates an error during build & doesn't created a header too. A console is as shown below.
10:47:40 **** Incremental Build of configuration Debug_FLASH for project hello_world_s32k146 ****
make -j8 pre-build main-build
"C:/Users/bj.rajendranath/workspaceS32DS.ARM.2018.R1/hello_world_s32k146/hello_world_s32k146/console.bat"
C:\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\Debug_FLASH>echo | set /p= "#define MY_PROJECT_NAME " 1>project_header.h
C:\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\Debug_FLASH>set MYDIR=\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\
C:\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\Debug_FLASH>set MYDIR1=\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146
C:\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\Debug_FLASH>for %f in (\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146) do set myfolder=%~nxf
C:\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\Debug_FLASH>set myfolder=hello_world_s32k146
C:\Users\bj.rajendranath\workspaceS32DS.ARM.2018.R1\hello_world_s32k146\hello_world_s32k146\Debug_FLASH>set /p = " "hello_world_s32k146" " 0<nul 1>>project_header.h
make: [makefile:85: pre-build] Error 1 (ignored)
Executing target #14 hello_world_s32k146.siz
Invoking: Standard S32DS Print Size
arm-none-eabi-size --format=berkeley hello_world_s32k146.elf
text data bss dec hex filename
5928 3408 3144 12480 30c0 hello_world_s32k146.elf
Finished building: hello_world_s32k146.siz
Also, Suggest how to reflect it in the project, as it requires the manual addition of the header file.
Raju
Hi,
It the project_header.h file contains line with your project definition - you can just include it in main.c (or in source, where you need it) for example. Also make sure, that Project knows path for this header file (or generate this header in /include folder):