S32K Knowledge Base

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

S32K Knowledge Base

Labels

Discussions

Sort by:
Hello,      NXP does a big change on document structure.     Generally, you can find pin assignment table, interrupt mapping and memory map table in RM. But now, these information change to Excel files and attached in RM.   For example on S32K.    You will find the words in RM, like 'For reset values per port, see IO Signal Description Input Multiplexing sheet(s) attached to the Reference Manual.'    Then, please go to attachment tab of your PDF file viewer, like Adobe Acrobat Reader DC.     These steps are also fit for MPC57xx , S32R family. Cheers! Oliver
View full article
Welcome to the S32K Microcontrollers forum. Get expert advice from the NXP developer community. Our support team also monitors these forums to provide answers and take your feedback.   Anyone can read the discussions, but only registered NXP Community members can post questions and comments. Before you ask a question, please search the community to find if someone has already offered a solution. If you don’t see a solution, then ask the community your question. S32K Web page S32K Reference manual S32K Data sheet S32K Application notes and other documents S32K Evaluation Board S32 Design Studio IDE https://community.nxp.com/docs/DOC-334170 
View full article
******************************************************************************** * Detailed Description: * * This example shows how to use the back-to-back mode of the PDB to trigger * sequence of ADC channels conversion. 4 PDB channel 0 pre-triggers/triggers are * generated upon single PDB SW trigger. The first trigger is started by the PDB, * no delay is used. Next 3 triggers start after corresponding acknowledgment is * received from ADC0. * * Converted data is used to change color of the EVB led based on Trimmer position. * * ------------------------------------------------------------------------------ * Test HW:         FRDM-S32K144 * MCU:             PS32K144HFVLL 0N77P * Fsys:            default * Debugger:        S32DS * Target:          internal_FLASH * ********************************************************************************
View full article
Hi,        ARM Cortex-M have a DWT (Data Watchpoint and Trace) unit implemented, and it has a nice feature in that unit which counts the execution cycles. The DWT is usually implemented on most Cortex-M3, M4 and M7 devices, including e.g. the NXP S32K14x.      Attachment is the sample project on S32K142 to measure the running time of a function.     Password of extraction is nxp.     Enjoy the measuring!   Cheers! Oliver BTW, Measure the running time of one function on PowerPC could also be gotten through the link.
View full article
************************************************************************************************ Detailed Description: WDOG tested in SystemInit() function (system_S32K116.c) after POR. For debugging purposes: - WDOG counter reference clock is pre-scaled to slow the test (CS_PRES = 1). - During CNT_LOW test, BLUE LED (PTE8) ON. - During CNT_HIGH test, RED LED (PTD16) ON. - Once both tests have passed, GREEN LED (PTD15) ON. If either of the test fails, WDOG will stay in its default configuration and rest the MCU. ---------------------------------------------------------------------------------------------------------------- Test HW: S32K116EVB-Q048 REV.B MCU: S32K116 0N96V Debugger: S32DSR1, OpenSDA Target: internal_FLASH ************************************************************************************************
View full article
******************************************************************************** Detailed Description: The S32K144 MCU is secure if SEC bits are set to non 0b10 value in Flash Secure Register (FSEC). And can be unsecure using either Mass Erase or Verify Backdoor Access Key command provided they are enabled, again indicated by bits KEYEN and MEEM in the FSEC register. The FSEC register is a read-only register and is loaded with the content of the flash security byte in the Flash Configuration Field located in program flash memory during the reset sequence. The configuration field holds the Backdoor comparison key as well and is configurable in startup_S32K144.S file. The attached example code shows use of Verify Backdoor Access Key flash command. The MCU is secured in the Flash configuration field and therefore once the application has been loaded the debugger does not have access to the MCU which must be run stand-alone. The state of the SEC bits is indicated by LEDs. The RED LED indicates the MCU is secure (SEC != 0b10) after reset. After a delay loop, the Verify Backdoor key command is executed which will unsecure the device and the LED will turn BLUE (SEC = 0b10). NOTE: The Verify Backdoor key command is executed from RAM to avoid simultaneous access to the PFlash block. -------------------------------------------------------------------------------------------- Test HW:      S32144EVB-Q100 MCU:           S32K144 0N47T Debugger:    S32DS1.3, OpenSDA Target:          internal_FLASH ******************************************************************************** 2.0     Sep-30-2017     Daniel ********************************************************************************
View full article
/******************************************************************************** Detailed Description: Example shows possible implementation of multiple ADC conversions using SDK. Here 25 channels are sampled periodically. 2 ADC modules and 2 PDBs are used. ADC0 is configured to sample 16 channels, ADC1 9 channels. PDBs are set to back-to-back mode to perform chain conversion. Within ADC component you need to select ADC input to be measured for each item in configuration list. For ADC0 channels ADC ch12 is selected, as it is connected to trimmer on the EVB. DMA is used to read result into single buffer, and DMA callbacks are issued to indicate end of transfer for each ADC module. Within those callbacks PTE14 and PTE15 is toggled. PDB0 output pulse is generated on the PTE16 to indicate start of ADC measurement. This is done periodically at LPIT ch0 rate, which is set to 30us. The ADC0 ch0 result is used to dim LEDs. * ------------------------------------------------------------------------------ * Test HW:       S32K144EVB-Q100 * MCU:           FS32K144UAVLL 0N57U * Target:        Debug_FLASH * EVB connection: * Compiler:      S32DS.ARM.2018.R1 * SDK release:   S32SDK_S32K1xx_RTM_3.0.0 * Debugger:     Lauterbach Trace32 ******************************************************************************** Revision History: Ver Date          Author          Description of Changes 0.1 May-04-2019   Petr Stancik    Initial version *******************************************************************************/
View full article
******************************************************************************** * Detailed Description: * * This example shows how to init DMA for simple memory to memory copy. * Eight 16-bit values are copied upon SW start. * * ------------------------------------------------------------------------------ * Test HW:         FRDM-S32K144 * MCU:             PS32K144HFVLL 0N77P * Fsys:            default * Debugger:        S32DS * Target:          internal_FLASH * ******************************************************************************** Original Attachment has been moved to: Example-S32K144-DMA-RAM2RAM-test-v1_0-S32DS.zip
View full article
S32K1xx   S32K144 Example S32K144 CMP Round-robin S32DS2.0  Example S32K144 Verify Backdoor Access Key S32DS1.3  Example S32K144 FlexCAN0 RXFIFO DMA nonSDK S32DS13  Example S32K144 PDB ADC trigger DMA ISR S32DS  Example S32K144 Flash RW simple S32DS  Example S32K144 DMA memory copy test S32DS  Example S32K144 EEEPROM usage Example S32K144 EEEPROM usage - No SDK  Example S32K144 RTC VLPS  Example S32K144 WDOG RCM interrupt  Example S32K144 SRAM ECC Injection  Example S32K144 RAM Retention S32DS.R1 Example S32K144 I2C Master MPL3115A2 S32DSR1_v3  Example S32K144 FlexCAN RXFIFO DMA S32DS.ARM.2018.R1  Example S32K144_printf_implementation - S32DS_1.0  Example S32k144 UART printf/scanf under FreeRTOS - S32DS Example S32K144 SDK Function call on configurable period using LPIT timer.  Example S32K144 .noinit section usage Example S32K144 PDB ADC DMA S32DS.ARM.2018.R1   Example S32K144 RAM selftest simple S32DS 2018.R1  Example S32K144 Position Independent Code  Example S32K144 FlexCAN Pretended Networking STOP mode test S32DS.ARM.2.2  Example S32K144 LPIT DMA LPSPI  Example S32K144 FlexCAN TX/RX/Error ISR test S32DS2.2  Example S32K144 FlexIO Idle Detection S32DS2.2   S32K146 Example S32K146 Set_whole_FlexRAM-as_RAM S32DS.ARM.2.2   S32K148 Example S32K148 PDB0-PDB1 ring S32DS3.4 RTM4.0.3  Example S32K148 PDB0-PDB1 ring DMA S32DS3.4 RTM4.0.3  Example S32K148 GPIO Interrupt     S32K116 Example S32K116 WDOG Fast Test  Example S32K116 LPUART LIN Slave TXRX ISR S32DS.ARM.2.2  Example S32K116 FlexCAN PN STOP S32DS.ARM.2.2 Example S32K116 FlexCAN VLPR test S32DS.ARM.2.2   S32K118 Example S32K118-SRAM-keep_data_over_SW_reset v0_1 S32DS.ARM.2.2   S32K3xx   S32K344 Example S32K344 PIT BTCU ADC DMA DS3.4 RTD100   Example S32K344 FlexCAN_Ip TX/RX/EnhanceRXFIFO test S32DS3.4 RTD200     Example Siul2_Port_Ip_Example_S32K344_ITCM_DTCM S32DS3.4 RTD300    
View full article
Where can I get s32k14x data sheet or reference manual???
View full article
******************************************************************************************************* * Detailed Description: The purpose of this demo application is to present some usage modes of the eMIOS for the S32K3xx MCU. The application uses the eMios_Pwm driver as OPWMCB ( Center aligned Output PWM Buffered with dead time), OPWMB (Output Pulse Width Modulation Buffered) and OPWMT (Output Pulse Width Modulation Trigger) to generate waveforms.  PWM signal generated by EMIOS 0 CH 1 (OPWMCB mode), EMIOS 0 CH 2 (OPWMCB mode), EMIOS 0 CH 3 (OPWMB mode) and EMIOS 0 CH 4 (OPWMT mode). Each waveform was manipulated to demonstrate a capability (dead time insertion and phase shift) of the configured mode. The application also uses the eMios_Icu driver as ICU_MODE_SIGNAL_MEASUREMENT in SAIC (Single Action Input Capture) mode with interrupts and IPWM (Input Pulse Width Measurement) mode without interrupts to obtain the duty cycle of the captured signal. PWM signal generated by EMIOS 2 CH 8 (OPWMB mode) measured by EMIOS 1 CH 5 (SAIC mode) AND CH 6 (IPWM mode). * Test HW: S32K3X4EVB-T172 * MCU: S32K344 * Debugger: S32DS 3.5, OpenSDA * Target: internal_FLASH *******************************************************************************************************
View full article
******************************************************************************************************* * Detailed Description: The purpose of these demo applications is to present a usage of the LPSPI Driver together with DMA Driver (IP and MCAL) for the S32K3xx MCU. The applications uses the LPSPI driver to transfer data between LPSPI2 (master, no DMA) and LPSPI0 (slave, with DMA) physical units. * Connections * Test HW: S32K3X4EVB-T172 * MCU: S32K344 * Debugger: S32DS 3.5, PEMicro Multilink Universal FX rev.B * Target: internal_FLASH *******************************************************************************************************
View full article
Detailed Description:                      This config tool simplifies DCF records calculation for S32K344 device.                 Look at HowToUse sheet for simple guideline, then work with DCF sheet                 Notes: - Macros have to be enabled!         BR, Petr
View full article
******************************************************************************** The purpose of this demo application is to show you the usage of the FlexCAN module configured to use CAN FD using the S32 RTD API. - This demo application requires two boards, or single board connected with CAN tool. - CAN FD is enabled with bitrate 500/2000 kbps - It configures FlexCAN0 module and its transceiver (TJA1153). - MB0 is used to transmit CANFD std. ID - MB1 is configured to receive any std. ID - Callback function is used as well to handle TX and RX process in MBs. Received ID is echoed back. - setupCanXCVR function is called to Init TJA1153 connected to FlexCAN0 on the board. It expects transceiver in Vanilla state and set TPL to pass all std and ext ID and do not block any message coming from bus. Finally leaving configuration mode without writing to non-volatile memory nor locking the transceiver. * * ------------------------------------------------------------------------------ * Test HW: S32K3X8EVB-Q289 rev B2 * MCU: P32K358HVS 0P14E * Compiler: S32DS.ARM.3.5 * SDK release: S32K3_RTD_4.0.0_D2311 * Debugger: Lauterbach * Target: internal_FLASH * ********************************************************************************
View full article
The following article is intended to give an example on the use of the FS26 in standby mode with the S32K3 MCU also in standby to get lower consumptions on costumer designs and waking up both through an external wake (EXTWAKE) and the PGOOD SBC signal. Software requirements: The attached codes uses the following SW requirements: S32K3 RTD 4.0.0 HF02 FS26 SBC RTD 3.0.0 HW Requirements: There are a few reworks needed on the EVB in order to make the code work.  S32K3X8EVB-Q289 Rev B2: 1.- Remove resistor R2301 and place R2304 instead, this change is because the PTA8 signal has the EXTWAKE option on the user push-button, this allows that when you send a WKPU request from the MCU (with the push-button) what the MCU does when it has PGOOD activated is that it sends an EXTWAKE signal to WAKE1 of the FS26.     2.- Change the J685 jumper position to 2-3, this jumper is the VDEBUG mode.       3*.- Optional: FS26 DS recommend FCCU lines with certain values of resistors on their lines that are not present by default on the S32K3X8EVB-Q289.          I've attached the example program on a ZIP file, hope it helps.  
View full article
This page supports the NXP Tech Days training session AUT-T4984_Hands-On Workshop_Battery Management System Software Stack. The full installation pre-requisites are attached in the .zip bellow. Please follow closely BMS_SWInstalationGuide.pdf.
View full article
This page supports the NXP Tech Days training session AUT-T4978 for "Hands-On Workshop: The Safety Peripheral Driver in the S32K3 - The Next Level to Achieve Safety". The full installation pre-requisites are attached below, as well as the required S32DS demo application project.
View full article
  1. Abstract This article also explains the S32DS+EB configuration, RTD400. The MCAL training of other modules will be based on this structure in the future. However, this article will provide a command line version of the code. If you need the command line mode, you can directly copy one under the RTD MCAL code package and use VScode to compile it. The hardware of this article is based on K312-miniEVB, and the board situation is as follows:      Fig 1 Function: In the K312 MCAL code, the UART transceiver function is implemented using DMA. Since RTD400 does not have K312 routines, there is also a process of porting from RTD400 to K312 MCAL. Of course, the previous article has explained it very clearly, and also provided the S32DS project template. This article will be based on the previous S32DS EB project template.  2. Function Implementation 2.1 K312 MINIEVB hardware configuration For the hardware configuration, since this article only uses UART, the structure is very simple, using the pins: LPUART3_TX: PTD2 LPUART3_RX: PTD3 and an external TTL-USB tool to achieve signal communication. 2.2 EB Configuration     Here we list all the modules used in EB tresos related to this article, and focus on the modules that require specific configuration. Fig 2 2.2.1 Mcl module The Dma Logic Channel interface needs to be configured. The main purpose is to configure two DMA channels for LPUART3_TX and RX. (1)dmalogicChannel_Type_0 Fig 3 (2)dmalogicChannel_Type_2 Fig 4 The callback registered here can also be called directly in the code. 2.2.2 Mcu module Mcu->McuClockSettingConfig->McuClockReferencePoint->Lpuart3_clk Fig 5 In fact, it configures the clock source frequency of LPUART to 24Mhz, which comes from AIPS_SLOW_CLK. 2.2.3 Platform module Platform->Interrupt Controller->IntCtrlConfig,Configure 3 channels: Fig 6 Here we only need to pay attention to the LPUART3 interrupt, as well as the DMA0 channel 6 and channel 7 interrupts, because these two DMA channels are configured for UART TX and RX. FlexIO is ignored, it is just a matter of whether it is deleted in the original routine. 2.2.4 Port module Port->PortContainer, add PTD2,PTD3 pins: Fig 7 Fig 8 2.2.5 Uart module There are two places to configure: (1)uart->General Fig 9 (2)uart->uartChannel Fig 10 There are 4 points to note here: Point 1: Select the clock source configured in the mcu Point 2: Configure the baud rate to 115200 Point 3: Select the asynchronous mode as DMA Point 4: Select the two DMA channels configured in the mcl, and you need to match TX and RX to the corresponding DMA channels. 2.2.6 Rm module Rm->DMA MUX Configure 2 DMA_MUX channels: Fig 11 Fig 12 2.3 main code   #include "Mcl.h" #include "Mcu.h" #include "CDD_Uart.h" #include "CDD_Rm.h" #include "Port.h" #include "Platform.h" #include "Lpuart_Uart_Ip_Irq.h" #include "Flexio_Uart_Ip_Irq.h" //#include "check_example.h" #include <string.h> #include "Port_Cfg.h" #define UART_LPUART_INTERNAL_CHANNEL 0U #define UART_FLEXIO_TX_CHANNEL 1U #define UART_FLEXIO_RX_CHANNEL 2U /* Welcome messages displayed at the console */ #define WELCOME_MSG "MCAL UART DMA Helloworld for automotive with S32K312!\r\n" /* Error message displayed at the console, in case data is received erroneously */ #define ERROR_MSG "An error occurred! The application will stop!\r\n" /* Length of the message to be received from the console */ #define MSG_LEN 50U #define UART_BUFFER_LENGTH ((uint32)10U) Std_ReturnType T_Uart_Status; //uint8 Rx_Buffer[UART_BUFFER_LENGTH]; #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE #include "Uart_Memmap.h" __attribute__(( aligned(32) )) uint8 Rx_Buffer[UART_BUFFER_LENGTH]; #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE #include "Uart_Memmap.h" uint32 g_Uart_CallbackCounter = 0U; uint32 g_DmaCh16_ErrorCallbackCounter = 0U; uint32 g_DmaCh17_ErrorCallbackCounter = 0U; //void Uart_Callback (void); void Uart_Callback(const uint8 HwInstance, const Lpuart_Uart_Ip_EventType Event, void *UserData); void Mcl_DmaCh16_ErrorCallback (void); void Mcl_DmaCh17_ErrorCallback (void); void Uart_Callback(const uint8 HwInstance, const Lpuart_Uart_Ip_EventType Event, void *UserData) { if(Event == LPUART_UART_IP_EVENT_END_TRANSFER) { __asm volatile ("nop"); __asm volatile ("nop"); __asm volatile ("nop"); __asm volatile ("nop"); __asm volatile ("nop"); __asm volatile ("nop"); } else if (Event == LPUART_UART_IP_EVENT_TX_EMPTY) { __asm volatile ("nop"); __asm volatile ("nop"); } else if (Event == LPUART_UART_IP_EVENT_RX_FULL) { __asm volatile ("nop"); } else if (Event == LPUART_UART_IP_EVENT_ERROR) { __asm volatile ("nop"); } else { __asm volatile ("nop"); } } void Mcl_DmaCh6_ErrorCallback (void) { g_DmaCh16_ErrorCallbackCounter++; } void Mcl_DmaCh7_ErrorCallback (void) { g_DmaCh17_ErrorCallbackCounter++; } boolean User_Str_Cmp(const uint8 * pBuffer1, const uint8 * pBuffer2, const uint32 length) { uint32 idx = 0; for (idx = 0; idx < length; idx++) { if(pBuffer1[idx] != pBuffer2[idx]) { return FALSE; } } return TRUE; } /** * @brief Main function of the example * @details Initializez the used drivers and uses the Icu * and Dio drivers to toggle a LED on a push button */ int main(void) { Std_ReturnType UartStatus = E_NOT_OK; uint32 RemainingBytes; uint32 Timeout = 0xFFFFFF; Uart_StatusType UartReceiveStatus = UART_STATUS_TIMEOUT; Uart_StatusType UartTransmitStatus = UART_STATUS_TIMEOUT; /* Initialize the Mcu driver */ Mcu_Init(NULL_PTR); Mcu_InitClock(McuClockSettingConfig_0); Mcu_SetMode(McuModeSettingConf_0); /* Initialize Mcl module */ Mcl_Init(NULL_PTR); /* Initialize Rm driver for using DmaMux*/ Rm_Init (NULL_PTR); /* Initialize all pins using the Port driver */ Port_Init(NULL_PTR); /* Initialize IRQs */ Platform_Init(NULL_PTR); /* Initializes an UART driver*/ Uart_Init(NULL_PTR); T_Uart_Status = Uart_AsyncSend(UART_LPUART_INTERNAL_CHANNEL, (const uint8 *)WELCOME_MSG, strlen(WELCOME_MSG)); if (E_OK == T_Uart_Status) { do { /* Get transmission status */ UartTransmitStatus = Uart_GetStatus (UART_LPUART_INTERNAL_CHANNEL, &RemainingBytes, UART_SEND); } while (UART_STATUS_NO_ERROR != UartTransmitStatus && 0 < Timeout--); Timeout = 0xFFFFFF; UartTransmitStatus = UART_STATUS_TIMEOUT; } for(;;) { /* Receive data from the PC - Get 10 bytes in total */ UartStatus = Uart_AsyncReceive (UART_LPUART_INTERNAL_CHANNEL, Rx_Buffer, UART_BUFFER_LENGTH); if (E_OK == UartStatus) { do { /* Get receive status */ UartReceiveStatus = Uart_GetStatus (UART_LPUART_INTERNAL_CHANNEL, &RemainingBytes, UART_RECEIVE); } while (UART_STATUS_NO_ERROR != UartReceiveStatus && 0 < Timeout--); Timeout = 0xFFFFFF; UartReceiveStatus = UART_STATUS_TIMEOUT; } UartStatus = E_NOT_OK; /* Send data to the PC - Echo back the received data */ UartStatus = Uart_AsyncSend (UART_LPUART_INTERNAL_CHANNEL, Rx_Buffer, UART_BUFFER_LENGTH); if (E_OK == UartStatus) { do { /* Get transmission status */ UartTransmitStatus = Uart_GetStatus (UART_LPUART_INTERNAL_CHANNEL, &RemainingBytes, UART_SEND); } while (UART_STATUS_NO_ERROR != UartTransmitStatus && 0 < Timeout--); Timeout = 0xFFFFFF; UartTransmitStatus = UART_STATUS_TIMEOUT; } UartStatus = E_NOT_OK; } Uart_Deinit(); Mcl_DeInit(); // Exit_Example((T_Uart_Status1 == E_OK) && (T_Uart_Status2 == E_OK)); return (0U); }   It should be noted here that according to RTD C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins\Uart_TS_T40D34M40I0R0\doc的RTD_UART_IM.pdf, RTD_UART_UM.pdf. Fig 13 When doing DMA transfer, the buffer needs to be placed in the noncacheable area. That's why this article is:   #define UART_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE #include "Uart_Memmap.h" __attribute__(( aligned(32) )) uint8 Rx_Buffer[UART_BUFFER_LENGTH]; #define UART_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE #include "Uart_Memmap.h"   3. Test Result Use UART3, pin UART3_TX:PTD2, UART3_RX:PTD3 After the chip is reset, send first: Helloworld for automotive with S32K344! Then wait for reception. After receiving 10 bytes of data, generate uart_callback interrupt and enter LPUART_UART_IP_ENET_END_TRANSFER. You can see that the data received in RX_Buffer is consistent with the data sent. Then, the code will loop back the received data. The test situation is as follows: The figure below shows two groups of tests: PC sends: 1234567890, after MCU receives it, loop it back. PC sends: 0987654321, after MCU receives it, debug stops at the breakpoint, you can check the received buffer situation, you can see that the buffer data is correct. Fig 14 Fig 15 Attached are two code packages: (1) Uart_TS_T40D34M40I0R0_miniK312_3.zipEB MCAL command line method After unzip the code, put it in: C:\NXP\SW32K3_S32M27x_RTD_R21-11_4.0.0\eclipse\plugins, and then you can compile it directly using the command line : Fig 16 (2)Mcal_UARTDMA_S32K312_RTD400_S32DS.zip:The way to import into S32DS, of course, it already contains the EB project: Fig 17  
