Module 1: Environment Setup

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

Module 1: Environment Setup

23,669 Views
dumitru-daniel_
NXP Employee
NXP Employee

INTRODUCTION

In this module of the 3-Phase PMSM Workshop, the focus is on the hardware and software setups that are going to be used throughout this workshop to implement and test a complete 3-phase Permanent Magnet Synchronous Motor (PMSM) control system with NXP’s S32K micro-controller family. Except for the hardware components that can be purchased from NXP website or various distributors around the world, the software tools used for developing the applications are free of charge.

 

The following table summarize the most important resources that will be used for reference for upcoming modules:

S32K144EVB & SoC DEVKIT MOTORGD

S32K144EVB  – Product home page

S32K144EVB  – Quick Start Guide

S32K144 SoC – Reference Manual

S32K144 SoC – Data Sheet

DEVKIT MOTORGD  – Product home page

DEVKIT MOTORGD  – Quick Start Guide

MC34GD3000            – Data Sheet

PMSM DEVKIT          – Product home page

DEVELOPMENT TOOLS

MATLAB TOOLBOX for S32K1xx Add-On Installer – MathWorks File Exchange Page

FreeMASTER Run-Time Debugging Tool                – Product home page

S32DS-ARM Design Studio IDE for ARM                – Product home page

Support & Training                                                   – Community page

 

 

 

HARDWARE SETUP

Nowadays, to most common and convenient way to implement the Field Oriented Control (FOC) to control the rotor position in a PMSM is numerical/digital approach. In the distant past like ‘70s & ‘80s most of the applications were developed using analogue techniques which posed a lot of challenges in terms of maintenance and scalability.

 

Today, we face an abundance of cost effective micro-controller solutions that are reliable, performant and integrates various functionalities that makes engineers life easier than ever. One of such solution is the NXP’s S32K scalable family of AEC-Q100 qualified 32-bit ARM Cortex-M4F and Cortex-M0+ based MCUs targeted for general purpose automotive and high reliability industrial applications.

 

Due to its low cost, large availability and feature-rich options we choose to implement the motor control solution on NXP’s S32K144EVB Development Kit. As is shown in Fig. 1, this small form factor low cost (US$49) platform is a perfect development system for quick application prototyping and demonstration. 

 

pastedImage_59.png
Fig. 1: S32K144EVB’s components & ports used during the workshop

 

The main component of this development platform is the S32K144 MCU that integrates a 32bit Cortex M4F core capable of running at 112MHz with 512KB of Flash memory and 54KB of RAM . Dedicated hardware peripherals for motor control (FTM, ADC, PDB, Timers) and a large collection of communication blocks makes this MCU a suitable candidate for various industrial and automotive applications. A block diagram with the most important components and features is shown in Fig. 2.

 

In addition to this punchy MCU on the evaluation board we can also find:

  • dedicated OpenSDA serial debug interface that will help us debug and visualize the data in real time;
  • high speed communication CAN controller that support CAN-FD protocol;
  • various interconnect standard headers to interface with other devices;
  • analogue and digital inputs/outputs to control the application and/or signal various states;
pastedImage_68.png

Fig. 2: S32K144 MCU Block Diagram

 

The S32K144EVB is design to work in conjunction with various plug in modules the most common one being the DEV-KIT MOTORGD that is designed to offer a low cost (US$49) power inverter solution for PMSM and BLDC motor control applications.

 

As it is depicted in Fig. 3, the kit can be configured to drive PMSM or BLDC applications with a simple jumper configuration that selects which type of measurements are performed: inverter phase currents for PMSM or Back-EMF voltages for BLDC. A dedicated MOSFET gate driver MC34GD3000 controls the 3-phase inverter that can deliver up to 5Amps RMS on each phase. To address sensor based motor control applications the shield support both HALL or ENCODER type of feedback.

pastedImage_78.png
Fig. 3: DEV-KIT MOTORGD’s components & ports used during the workshop

 

To simplify the design process NXP’s is offering a complete out of the box solution for PMSM control application as shown in Fig. 4. The MTRDEVKSPNK144 3-phase PMSM Development Kit with NXP S32K144 MCU is designed to enable rapid prototyping and evaluation of the motor control application without having to wait for the final hardware design.

pastedImage_84.png
Fig. 4: NXP’s MTRDEVKSPNK144 kit used during the workshop

