S32K396 LPSPI DMA

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

S32K396 LPSPI DMA

163 Views
Luis1
Contributor I

Hello,

i can't get lpspi with dma to work. I have looked into many example projects and community posts, but it doesnt seem to fix my problem. A lot of posts and examples are for the s32k344 or similar. I think i am missing something for the S32k396. Here are my settings. I am using the S32K3 Real-Time Drivers AUTOSAR R23-11 Version 7.0.0.

SPI works fine when i disable DMA. So the Pins and Ports should be correct.

Mcl:

i have enabled DMA support.

Luis1_2-1780050952661.png

Luis1_3-1780050990062.png

same with Rx, just different names ("Tx" -> "Rx")

Mcu:

In Mcu/McuModuleConfiguration/McuModeSettingConf/McuPeripheral i have enabled the peripheral clocks for: eDMA, eDMA_TCD_0 and eDMA_TCD_1, DMAMUX_0, LPSPI_1.

RM:

I enabled the dma mux support and enabled global init.

Luis1_4-1780051351639.png

SPI:

Luis1_5-1780051429008.png

Luis1_6-1780051448572.png

Luis1_7-1780051515307.png

IntCtrl_Ip:

Luis1_8-1780051677533.png

And finally my init:

//initialization of the MCAL Autosar drivers

//CLK

if(Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]) == CLOCK_IP_ERROR){

return false;

}//else CLOCK_IP_SUCCESS

//MCU

Mcu_Init(&Mcu_Config_BOARD_InitPeripherals);

//Port

Port_Init(&Port_Config_BOARD_InitPeripherals);

//Interrupts

if(IntCtrl_Ip_Init(&IntCtrlConfig_0) == INTCTRL_IP_STATUS_ERROR){

return false;

}

//DMA

Rm_Init(&Rm_Config_BOARD_INITPERIPHERALS);

Mcl_Init(&Mcl_Config_BOARD_InitPeripherals);

 

//LPSPI1

Lpspi_Ip_StatusType lpspi_status = Lpspi_Ip_Init(&Lpspi_Ip_PhyUnitConfig_SpiPhyUnit_1_Instance_1_BOARD_InitPeripherals);

if(lpspi_status==LPSPI_IP_STATUS_SUCCESS){

Lpspi_Ip_UpdateTransferMode(Lpspi_Ip_DeviceAttributes_SpiExternalDevice_1_Instance_1_BOARD_InitPeripherals.Instance, LPSPI_IP_INTERRUPT); //transfer: interrupt

Lpspi_Ip_UpdateLsb(&Lpspi_Ip_DeviceAttributes_SpiExternalDevice_1_Instance_1_BOARD_InitPeripherals, 0); //0=MSB (big endian)

}else

return false;

 

 

For sending i use something like this:

Lpspi_Ip_AsyncTransmit(&Lpspi_Ip_DeviceAttributes_SpiExternalDevice_1_Instance_1_BOARD_InitPeripherals,

tx_buffer,

rx_buffer,

1,

lpspi1_callback

);

 

Thank you for helping!

Luis

 

 

0 Kudos
Reply
1 Reply

133 Views
VaneB
NXP TechSupport
NXP TechSupport

Hi @Luis1 

First, based on the information provided, it appears that you are mixing low-level drivers (IP layer) with high-level drivers (MCAL). This approach is generally not recommended, particularly if your implementation is intended to be AUTOSAR-compliant.

Regarding your configuration, I have the following observation:

  • For LPSPI1, you have assigned AIPS_PLAT_CLK as the SpiPhyUnitClockRef. However, the source clock for this is AIPS_SLOW_CLK. Therefore, you need to include this clock in the McuClockReferencePoint configuration within the MCU driver and assign it accordingly to this SPI instance.

Regarding your code, as mentioned earlier, you are mixing both software layers, which is not recommended. There are some exceptions when working with low-level drivers, as certain modules are only available in MCAL (for example, the RM), where mixing layers may be expected.

I suggest reviewing the following thread, where two examples are provided: one using the IP layer and another using MCAL. This will help you understand the differences in the APIs required for each approach. Please note that the examples are not specifically intended for S32K396 devices, but they can still serve as a useful reference.

Example S32K344 SPI Transmit & Receive Using DMA DS3.5 RTD500

 