View full article
1 Abstract After learning S32K3 PWM and have written some MCAL codes, this is the first MCAL article record starts with the combination of K344 EMIOS+ICU+TRIMUX+LCU, which can involve comprehensive configurations such as PORT, DIO, EMIOS, interrupt ICU, TRIGMUX, LCU, etc. The board platform is still based on NXP official S32K344EVB, RTD400, and the function is: use two channels of EMIOS0 and one channel of EMIOS1. After one channel of EMIOS 0 outputs PWM, it connects LCU through TRIGUMX to generate a set of complementary PWM, and the other channel can realize hardware interrupt control of PWM duty cycle through SW5 PT26 button. One channel of EMIOS1 is directly connected to the PTA29 onboard red light, and the brightness is gradually changed by changing the PWM duty cycle, and then the breathing light effect is realized by directly changing the on and off cycle. At the same time, when the PWM turns off the red light, the onboard green light is turned on through DIO, and when the PWM turns on the red light, the DIO turns off the onboard green light. Text description is always less intuitive than graphic description, so here is the picture:      Fig 1 2. Function realization This article is based on porting the MCAL code to the S32DS demo. Then, on the S32DS platform, MCAL related modules are configured through EB, and then compiled and downloaded for simulation through S32DS. Of course, if you like the command line mode, you can directly use the xmd file configured by EB, and then compile with VScode. The process is also very simple. This article will not go into details about the command line method.     2.1 Hardware and software platform Board:S32K344EVB,also can use other K3 boards. IDE:S32DS3.5 RTD: K344 RTD 400 MCAL tool: EBtresos Studio 29.0 2.2 Software control process Before talking about the specific MCAL configuration, here is the software flow chart of the functions in this article:                                                                             Fig 2 Here you can see that the default situation is the one configured through MCAL, and then the PWM frequency is also modified in the code, and the PWM duty cycle is modified by keystrokes and loop delays. 2.3 Resource Allocation Overview The hardware resources and functions used in this article are listed as follows: Fig 3 The configuration of emios related buses is as follows: Fig 4 It should be noted here that for the master bus and bus mode in MCL emios, it is necessary to select the appropriate PWM mode and counter bus in the PWM module, otherwise either the configuration will be wrong or the correct PWM waveform cannot be generated. From the official S32K3 RM, you can check the clock channel and bus type: Fig 5 For example, if EMIOS_CH23 is selected in PWM0, then this bus corresponds to bus A, and this clock can be used for all channels, so PWM0 is CH12 and can use Bus A. CH22 corresponds to bus F, and this clock can also be used for all channels, so it is no problem to select Bus F for PWM1 CH4. CH0 corresponds to bus B, and this clock corresponds to channels 0-7, so it can also be used for PWM2 is CH2. When selecting the counter bus clock source for your EMIOS channel, you must consider the channel coverage of the counter bus. In addition to the selection of the counter bus, there is also the PWM mode selection, which is easier to handle. For clock counting up, select OPWMB, and for clock counting up and down, select OPWMCB center-aligned PWM.      In actual use, the mode selection is usually determined based on one's own PWM requirements, and then based on the following RM table: Fig 6 You can find the channel types that the corresponding mode can support, and then select the corresponding channel, counter bus, etc. according to the channel type in Figure 5. With these basic knowledge, we can directly enter the EB configuration. 2.4 EB configuration    Here we list all the modules used in EB tresos related to this article, and focus on the modules that require specific configuration. Fig 7 2.4.1 Dio module The DioPort interface needs to be configured. The main purpose is to configure PTA30, onboard green light, select DioPort Id=1, Dio Channel Id=14. The rules for DioPortId and Dio Channel Id are as follows:     Channel = DioChannelId + DioPortId∗16 For S32K3X4 derivatives – Port AL=0 – Port AH=1 – Port BL=2 – Port BH=3 – Port CL=4 – Port CH=5 – Port DL=6 – Port DH=7 – Port EL=8 – Port EH=9 – Port FL=10 – Port FH=11 – Port GL=12 – Port GH=13 PTA30=>30=DioChannelId(14)+DioPortId*16 2.4.2 Icu module First, configure IcuSiul2, the goal is to enable the input interrupt of onboard SW5, PTB26. PTB26 corresponds to EIRQ[13], Then, the corresponding interrupt situation is as follows: Fig 8 Fig 9 (1) Icu->IcuSiul2->IcuSiul2Channels:13 (2) Icu->IcuChannel configuration is: Fig 10 Select IcuChannelRef as the previously configured IcuSiul2Channels, and add the interrupt notification function: User_EdgeDetect, note that this function is the name of the user interrupt processing function that needs to be added in the code.    (3)Icu->IcuHwInterruptConfigList-> ICU Peripheral ISR Name: SIUL2_0_IRQ_CH_13,IcuIsrEnable enable 2.4.3 Mcl module This module is mainly used to configure emios counting clock, trgmux, and LCU configuration. (1)Mcl->Trgmux Logic Instance->Hardware Instance: TRGMUX_IP_HW_INST_0   (2) Mcl->Trgmux Logic Group: Fig 11 The main purpose is to connect PWM1 Emios0_ch4 to LCU0_IN0 through Trigmux. (3)Mcl->LCU Configuration Here is the configuration of the LCU module. The main function is to configure the logic input and logic output. There is one input IN0 and two outputs OUT0 and OUT1. Fig 12 Fig 13 Fig 14 OUTPUT0  value is 0XAAAA=43690, OUTPUT1 value is 0X5555=21845 The purpose of this is to generate a pair of complementary PWMs from the input PWM. Fig 15 (4)Mcl->Emios Common Add two Emios, EMIOS_0 and EMIOS_1, which means two EMIOS are used. EMIOS0 is configured with two master bus channels: CH_22 and CH_0, and has different mode types, counting up and down and counting up. EMIOS1 is configured with one master bus channel: CH_23, counting up Corresponding to Figure 4. Fig 16 Fig 17 Note that the channel here is not the actual PWM output channel, but the counter bus channel of the PWM channel, which has the ability to provide clocks. 2.4.4 Mcu module   This module is the basis for the entire MCU to configure the clock. When using the default setting of the original RTD PWM demo, there is only one point that needs attention Mcu->McuClockSettingConfig_0->McuClockReferencePoint->McuClockReferencePoint_0->core clock 48MHZ. This clock is the source of the EMIOS clock. With the clock source, it is not difficult to calculate the actual PWM frequency according to the set period. For example, if a 1Khz PWM is required, you can configure period=48M/1K=48000 2.4.5 Platform module Platform->Interrupt Controller->IntCtrlConfig0, enable SIUL_1_IRQn, and add Handler as: SIUL2_EXT_IRQ_8_15_ISR Note that this SIUL2_EXT_IRQ_8_15_ISR is not written randomly, but must correspond to the one in Siul2_Icu_Ip_Irq.c, otherwise an error will be reported. Fig18 Different interrupts have different interrupt service functions. You need to find the function name defined in the code and fill it into EB. EB configuration is as follows: Fig 19 2.4.6 Port module The configuration of 8 pins is as follows: Fig 20 As you can see, there are 3 main EMIOS PWMs, one input interrupt, one output GPIO, and two output LCU complementary PWMs. 2.4.7 Pwm module Mcl configures the counter clock channel of EMIOS. The PWM channels to be output need to be configured in the Pwm module and linked to the MCU clock source and the emios counter bus source in Mcl. (1) Pwm->PwmEmios Add two groups for the corresponding EMIOS modules. For example, this article uses EMIOS0 and EMIOS1, so two need to be added: Fig 21 For PwmEmios_1, there is one channel, and the configuration is as follows: Fig 22 PwmEmiosBusRef: /Mcl/Mcl/MclConfig/EmiosCommon_1/EmiosMclMasterBus_0 Fig 23 As you can see, the busRef of PwmEmios_1 here is Emios_ch_23 in Mcl, that is, BusA. That is to say, the bus reference clock used by EMIOS1_CH12 comes from EMIOS1_CH23, that is, Bus A. There are two channels configured in PwmEmios_0, and the configuration is as follows: Fig 24 Fig 25 The bus reference clock used by EMIOS0_CH4 comes from EMIOS0_CH22, which is Bus F. Another EMIOS0 channel: Fig 26 Fig 27 The bus reference clock used by EMIOS0_CH2 comes from EMIOS0_CH0, that is, Bus B, so select Bus BCDE. At this point, we can clearly understand the relationship between the real PWM output channel and the internal MCL Emios counter bus channel. (2)Pwm->PwmEmios With the specific information of PWM configured above, we can directly configure the PWM channels. There are three channels in total: PWM0, PWM1, PWM2, which are also the flags needed in the code. Fig 28 2.5 main code   #include "Pwm.h" #include "Mcu.h" #include "Port.h" #include "Mcl.h" #include "Platform.h" #include "Dio.h" #include "Icu.h" //#include "check_example.h" #define NUM_BLINK_LED (uint32)10U #define DELAY_TIMER (uint32)5000000U #define MCL_EMIOS_1_CH_23 (uint16)279U #define MCL_EMIOS_0_CH_22 (uint16)22U Mcl_LcuSyncOutputValueType PWM_OutputList[2]; volatile uint8 UserCountIrqCH0; void TestDelay(uint32 delay); void TestDelay(uint32 delay) { static volatile uint32 DelayTimer = 0; while(DelayTimer<delay) { DelayTimer++; } DelayTimer=0; } void User_EdgeDetect(void) { /* increment IRQ counter */ UserCountIrqCH0++; if(UserCountIrqCH0 % 2 == 0) { Pwm_SetDutyCycle(PwmChannel_2, 0X6000); } else { Pwm_SetDutyCycle(PwmChannel_2, 0X2000); } } int main(void) { uint8 num_blink = 0U, i = 0; uint16 duty_cnt = 0; UserCountIrqCH0 = 0U; /* Initialize the Mcu driver */ Mcu_Init(&Mcu_Config_VS_0); /* Initialize the clock tree */ Mcu_InitClock(McuClockSettingConfig_0); /* Apply a mode configuration */ Mcu_SetMode(McuModeSettingConf_0); Platform_Init(NULL_PTR); /* Initialize all pins using the Port driver */ Port_Init(&Port_Config_VS_0); /* Initialize Mcl driver */ Mcl_Init(&Mcl_Config_VS_0); /* Initialize the Icu driver */ Icu_Init(NULL_PTR); Icu_EnableEdgeDetection(IcuChannel_0); Icu_EnableNotification(IcuChannel_0); /* Initialize Pwm driver , after that Led on*/ Pwm_Init(&Pwm_Config_VS_0); /* PTA29 duty cycle is 50% */ Pwm_SetDutyCycle(PwmChannel_0, 0X4000); // PTB16,pwm1 , emios0_ch4, use trigmux LCU output 2 Complementarity PWM Mcl_LcuSyncOutputValueType lcuEnable[2U]; lcuEnable[0].LogicOutputId = 0; lcuEnable[0].Value = 1U; lcuEnable[1].LogicOutputId = 1; lcuEnable[1].Value = 1U; Mcl_SetLcuSyncOutputEnable(lcuEnable, 2U); TestDelay(DELAY_TIMER); /* Set new period for all channels used external counter bus */ Mcl_Emios_SetCounterBusPeriod(MCL_EMIOS_1_CH_23, 4800, FALSE); // pwmchannel_0 10Khz Mcl_Emios_SetCounterBusPeriod(MCL_EMIOS_0_CH_22, 1200, FALSE);// for PwmChannel_1, 20Khz // PWM0: 10kHZ //PWM1: 20KHZ //PWM2:1KHZ // PTA29 10kHZ /* PTA29 duty cycle is 50% */ Pwm_SetDutyCycle(PwmChannel_0, 0X4000); /* Setup new duty cycle to the pin*/ Pwm_SetDutyCycle(PwmChannel_1, 0x4000); for(i=0; i <= 10; i++) { duty_cnt = i * 0x800; Pwm_SetDutyCycle(PwmChannel_0, duty_cnt); TestDelay(DELAY_TIMER); } /* Using duty cycle 0% and 100% to Blink LED */ while(1) { /* pwm1 when duty cycle is 75% */ Pwm_SetDutyCycle(PwmChannel_1, 0X6000); //Led off Pwm_SetDutyCycle(PwmChannel_0, 0X0000); //red off Dio_WriteChannel(DioConf_DioChannel_Digital_ledgreenPTA30, STD_HIGH); //green on TestDelay(DELAY_TIMER); /* pwm 1 when duty cycle is 25% */ Pwm_SetDutyCycle(PwmChannel_1, 0X2000); //Led ON Dio_WriteChannel(DioConf_DioChannel_Digital_ledgreenPTA30, STD_LOW); //Green OFF Pwm_SetDutyCycle(PwmChannel_0, 0X8000); //RED ON TestDelay(DELAY_TIMER); num_blink++; } /* De-Initialize Pwm driver */ Pwm_DeInit(); //Exit_Example(TRUE); return 0U; }   3. Test Result After power-on, the onboard red light flashes, then gradually turns bright from off, and flashes alternately with the green light. Test PWM1 PTB16: EMIOS0_CH4, the waveform is 20Khz after stabilization, and the duty cycle changes alternately between 25% and 75%. PWM2 PTB14: EMIOS0_CH2, after stabilization, the frequency is 1KHZ, and as the onboard SW5 is pressed, the duty cycle changes alternately between 25% and 75%. Test PTD3, PTD2, it can be seen that it is a pair of complementary waveforms, and the frequency is the same as PTB16, and the duty cycle change rule is also the same. It can be seen that the key interrupt, 3 main PWM, and 2 LCU PWM in this article are already working. Fig 29 Fig 30  
View full article
[S32K3 Tools Part] How to port RTD's existing MCAL demo to other K3 chips  1. Abstract     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. 2. Platform and migration steps 2.1 Platform Description 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 2.2 Migration steps 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 2.2.1 Copy the project and configure 2.2.1.1 Copy the project 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 2.2.1.2 Configure the project 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. 2.2.2 EB project configuration 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  3.Command line compilation and result testing 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. 4. S32DS project migration and testing       In the previous document: https://community.nxp.com/t5/S32K-Knowledge-Base/S32K3-Tools-Part-How-to-import-RTD-EB-project-into-S32DS/ta-p/1966207 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. 4.1 S32DS Project Configuration     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);   4.2 EB project replacement 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. 4.3 MCAL S32DS project testing 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.          
View full article