Anyhow, the workshop is designed to be generic. The only part that is absolutely need it: S32K144 MCU. The Model-Based Design approach and the models we are going to develop throughout this workshop are generic and should help you prototype on any other setup made of power inverter and motor.

 

 

 

SOFTWARE SETUP

NXP offers a wide set of enablement tools and software to help customers to prototype and develop complex applications on top of NPX’s hardware. This workshop keep focus on Model-Based Design prototyping techniques and all the applications that are designed to control the PMSM are developed with NXP’s Model-Based Design Toolbox for S32K1xx. This toolbox is designed to work in conjunction with MATLAB and Simulink tools from MathWorks in order to facilitate fast prototyping and deployment with the help of MATLAB Embedded Coder automatic C-code generation as depicted in Fig. 5.

 

The generated code is configured to:

  • enable special functionalities that are delivered as standard drivers by the NXP’s SDK package for S32K MCU families;
  • enable optimized software routines design for motor control supported by NXP’s Automotive Math and Motor Control Library (AMMCLIB);
pastedImage_95.png
Fig. 5: NXP’s Model-Based Design Toolbox SW Architecture Philosophy

 

The main advantages of this approach are:

  • no longer have to focus on C-code implementation leaving extra time available for algorithm development and research;
  • re-use existing standard peripheral initialization code provided via standard SDK;
  • re-use special motor control and math functions exposed via AMMCLIB;
  • easy to migrate between S32K MCU derivatives to match your own criteria of cost vs. performance;
  • simplify the migration between NXP’s platforms that are supported via various Model-Based Design Toolboxes;
  • easy to integrate the MATLAB generated code for generic algorithm into a dedicated Integrated Development Environment such as S32 Design Studio;

NOTE: ALL THE SOFTWARE TOOLS USED IN THIS WORKSHOP ARE FREE. SOME OF THE TOOLS REQUIRES A VALID LICENSE THAT CAN BE OBTAINED FREE-OF-CHARGE FROM YOUR NXP ACCOUNT

                                  

NXP’s Model-Based Design Toolbox for S32K1xx is delivered as an Add-On package that can be installed automatically in MATLAB. This way MATLAB is going to take care of all installation steps and dependencies. This Add-On can be obtained:

 

The easiest way to install the toolbox is to get it directly from MathWorks site via MATLAB Add-Ons Browser as shown in Fig. 6.

pastedImage_107.png
Fig. 6: Browse for Add-Ons in MATLAB

 

With a simple search with S32K keyword a list of available toolboxes should become visible. Most likely the first result returned is the NXP Support Package S32K1xx toolbox.

pastedImage_111.png
Fig. 7: Search results

 

Select the package and click on Add button to start the installation process.

pastedImage_117.png
Fig. 8: Adding the NXP’s toolbox to your local MATLAB Add-on collection

 

After the installation is completed you need to select the Open Folder to change the MATLAB path to navigate to the folder where the toolbox has been installed.

pastedImage_121.png

pastedImage_123.png

Fig. 9: Support Package Install completed

 

Execute the Installer.p file to start the Step-by-step Installer Wizard that will configure the rest of the tools on your PC. You need to have an active NXP account to be able to download the packages and generate a license file. The GUI is configured to make your journey simpler.

 

You need to perform four steps as depicted in Fig. 10:

  • download the package: this is semi-automatic since you need to log-in with NXP account to gain access to mltbx package.
  • install the package: this is done automatically by MATLAB
  • generate the license: this is a manual step. Watch this video to get more details in case you face issues with online documentation from NXP website
  • verify the install: this is done automatically by the Installer Guide.
pastedImage_2.png

Fig. 10: NXP’s Toolbox Installation Guide

 

The final step is to configure a compiler tool-chain that will be used to cross-compile from ARM architecture the MATLAB generated code. The actual toolbox for S32K1xx supports GCC, IAR and GreenHills compilers. For convenience, the toolbox is shipped with the free GCC toolchain that is fully supporting the S32K MCU families. To keep things simple and Simulink models available for anyone we are going to configure the GCC as tool-chain that is going to be used for cross-compilation of motor control applications.

 

Fig. 11 shows the default location of the GCC compiler within the Model-Based Design Toolbox suite and how to create a new System Variable to point to the location of the GCC tool-chain. Please note that the name of the System Variable is defined as: GCC_S32K_TOOL. If you plan to use a different tool-chain please refer to NXP’s Model Based Design Toolbox help that is available directly from MATLAB.

 

