[S32K3 tool part]:How to use IAR compiler or IAR project to compile S32K3 MCAL project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[S32K3 tool part]:How to use IAR compiler or IAR project to compile S32K3 MCAL project

[S32K3 tool part]:How to use IAR compiler or IAR project to compile S32K3 MCAL project

[S32K3 tool part]How to use IAR compiler or IAR project to compile MCAL project

 

1.    Abstract

     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

2. IAR Complier with S32K3 RTD MCAL project

2.1 S32K3 HW and SW

SW32K3_S32M27x_RTD_R21-11_6.0.0

S32K3X4-EVB

Based on Dio_TS_T40D34M60I0R0

IARIAR EW for Arm 9.70.1

EB tresos29.0.0

2.2 Compile MCAL project steps using IAR compiler CMD method

2.2.1 Copy one RTD MCAL new project

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

kerryzhou_0-1759479138916.png

Fig 1

2.2.2 Complie EB tresos project

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:

kerryzhou_1-1759479139017.png

Fig 2

2.2.3 Vscode open Dio_TS_T40D34M60I0R0_IAR project

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

kerryzhou_2-1759479139074.png

Fig 3

2.2.4   Project_parameters.mk modification

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.

kerryzhou_3-1759479139116.png

Fig 4

2.2.5   Check_build_params.mk modification

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

kerryzhou_4-1759479139165.png

Fig 5

2.2.6        Makefile modification

  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

kerryzhou_5-1759479139311.png

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)

kerryzhou_6-1759479139439.png

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  

kerryzhou_0-1759486694885.png

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

 

kerryzhou_8-1759479139911.png

Fig 9

kerryzhou_9-1759479140195.png

Fig  10

So how did these IAR compilation options come about? You can refer to the release note of RTD600, which contains corresponding descriptions

kerryzhou_10-1759479140292.png

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

 

kerryzhou_11-1759479140481.png

Fig 12

2.2.7   Build to generate elf

Commander:

make clean

make build

to generate the elf files:

kerryzhou_12-1759479140695.png

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.

3. Import RTD MCAL to IAR IDE project

This chapter explains how to create an IAR IDE project and import MCAL drivers to implement S32K3 MCAL combined with EB tresos for running.

3.1 MCAL IAR IDE project 2 methods

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

kerryzhou_13-1759479140899.png

Fig 14

3.2 MCAL IAR IDE project import steps

3.2.1 create the new RTD MCAL IAR project folder

   Create a new folder, named as:S32K344_DIO_MCAL_RTD600_IAR

3.2.2 create the sub folder for IAR project

      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

kerryzhou_14-1759479140922.png

Fig 15

3.2.3 create EB tresos project

(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

kerryzhou_15-1759479141010.png

Fig 16

3.2.4 Copy RTD related drivers to IAR project folder

(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.

kerryzhou_16-1759479141081.png

Fig 17

3.2.5 IAR IDE create IAR project

  (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.

kerryzhou_17-1759479141217.png

Fig 18

(4)IAR project platform folder added result:

kerryzhou_18-1759479141232.png

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

kerryzhou_19-1759479141564.png

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

kerryzhou_20-1759479141785.png

Fig 21

(4)Debugger

Setup: PE micro, run to main

Extra Options:

Use command line options:

--drv_vector_table_base=__ENTRY_VTABLE

kerryzhou_21-1759479141872.png

Fig 22

3.2.7  Build IAR project

Project->Rebuild All

kerryzhou_22-1759479141894.png

Fig 23

3.2.8  Test result

Download and debug result:

kerryzhou_23-1759479142011.png

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.

 

Attachments
No ratings
Version history
Last update:
2 weeks ago
Updated by: