Through regular observation, it has been found that there are still many customers using platforms such as MCAL+IAR, including those using IAR compilers and those directly using IAR IDEs. In fact, when I was working on industrial MCUs in the past, I also particularly liked IAR IDE for its fast compilation speed, high compilation efficiency, and small code generation. However, when I came to auto MCU, I found that its popularity was not very high, and I also noticed that some customers encountered various problems when importing MCAL into IAR. Therefore, I will directly write a tool article on how to use IAR compiler or IAR IDE project to compile NXP S32K MCAL in combination with EB tresos MCAL.
This article uses S32K344 combined with RTD600 to illustrate the compilation of MCAL projects using IAR compiler and the direct import of MCAL into IAR IDE projects
SW32K3_S32M27x_RTD_R21-11_6.0.0
S32K3X4-EVB
Based on Dio_TS_T40D34M60I0R0
IAR:IAR EW for Arm 9.70.1
EB tresos29.0.0
Open path
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins
Copy Dio_TS_T40D34M60I0R0 , rename it as Dio_TS_T40D34M60I0R0_IAR
Fig 1
Use EB tresos tool open the following EB tresos project :
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Dio_TS_T40D34M60I0R0_IAR\examples\EBT\S32K3XX\Dio_Example_S32K344\TresosProject
Generate code:
Fig 2
Use VS code open the following path folder:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Dio_TS_T40D34M60I0R0_IAR\examples\EBT\S32K3XX\Dio_Example_S32K344
Of course, you can also directly open this folder path using the command line, as long as you ensure that it is in the same layer path as the. mk and makefile scr
Fig 3
Mainly modify the following points:
TOOLCHAIN = iar
IAR_DIR = C:/IAR/ewarm-9.70.1
TRESOS_DIR = C:/EB/tresos_29_0_0
PLUGINS_DIR = C:/NXP/SW32K3_S32M27x_RTD_R21-11_6.0.0/eclipse/plugins
The path of IAR must be consistent with the version of IAR software used to ensure that the corresponding IAR compiler can be found.
Fig 4
Add the following content to check_build_params.mk:
else ifeq ($(TOOLCHAIN),iar)
ifeq ("$(wildcard $(IAR_DIR)/arm/bin/iccarm.exe)","")
$(error Invalid path set to the IAR compiler. \
The provided path: from project_parameters.mk IAR_DIR=$(IAR_DIR) is invalid!)
Endif
Fig 5
Makefile need the following 5 points modification:
(1)Compilier change
ifeq (${TOOLCHAIN},iar)
CC := $(IAR_DIR)/arm/bin/iccarm.exe
LD := $(IAR_DIR)/arm/bin/ilinkarm.exe
AS := $(IAR_DIR)/arm/bin/iasmarm.exe
# Intel Hexadecimal Flash image tool
GENHEX := $(IAR_DIR)/arm/bin/ielftool.exe
HEX_OPTS := --ihex
OUT_OPTS := -o
endif
Fig 6
(2) SRC_DIRS add TOOLCHAIN
SRC_DIRS += $(foreach mod,$(MCAL_MODULE_LIST),$(PLUGINS_DIR)/$(mod)_$(AR_PKG_NAME)/src) \
$(foreach mod,$(MCAL_MODULE_LIST_ADDON),$(PLUGINS_DIR_ADDON)/$(mod)_$(AR_PKG_NAME_ADDON)/src) \
$(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/startup/src \
$(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/startup/src/m7 \
$(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/startup/src/m7/$(TOOLCHAIN)
Fig 7
(3) Linker file modification
ifeq ($(LOAD_TO),flash)
ifeq (${TOOLCHAIN},iar)
LINKER_DEF:= $(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/build_files/${TOOLCHAIN}/linker_flash_$(DERIVATIVE_LOWER).icf
else
LINKER_DEF:= $(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/build_files/$(TOOLCHAIN)/linker_flash_$(DERIVATIVE_LOWER).ld
endif
else
ifeq (${TOOLCHAIN},iar)
LINKER_DEF:= $(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/build_files/$(TOOLCHAIN)/linker_ram_$(DERIVATIVE_LOWER).icf
else
LINKER_DEF:= $(PLUGINS_DIR)/Platform_$(AR_PKG_NAME)/build_files/$(TOOLCHAIN)/linker_ram_$(DERIVATIVE_LOWER).ld
endif
endif
Fig 8
(4) Complier options change
ifeq (${TOOLCHAIN},iar) ################################################################################ # iar Compiler options ################################################################################ clib := $(IAR_DIR)/arm/lib CCOPT += --cpu=Cortex-M7 \ -DAUTOSAR_OS_NOT_USED \ -DUSE_MCAL_DRIVERS \ --fpu=FPv5-SP \ --cpu_mode=thumb \ --endian=little \ -e \ -Ohz \ --debug \ --no_clustering \ --no_mem_idioms \ --do_explicit_zero_opt_in_named_sections \ --require_prototypes \ --no_wrap_diagnostics \ --diag_suppress=Pa050 \ $(MISRA) \ -D$(PLATFORM) \ -D$(DERIVATIVE) \ -DIAR \ -DUSE_SW_VECTOR_MODE \ -DENABLE_FPU \ -DD_CACHE_ENABLE \ -DI_CACHE_ENABLE
LDOPT := --entry _start \ --enable_stack_usage \ --skip_dynamic_initialization \ --no_wrap_diagnostics \ --cpu=Cortex-M7 \ --fpu=FPv5-SP
ASOPT := $(ASOPT) \ --cpu Cortex-M7 \ --cpu_mode thumb \ -g \ -r \ -DMULTIPLE_CORE
endif
|
Fig 9
Fig 10
So how did these IAR compilation options come about? You can refer to the release note of RTD600, which contains corresponding descriptions
Fig 11
(5) Elf related change
ifeq (${TOOLCHAIN},iar) %.elf: %.o $(LINKER_DEF) @echo "Linking $@" @$(LD) $(ODIR)/*.o $(LDOPT) --config $(LINKER_DEF) --map $(ODIR)/ -o $(ODIR)/$@@ @$(GENHEX) $(HEX_OPTS) "$(ODIR)/$(ELFNAME).elf" "$(ODIR)/$(ELFNAME).hex" else %.elf: %.o $(LINKER_DEF) @echo "Linking $@" @$(LD) -Wl,-Map,"$(MAPFILE)" $(LDOPT) -T $(LINKER_DEF) $(ODIR)/*.o -o $(ODIR)/$@@ @$(GENHEX) $(HEX_OPTS) "$(ODIR)/$(ELFNAME).elf" $(OUT_OPTS) "$(ODIR)/$(ELFNAME).hex" endif
|
Fig 12
Commander:
make clean
make build
to generate the elf files:
Fig 13
After generation, the elf can be burned onto the S32K344 EVB board for testing. The test results show that the onboard red light is flashing, indicating that the IAR compiler can work in command-line mode.
This chapter explains how to create an IAR IDE project and import MCAL drivers to implement S32K3 MCAL combined with EB tresos for running.
Difference between two methods and how to import MCAL drivers:
(1) Directly copy the RTD MCAL driver to the IAR IDE project directory
(2) Connect the IAR IDE project driver to the original RTD driver path
Fig 14
Create a new folder, named as:S32K344_DIO_MCAL_RTD600_IAR
Generate:EB tresos project code
Include:app related include file
Mcal: mcal driver copy from RTD
src: project main file
Tresos_Project:EB tresos project
Fig 15
(1) Create the EB tresos project in the followign path: S32K344_DIO_MCAL_RTD600_IAR\Tresos_Project\Mcal_Dio_S32K344_RTD600_IAR
(2)Add modules: BaseNXP, Dem, Dio, EcuC, Mcu, Platform, Port, Resource
(3)Copy RTD xdm files in the following path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Dio_TS_T40D34M60I0R0\examples\EBT\S32K3XX\Dio_Example_S32K344\TresosProject\Dio_Example_S32K344\config
to: S32K344_DIO_MCAL_RTD600_IAR\Tresos_Project\Mcal_Dio_S32K344_RTD600_IAR\config
(4)EB tresos Generate project
EB tresos code will be generated to folder:
S32K344_DIO_MCAL_RTD600_IAR\Generate
Fig 16
(1) BaseNXP: header, include, src
(2)Det: include, src
(3)Dio: include, src
(4)Mcu: include, src
(5)Platform: build_files, include, src, startup
(6)Port: include, src
(7)Rte: include, src
Copy RTD folder to IAR project is one method, if don’t want to copy the file, also can use the linker to add the RTD install path drivers directly.
Fig 17
(1) Project->Create new project
(2) In the IAR project, add group
The related folder in project can be structured like the fig 18, which contains:
Generate: Include and src->EB tresos project generate code
Mcal: Base, Det, Dio, Mcu, Platform, Port, Rte->Mcal driver
Src: Main.c->project main code
(3) Add RTD mcal related drivers to IAR project
The RTD MCAL related driver files can be directly downloaded from the RTD installation path or copied to a folder in the IAR project, and both methods yield the same result.
Fig 18
(4)IAR project platform folder added result:
Fig 19
(5)main code add
Main.c can copy from path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Dio_TS_T40D34M60I0R0\examples\EBT\S32K3XX\Dio_Example_S32K344\src
to
S32K344_DIO_MCAL_RTD600_IAR\src
Comment:
//#include "check_example.h"
// Exit_Example(TRUE);
3.2.6 IAR project options configuration
(1)General options->Target->Device->NXP S32K344
(2)C/C++ Complier->Preprocessor
Addional include directories:
Use IAR project folder drivers which copied from RTD install path, the directories are:
$PROJ_DIR$\Generate\include
$PROJ_DIR$\mcal\BaseNXP_TS_T40D34M60I0R0\header
$PROJ_DIR$\mcal\BaseNXP_TS_T40D34M60I0R0\include
$PROJ_DIR$\mcal\Mcu_TS_T40D34M60I0R0\include
$PROJ_DIR$\mcal\Platform_TS_T40D34M60I0R0\include
$PROJ_DIR$\mcal\Rte_TS_T40D34M60I0R0\include
$PROJ_DIR$\mcal\Platform_TS_T40D34M60I0R0\startup\include
$PROJ_DIR$\mcal\Det_TS_T40D34M60I0R0\include
$PROJ_DIR$\mcal\Dio_TS_T40D34M60I0R0\include
$PROJ_DIR$\mcal\Port_TS_T40D34M60I0R0\include
$PROJ_DIR$\include
If use the RTD install path drivers, use the following directories:
$PROJ_DIR$\Generate\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\BaseNXP_TS_T40D34M60I0R0\header
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\BaseNXP_TS_T40D34M60I0R0\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Mcu_TS_T40D34M60I0R0\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Platform_TS_T40D34M60I0R0\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Rte_TS_T40D34M60I0R0\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Platform_TS_T40D34M60I0R0\startup\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Dio_TS_T40D34M60I0R0\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Port_TS_T40D34M60I0R0\include
C:\NXP\SW32K3_S32M27x_RTD_R21-11_6.0.0\eclipse\plugins\Det_TS_T40D34M60I0R0\include
$PROJ_DIR$\include
Defined symbols:
S32K3XX
S32K344
IAR
USE_SW_VECTOR_MODE
D_CACHE_ENABLE
I_CACHE_ENABLE
ENABLE_FPU
Extra options:
--no_clustering
--no_mem_idioms
--do_explicit_zero_opt_in_named_sections
--require_prototypes
--no_wrap_diagnostics
Languate 1:
Check Require prototypes
Diagnostics
Suppress these disgnostics:
Pa050
Fig 20
(3)Linker:
Two points need to be added:
$PROJ_DIR$\mcal\Platform_TS_T40D34M60I0R0\build_files\iar\linker_flash_s32k344.icf
Library->Entry symbols: _start
Fig 21
(4)Debugger
Setup: PE micro, run to main
Extra Options:
Use command line options:
--drv_vector_table_base=__ENTRY_VTABLE
Fig 22
Project->Rebuild All
Fig 23
Download and debug result:
Fig 24
After downloading and running, the red led is blinking on the board, indicating that the IAR IDE MCAL import method project has been successfully run.