pastedImage_4.png

Fig. 11: Setting up the GCC tool-chain as compiler for MBD Toolbox

 

In addition to the Model-Based Design Toolbox installation and configuration you will need to install the FreeMASTER Run-Time Debugging Tool. The installer can be found in the same Toolbox folder as the GCC tool-chain or it can be downloaded separately from the NXP’s official website. The installation of FreeMASTER is very simple, just run the executable and follow the on the screen instructions.

 

 

 

VERIFICATION

There is no better way to verify something than to create an application. To validate that the hardware and software setup is done correctly and prepared for motor control application development we need to build an example that should validate the following aspects:

  • MATLAB code generation: this validates that the NXP toolbox installed correctly, the GCC path and system variable is set correctly, the proper MATLAB licenses exists and are valid
  • Application download: this validates that the board is recognized by the Windows OS, the correct OpenSDA USB drivers are installer and configures, the board is alive
  • Application running: this validates that the application programmed on the board is executed, the HW inputs and output are operational, the communication with the board is stable

 

We can test these aspects with a basic application that consists in:

  • Read the SW2 push button state at each 0.1 seconds
  • Switch on/off the Blue LED
  • Record the value of the push button and display its state via serial communication in FreeMASTER

 

The application flow is shown in Fig. 12. The code that runs on S32K144 MCU will be pooling at each 0.1 seconds the state of the SW2 push button and depending on the value read via the associated digital input will update the state of the Blue LED by writing 1 or 0 to the associated digital output. In the same time the application needs to configure the UART peripheral to send the value of the variable associated with the SW2 push button state to the FreeMASTER where it can be displayed in real time.

pastedImage_3.png
Fig. 12: Basic Application – hardware mapping

 

On the S32K144EVB the hardware schematics indicates that the signal from the SW2 push button is routed to the general-purpose pin PTC12. That is the input we are going to use for reading the push button state at each 0.1 seconds.

pastedImage_5.png

Fig. 13: Push button signal routing

The Blue LED is associated with the PTD0 general-purpose pin. Each time the SW2 push button will be depressed we need to switch the Blue LED ON.

pastedImage_8.png
Fig. 14: Blue LED signal routing

 

To communicate with the S32K144 MCU, we are going to use the built-in OpenSDA that will have a dual purpose: to load/flash the application into the MCU flash memory and to assist with serial communication over the virtual COM port mapped on top of physical USB. For S32K144EVB the MK20 microprocessor that implements the OpenSDA protocol is connected with the S32K144 MCU via RX/TX assigned for UART1 peripheral instance as it is shown in Fig. 15.

pastedImage_11.png

Fig. 15: Communication between the Host PC and S32K144 MCU

To get more information about the OpenSDA hardware and software please visit NXP’s OpenSDA webpage.

 

The entire can be implemented in a matter of minutes using standard Simulink blocks from NXP’s Model Based Design Toolbox for S32K1xx Simulink Library.

pastedImage_1.png

Fig. 16: NXP’s Model-Based Design Simulink Library

Check the video below for to see a step-by-step tutorial regarding the implementation details and final setup validation.

Hands-on video training: How to build an application from scratch with NXP's Model-Based Design Toolbox for S32K MCU family for testing the Hardware and Software environment setup
   
 

 

The final model is shown below:

pastedImage_3.png

Fig. 16: Simulink model to verify the Hardware and Software setup

 

When the application is loaded and executed on the target the following result should be visible in FreeMASTER

pastedImage_5.png

Fig. 17: FreeMASTER variable display

 

We hope you enjoy the new workshop format and find this information useful. Feel free to LIKE this article and comment below.

 

Update revisions:

March 18, 2019

May 06, 2020

29 Replies

119 Views
shangchuan
Contributor I

Hi,

I'm testing the motor control demo from this example in MATLAB 2022a. 

https://www.mathworks.com/matlabcentral/fileexchange/93535-field-oriented-control-of-pmsm-using-nxp-...

After successfully build a target model of motor control algorithms, I click on Run on the host model for real-time communication.

Then I see below error message regarding unable to create a communication link with the serial port. When I plug in to NXP board, I only see the "EVB-S32K144" pops up from the device manage but no any other COM port shows up. Can you help with the issue? Thank you. 

shangchuan_0-1711135119508.png

Best regards,

Shang-Chuan Lee

0 Kudos

67 Views
stefancinipeanu
NXP Employee
NXP Employee

