[S32K3 Tools Part] How to port RTD's existing MCAL demo to other K3 chips
From the release notes of NXP's RTD4.0.0, we can see that the supported chip models are very complete:
Fig 1
From this point, we can know that RTD4.0.0 can cover all S32K3 series chips. But if you want a ready-made demo, such as MCAL demo, you can see it under the ready-made demo path, for example:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0\examples\EBT
Just S32K344,S32K358,S32K388,S32K396,S32M276。
Therefore, if you use other S32 chips, such as K312, in actual use, although it is within the range supported by RTD, but there is no ready-made demo to use, you need to do the porting by yourself. This article will explain how to port the RTD4.0.0 K344 MCAL demo to S32K312 and configure the corresponding EB project. First, implement the execution in the command line. After success, port the working MCAL code EB project to S32DS.
This article is based on RTD4.0.0: SW32K3_S32M27x_RTD_R21-11_4.0.0
For other versions with patch or HF, the operation process is the same!
Hardware platform: S32K312 mini EVB or S32K312EVB
Other official EVBs, such as S32K31XEVB, or the customer's own S32K3 hardware board also have the same steps.
Due to the lack of official EVB boards, this article is based on S32K312 mini EVB, combined with P&E Multilink simulator download simulation. The platform situation is as follows:
Fig 2
The reference demo can be any existing demo in RTD4.0.0. In order to simplify the process, this article takes DIO as an example:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0\examples\EBT\S32K3XX\Dio_Example_S32K344
In order not to affect the original RTD default demo, here we directly copy a Dio_TS_T40D34M40I0R0 and open the path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins
Copy Dio_TS_T40D34M40I0R0 and save it in a folder named: Dio_TS_T40D34M40I0R0_miniK312_doc
The process for other chips is similar. You only need to change the chip name and related configuration to the required chip.
Open folder:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX
Copy Dio_Example_S32K344 to Dio_Example_S32K312
Fig 3
Open path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\TresosProject
Modify the EB project Dio_Example_S32K344 to Dio_Example_S32K312
Fig 4
Enter the newly created Dio_Example_S32K312, open the path with VScode, and save the VScode workspace to this path.
Modify project_parameters.mk:
GCC_DIR = C:/NXP/S32DS.3.5_RTD400/S32DS/build_tools/gcc_v10.2/gcc-10.2-arm32-eabi
TRESOS_DIR = C:/EB/tresos_29_0_0
PLUGINS_DIR = C:/NXP/SW32K3_S32M27x_RTD_R21-11_4.0.0/eclipse/plugins
EXAMPLE_DERIVATIVE = S32K312
TRESO_PROJECT_NAME = Dio_Example_S32K312
Fig 5
Fig 6
Check_build_params.mk, delete the following code:
ifeq ("$(wildcard $(T32_DIR)/bin/windows/t32marm.exe)","")
$(error Invalid path set to Trace32. \
The provided path: from project_parameters.mk T32_DIR=$(T32_DIR) is invalid!)
endif
This part is used for lauterbach trace32. If it is not deleted, an error will be reported.
The following is the configuration of the EB project. Open the EB tresos Studio 29.0 software and import the project.
File->Import->General->Existing Projects into Workspace, add the EB project path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\TresosProject\Dio_Example_S32K312
Note, do not click copy projects into workspace!!!
Select the project Dio_Example_S32K344, right-click the mouse, and rename it to: Dio_Example_S32K312
Fig 7
Double-click someId to open the configuration module.
Open the Resource module, General->ResourceSubderivative select the target chip partbumber, here select: s32k312_hdqfp172
Fig 8
After saving, you will find many errors reported as follows:
Fig 9
There is no need to worry too much here, because if you analyze it carefully, you will find that it is actually because there are many modules on K344 that K312 does not have. So enter the error prompt location and delete the missing K312 module.
Mcu->McuModeSettingConf->McuPeripheral
If you click in, you can find that if the K312 does not have a module, there is a red cross in front of the peripheral Name.
Fig 10
The direct method is to delete all the error items, a total of 41.
After deleting, you can find that all the problems are gone:
Fig 11
Select someId in the project, right-click, and click Generate Code. You can see that the project can be generated without any errors.
Fig12
Don't take it lightly here. Although the code can be generated without error, there is still a place that needs to be modified.
Here, we can firstly close the EB tresos tool, then open terminal->new terminal in VScode and enter:
Fig13
We can see the error content is : mcucgm0_clockMux0/McuClockMux0Divider5, McuClockMux0Divider6, McuClkMux0Div5_En, McuClkMux0Div6_En.
Open S32KRM here, and you can see that K312 actually does not have MUX_0_5,6.
Fig 14
At this time, when I opened the EB tresos software again, there was indeed such an error on the interface, and there was no divider 5,6 option in mcucgmClockMux0.
Fig 15
Don't worry at this time, there is a way to fix this problem.
Close the EB tresos tool and open the text:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\TresosProject\Dio_Example_S32K312\config\ Mcu.xdm
file.
Directly turn off the enablement and value configuration of divider 5 and 6 in the file.
Modify the following code:Modified to:The main thing is to change the enable and frequency value of Mux0Divider5,6 hidden in the file.
Reopen it and you can see that the error disappears. Right-click on the EB project someId, generate project, and the code can be generated normally without error.
Here is a little trick: In order to prevent the mismatch between the previously generated code and the latest EB project, you can also change:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\generate
Folder:src,include clean it,then regenerate in EB tresos when generating a project.
Close the EB software and enter make generate again in the terminal of the Vscode project
You can see that there are no problems at this time:
Fig 16
From the above steps, the code and EB configuration migration of an existing RTD K344 project to a K312 MCAL project has been completed. Now, through VScode, command line form, generate main.elf, and then download and test.
Command:
make generate
make build
the main.elf can be found in the following folder path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\out
Regarding testing, because there is a main.elf file and PE Multilink, you can create a new K312 project in S32DS. The debug interface is PE Multilink. After compiling and generating the code, copy main.elf to the Debug_FLASH folder of the new project. In the S32DS debug configuration, directly replace the C/C++ application with main.elf and download it for testing.
Fig 17
As you can see, you can enter the debug interface, and the LED light on the actual test board can flash successfully.
This means that the MCAL code has been successfully ported to K312.
In the previous document:
Previously, the RTD MCAL EB project was transplanted to the K344 project of S32DS. Simply modify the project name, project chip model, ld file, driver file inclusion, etc., then clean the project and compile the project.
It is assumed here that you already have an RTD MCAL project imported into the S32DS project, and then modify it based on this.
Because the folder was copied under the original RTD folder, there is a newly created folder in the S32DS project Mcal_Plugins->Link_Source. This folder needs to be excluded from compilation:
Select Dio_TS_T40D34M40I0R0_minik312_doc, right-click Build path->remove from->Debug_FLASH.
Fig 18
Rename the project from Mcal_Dio_S32K344_RTD400 to Mcal_Dio_S32K312_RTD400.
Modify the following project configuration, project->properties:
(1)preprocessor
S32K344->S32K312
Fig 19
(2) Sstandard S32DS C Linker->General
Modify
"${MCAL_PLUGIN_PATH}/Platform${MCAL_MODULE_NAME_SUFFIX}/build_files/gcc/linker_flash_s32k344.ld"
To
"${MCAL_PLUGIN_PATH}/Platform${MCAL_MODULE_NAME_SUFFIX}/build_files/gcc/linker_flash_s32k312.ld"
After modification, click apply and close
Now, change the main.c content to the content in path:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\src\main.c
Add header file:
#include "Port_Cfg.h"
Comment code:
// #include "check_example.h"
// Exit_Example(TRUE);
Copy:
C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Dio_TS_T40D34M40I0R0_miniK312_doc\examples\EBT\S32K3XX\Dio_Example_S32K312\TresosProject\Dio_Example_S32K312\config
All the .xdm file to the S32DS EB folder, replace the old file:
Mcal_Dio_S32K312_RTD400\Tresos_Project\Mcal_Dio_S32K344_RTD400\config
Use the EB tresos open the above project, then Generate project,after the code is generated, close the EB project, back to the S32DS side.
clean project:project->clean project, then build the project
Fig 20
You can see that it can be compiled successfully, then RUN->debug configuration selects the downloaded code xxx_Debug_FLASH_PNE. Note that you need to change the Device from S32K344 to S32K312
Fig 21
After successful configuration, click debug, download the code and simulate. The results are as follows:
Fig 22
As you can see, we can successfully enter debug, and the light on the board is actually blinking, which means that the RTD MCAL project demo can be successfully ported to S32K312 S32DS.