BR, VaneB

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2373027%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K396%20LPSPI%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2373027%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3Ei%20can't%20get%20lpspi%20with%20dma%20to%20work.%20I%20have%20looked%20into%20many%20example%20projects%20and%20community%20posts%2C%20but%20it%20doesnt%20seem%20to%20fix%20my%20problem.%20A%20lot%20of%20posts%20and%20examples%20are%20for%20the%20s32k344%20or%20similar.%20I%20think%20i%20am%20missing%20something%20for%20the%20S32k396.%20Here%20are%20my%20settings.%20I%20am%20using%20the%26nbsp%3BS32K3%20Real-Time%20Drivers%20AUTOSAR%20R23-11%20Version%207.0.0.%3C%2FP%3E%3CP%3ESPI%20works%20fine%20when%20i%20disable%20DMA.%20So%20the%20Pins%20and%20Ports%20should%20be%20correct.%3C%2FP%3E%3CP%3EMcl%3A%3C%2FP%3E%3CP%3Ei%20have%20enabled%20DMA%20support.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_2-1780050952661.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_2-1780050952661.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387270iFF6FC61CE06B744E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_2-1780050952661.png%22%20alt%3D%22Luis1_2-1780050952661.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_3-1780050990062.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_3-1780050990062.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387271iAD31BCA91B8B51DC%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_3-1780050990062.png%22%20alt%3D%22Luis1_3-1780050990062.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Esame%20with%20Rx%2C%20just%20different%20names%20(%22Tx%22%20-%26gt%3B%20%22Rx%22)%3C%2FP%3E%3CP%3EMcu%3A%3C%2FP%3E%3CP%3EIn%20Mcu%2FMcuModuleConfiguration%2FMcuModeSettingConf%2FMcuPeripheral%20i%26nbsp%3Bhave%20enabled%20the%20peripheral%20clocks%20for%3A%20eDMA%2C%20eDMA_TCD_0%20and%26nbsp%3BeDMA_TCD_1%2C%20DMAMUX_0%2C%20LPSPI_1.%3C%2FP%3E%3CP%3ERM%3A%3C%2FP%3E%3CP%3EI%20enabled%20the%20dma%20mux%20support%20and%20enabled%20global%20init.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_4-1780051351639.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_4-1780051351639.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387272i72F7A2B57371F96B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_4-1780051351639.png%22%20alt%3D%22Luis1_4-1780051351639.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ESPI%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_5-1780051429008.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_5-1780051429008.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387273iCD9B629463F95119%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_5-1780051429008.png%22%20alt%3D%22Luis1_5-1780051429008.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_6-1780051448572.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_6-1780051448572.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387274iF87DDDCF0422EDDA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_6-1780051448572.png%22%20alt%3D%22Luis1_6-1780051448572.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_7-1780051515307.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_7-1780051515307.png%22%20style%3D%22width%3A%20374px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387275iE45C27B924DE1CA3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_7-1780051515307.png%22%20alt%3D%22Luis1_7-1780051515307.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIntCtrl_Ip%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Luis1_8-1780051677533.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Luis1_8-1780051677533.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F387278i7D15A1882AA4600F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Luis1_8-1780051677533.png%22%20alt%3D%22Luis1_8-1780051677533.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EAnd%20finally%20my%20init%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CP%3E%3CSPAN%3E%2F%2Finitialization%20of%20the%20MCAL%20Autosar%20drivers%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2FCLK%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E(Clock_Ip_Init(%26amp%3BMcu_aClockConfigPB_BOARD_InitPeripherals%5B0%5D)%20%3D%3D%20%3C%2FSPAN%3E%3CSPAN%3ECLOCK_IP_ERROR%3C%2FSPAN%3E%3CSPAN%3E)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%3CSPAN%3E%20false%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CSPAN%3E%2F%2Felse%20CLOCK_IP_SUCCESS%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2FMCU%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EMcu_Init(%26amp%3BMcu_Config_BOARD_InitPeripherals)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2FPort%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EPort_Init(%26amp%3BPort_Config_BOARD_InitPeripherals)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2FInterrupts%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E(IntCtrl_Ip_Init(%26amp%3BIntCtrlConfig_0)%20%3D%3D%20%3C%2FSPAN%3E%3CSPAN%3EINTCTRL_IP_STATUS_ERROR%3C%2FSPAN%3E%3CSPAN%3E)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%3CSPAN%3E%20false%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2FDMA%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ERm_Init(%26amp%3BRm_Config_BOARD_INITPERIPHERALS)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EMcl_Init(%26amp%3BMcl_Config_BOARD_InitPeripherals)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3E%2F%2FLPSPI1%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ELpspi_Ip_StatusType%3C%2FSPAN%3E%3CSPAN%3E%20lpspi_status%20%3D%20Lpspi_Ip_Init(%26amp%3BLpspi_Ip_PhyUnitConfig_SpiPhyUnit_1_Instance_1_BOARD_InitPeripherals)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E(lpspi_status%3D%3D%3C%2FSPAN%3E%3CSPAN%3ELPSPI_IP_STATUS_SUCCESS%3C%2FSPAN%3E%3CSPAN%3E)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ELpspi_Ip_UpdateTransferMode(Lpspi_Ip_DeviceAttributes_SpiExternalDevice_1_Instance_1_BOARD_InitPeripherals.%3C%2FSPAN%3E%3CSPAN%3EInstance%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3ELPSPI_IP_INTERRUPT%3C%2FSPAN%3E%3CSPAN%3E)%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2Ftransfer%3A%20interrupt%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ELpspi_Ip_UpdateLsb(%26amp%3BLpspi_Ip_DeviceAttributes_SpiExternalDevice_1_Instance_1_BOARD_InitPeripherals%2C%200)%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F0%3DMSB%20(big%20endian)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%3CSPAN%3E%20false%3B%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CP%3EFor%20sending%20i%20use%20something%20like%20this%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CP%3E%3CSPAN%3ELpspi_Ip_AsyncTransmit(%26amp%3B%3C%2FSPAN%3E%3CSPAN%3ELpspi_Ip_DeviceAttributes_SpiExternalDevice_1_Instance_1_BOARD_InitPeripherals%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Etx_buffer%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Erx_buffer%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E1%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Elpspi1_callback%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3EThank%20you%20for%20helping!%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ELuis%3C%2FSPAN%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2373201%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K396%20LPSPI%20DMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2373201%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F260015%22%20target%3D%22_blank%22%3E%40Luis1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20based%20on%20the%20information%20provided%2C%20it%20appears%20that%20you%20are%20mixing%20low-level%20drivers%20(IP%20layer)%20with%20high-level%20drivers%20(MCAL).%20This%20approach%20is%20generally%20not%20recommended%2C%20particularly%20if%20your%20implementation%20is%20intended%20to%20be%20AUTOSAR-compliant.%3C%2FP%3E%0A%3CP%3ERegarding%20your%20configuration%2C%20I%20have%20the%20following%20observation%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFor%20LPSPI1%2C%20you%20have%20assigned%20AIPS_PLAT_CLK%20as%20the%20SpiPhyUnitClockRef.%20However%2C%20the%20source%20clock%20for%20this%20is%20AIPS_SLOW_CLK.%20Therefore%2C%20you%20need%20to%20include%20this%20clock%20in%20the%20McuClockReferencePoint%20configuration%20within%20the%20MCU%20driver%20and%20assign%20it%20accordingly%20to%20this%20SPI%20instance.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ERegarding%20your%20code%2C%20as%20mentioned%20earlier%2C%20you%20are%20mixing%20both%20software%20layers%2C%20which%20is%20not%20recommended.%20There%20are%20some%20exceptions%20when%20working%20with%20low-level%20drivers%2C%20as%20certain%20modules%20are%20only%20available%20in%20MCAL%20(for%20example%2C%20the%20RM)%2C%20where%20mixing%20layers%20may%20be%20expected.%3C%2FP%3E%0A%3CP%3EI%20suggest%20reviewing%20the%20following%20thread%2C%20where%20two%20examples%20are%20provided%3A%20one%20using%20the%20IP%20layer%20and%20another%20using%20MCAL.%20This%20will%20help%20you%20understand%20the%20differences%20in%20the%20APIs%20required%20for%20each%20approach.%20Please%20note%20that%20the%20examples%20are%20not%20specifically%20intended%20for%20S32K396%20devices%2C%20but%20they%20can%20still%20serve%20as%20a%20useful%20reference.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FExample-S32K344-SPI-Transmit-amp-Receive-Using-DMA-DS3-5-RTD500%2Fta-p%2F1992224%22%20target%3D%22_blank%22%3EExample%20S32K344%20SPI%20Transmit%20%26amp%3B%20Receive%20Using%20DMA%20DS3.5%20RTD500%3C%2FA%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%2C%20VaneB%3C%2FP%3E%3C%2FLINGO-BODY%3E