Hello, @shangchuan 

It looks like you have an issue with the PEMicro Windows driver and the S32K144-EVB OpenSDA cannot install properly.

You should have something like this on the Device Manager window:

stefancinipeanu_0-1711361167523.png

What I suggest firstly to do is trying to install the PEMicro Driver for Windows manually, by proceeding with the following steps:

1. Open EVB-S32K144 partition and double-click on the SDA-INFO.HTM file.

stefancinipeanu_1-1711361295655.png

stefancinipeanu_2-1711361331940.png

2. A PEMicro web page will open. Click on the following link and try to install the PEMicro Windows USB Drivers.

stefancinipeanu_3-1711361481322.png

3. You have to create an account on PEMicro in order to download the drivers. 

stefancinipeanu_4-1711362046765.png

After the installation is successful, unplug the EVB and plug it again. The OS should assign a COM Port for your EVB automatically.

Let me know if this works!

Best regards,

Stefan.

 

 

 

 

0 Kudos

3,136 Views
mgoldamm
Contributor I
Thanks for the great setup guide! I'm pretty new to the world of MBD, so all the information here was extremely helpful, particularly in the demonstration video. However, the demo video is also a little outdated. In case it helps anyone down the road, here are the adjustments I made to the material presented in the video to get everything to run:
○ Simulink Model:
- Change the config information target to be the S32K144 64 KbsRAM MCU
- Build & download the code package using the "Embedded Coder" app in Simulink
○ FreeMASTER:
- Use COM5 for the project option port, since that maps to the OpenSDA interface
0 Kudos

16,298 Views
mpalframan
Contributor II

Hello,

I'm having trouble connecting with FreeMASTER for the last step. I see the COM port in Device Manager and see the mapped network drive, but using the recommend procedure or the connection Wizard, FreeMASTER can't connect to an UARTs

I tried the Ipuart_hello_world_s32k14x example, and that worked over PuTTY on the same COM port and baud rate.

I was able to use FreeMASTER with the MCSPTE1AK144 getting started example with S32 Design Studio in lieu of Simulink

Any Ideas of what might be going wrong?

0 Kudos

15,932 Views
RajG
Contributor III

@mpalframan try direct from tools option from above, it worked for me.

(PS: attaching screenshot for your help)

Regards,

RajG.

0 Kudos

17,521 Views
haibo
Contributor I

Hello Dumitru,
I am practicing the model "Verify_SW_HW_Setup",but it doesnot work well.
I followed the steps step by step, but every time the program is compiled and downloaded to the development board, it failed: the simulink always showed "building" for a long  time( i wait for twenty minutes ), and the light on the development board flashed in blue at a certain frequency.
Then i looked at the diagnostic log and it showed "*** Created executable: Verify_SW_HW_Setup.mot ### Successful completion of build procedure for model: Verify_SW_HW_Setup"
I uploaded a diagnosis viewer screenshot and a video of the malfunction.
My matlab version is matlab 2019a, and the computer operating system is Win10.
Thanks very much and wait for your reply!

 

 

0 Kudos

17,958 Views
Jimny
Contributor II

Hello, @dumitru-daniel_ 

The figures and videos in module 1 to module 10 cannot be loaded and displayed for several days.

I have checked my internet connection, web browser setting and disabled ad filter, I have even tried to browse these pages using starbuck's wifi and with different web browser, firefox, chrome, ms edge, but the figures and videos cannot be displayed.

Please help.

0 Kudos

17,978 Views
Jerry_zhang
Contributor I

Hi dumitru-daniel_,

  I followed the software setup steps in module1,but it doesn't work well ,i can't  use the simulink  model "Verify_SW_HW_Setup" you uploaded to generate code .My matlab version is matlab 2019a.I tried "MBDToolbox_S32K1xx_2018.R1_20180723" and" MBDToolbox_S32K1xx_4.2.0_20200720",the same errors happended . I will upload some pictures about the errors and the location of the GCC compiler in my computer.

Would you please  give me some advices. Thanks a lot.

                                                                                                                                                         Jerry

0 Kudos

17,907 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Jerry_zhang ,

From your screenshots I see two issues: the library link is broken, which means that either probably our toolbox is not in the Matlab's path, or the model is designed using another MBDT version. There is also the license error that tells that the toolbox is not able to see a valid MBDT license.

I would proceed using the following approach:

1. type the 'ver' command in Matlab, you should see a line like this:

Model-Based Design Toolbox for S32K1xx Series Version 4.2.0 (R2016a-R2020a)

If not, please set the Matlab Path to default and then go in the AddOns folder, where our toolbox is installed, and run the mbd_s32k_path.m script.

mariuslucianand_0-1600071098883.png

This will install our toolbox in the Matlab Path.

Now open the model and let me know if this solved the problem.

Hope this helps,

Marius

 

 

0 Kudos

17,968 Views
Jimny
Contributor II

The same problem occurs to me.

I use matlab 2019b and NXP_MBDToolbox_S32K1xx 4.2.0

1.png

 

2.png

 

0 Kudos

17,917 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Jimny ,

 

Looks like the read_SW2_pushbutton has the link broken with our library.

mariuslucianand_0-1600071336402.png

The easiest way for solving this issue is to delete the block, open our library and replace the deleted block with a Digital Read block from MBDT library. You then need to select back the PTC12 pin inside the read block. This will solve the link issue.

 

mariuslucianand_1-1600071558879.png

Hope this helps,

Marius

 

0 Kudos

17,852 Views
Jimny
Contributor II

@mariuslucianand @Jerry_zhang 

Hi, it happens to me that I found a solution to the broken link problem in all the model files attached.

First of all, I use matlab version 2019b and nxp mbd tool box 4.2.0.

When open the model file for the first time, e.g. ...\M1_2018.R1\Verify_SW_HW_Setup.mdl, matlab prompts the following diaglog box.

1.png

 

Click YES to open the model. And we can see there is a broken link model in the file.

2.png

 read_SW2_pushbutton is broken

Then we should save the model file, just click the SAVE button on the top right corner. And matlab will prompt the following dialog box.

3.png

 It seems the original file was created in an older matlab version, and when we save the file, it will be saved in a newer format and the old one will also be saved with its version number appended.

Just click OK to continue. And we will find a extra file is created in the directory.

4.PNG

 

Finally, open the model "Verify_SW_HS_Setup.mdl" again, matlab prompts the following dialog.

5.png

 It says that matlab will try to fix the broken links automatically.

Just click YES and voila, here is a working model.

6.png

 

I use this method to solve the same problem in module 4 and 5, and it works. The only thing you should to repair manually is in the fastloop control subsystem, the inverse park module and standard svm module has their port number changed, so you should repair the problem yourself.

7.png

 

There are some extra minor problems should be fixed to make the model run. Good luck.

0 Kudos

17,835 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Jimny ,

Thank you very much for your step-by-step explanation!

Regards,

Marius

0 Kudos

17,938 Views
Jerry_zhang
Contributor I

If you solve the problem,i hope you can share with me,thanks.

0 Kudos

18,079 Views
hossam_yonis
Contributor II

Hello,

Thanks for this demo.

I have a question about the out-port that I need to add so that I can show it in Freemaster.

I did all the steps but still the out-port name is not shown in Freemaster, Is there a way to check what I missed ?

0 Kudos

18,079 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi hossam.yonis@valeo.com‌,

Depending on your MATLAB/Simulink version you will probably need to define the Simulink Outport in the model itself as a "volatile" data type.

Otherwise, you will need to check the generated code and see in which variable the Simulink store the output. It is typically something like <model_name>_b.<variable_name> and plot that in the FreeMASTER.

Let me know if that works!

Best regards,

Daniel

18,079 Views
jeremoto
Contributor I

Hello,

 

I have the same issue. Even when I create a simulink signal object like hossam.yonis@valeo.com , I can't find the variable in freemaster. It seems to read correctly the addresses, because the value of the variable change when I change the address.

In the generated code, what can I do with the variable name?

 

Thanks

0 Kudos

18,079 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi jeremoto‌,

In general, I recommend using "volatile" - this way the variable will not be optimized out by cross-compiler (GCC/IAR/etc

If you use the data store then:

pastedImage_1.png

If you use the signals to assign variables then:

pastedImage_2.png

If you still can't find it after using "volatile" then have a look in the generated code. Typically, Simulink creates a structure and your variable is one of these structure fields.

Hope this helps!

Daniel

18,079 Views
jeremoto
Contributor I

It works with the data store memory. Thank you !

0 Kudos

18,079 Views
hossam_yonis
Contributor II

Hello,

Thank you for the tip, I created a simulink signal object and make it's storage class as global and now works.

Thanks again.