LPSPI EDMA driver is broken for multiple slaves in SDK 2.16.100 - 25.1 2.00 for IMXRT1171

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

LPSPI EDMA driver is broken for multiple slaves in SDK 2.16.100 - 25.1 2.00 for IMXRT1171

341 Views
nxp16
Contributor III

On the IMXRT1171, when trying to use multiple slaves with LPSPI EDMA, the SDK doesn't work correctly.  The wrong callback is called and the wrong user data is passed.

This is due to a bug in LPSPI_MasterTransferCreateHandleEDMA, where it uses internal static state (s_lpspiMasterEdmaPrivateHandle[]) to keep track of the lpspi_master_edma_handle but only includes one per SPI bus instance.  If you have multiple slaves with separate lpspi_master_edma_handles, callbacks, and PCSes on the same SPI bus, that state will end up being overwritten with the last one you configure, causing all receive/send completions to call the incorrect callback.

0 Kudos
Reply
1 Reply

255 Views
mayliu1
NXP Employee
NXP Employee

Hi @nxp16 ,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.

Thanks for your question.

For applications that use one LPSPI master with more than one SPI slave, this can be handled at the application level.

The LPSPI EDMA handle itself does not store any slave‑specific information.   Each time a transfer is started, the handle is updated with the configuration of the current transfer. Therefore, each transaction is independent.

You can record which slave (PCS) you want to communicate with before start a transfer,  Then, in the common callback, use this record to know which slave’s transfer has finished.

With this method, you can support multiple slaves without changing the driver.

Wish it helps you

Best Regards

MayLiu

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2332702%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELPSPI%20EDMA%20driver%20is%20broken%20for%20multiple%20slaves%20in%20SDK%202.16.100%20-%2025.1%202.00%20for%20IMXRT1171%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2332702%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EOn%20the%20IMXRT1171%2C%20when%20trying%20to%20use%20multiple%20slaves%20with%20LPSPI%20EDMA%2C%20the%20SDK%20doesn't%20work%20correctly.%26nbsp%3B%20The%20wrong%20callback%20is%20called%20and%20the%20wrong%20user%20data%20is%20passed.%3C%2FP%3E%3CP%3EThis%20is%20due%20to%20a%20bug%20in%20LPSPI_MasterTransferCreateHandleEDMA%2C%20where%20it%20uses%20internal%20static%20state%20(s_lpspiMasterEdmaPrivateHandle%5B%5D)%20to%20keep%20track%20of%20the%20lpspi_master_edma_handle%20but%20only%20includes%20one%20per%20SPI%20bus%20instance.%26nbsp%3B%20If%20you%20have%20multiple%20slaves%20with%20separate%20lpspi_master_edma_handles%2C%20callbacks%2C%20and%20PCSes%20on%20the%20same%20SPI%20bus%2C%20that%20state%20will%20end%20up%20being%20overwritten%20with%20the%20last%20one%20you%20configure%2C%20causing%20all%20receive%2Fsend%20completions%20to%20call%20the%20incorrect%20callback.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2333862%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20LPSPI%20EDMA%20driver%20is%20broken%20for%20multiple%20slaves%20in%20SDK%202.16.100%20-%2025.1%202.00%20for%20IMXRT1171%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2333862%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%2F70127%22%20target%3D%22_blank%22%3E%40nxp16%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20your%20interest%20in%20NXP%20Semiconductor%20products%20and%20for%20the%20opportunity%20to%20serve%20you.%3C%2FP%3E%0A%3CDIV%3E%0A%3CP%3EThanks%20for%20your%20question.%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%0A%3CP%3EFor%20applications%20that%20use%20one%20LPSPI%20master%20with%20more%20than%20one%20SPI%20slave%2C%20this%20can%20be%20handled%20at%20the%20application%20level.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20LPSPI%20EDMA%20handle%20itself%20does%20not%20store%20any%20slave%E2%80%91specific%20information.%26nbsp%3B%20%26nbsp%3BEach%20time%20a%20transfer%20is%20started%2C%20the%20handle%20is%20updated%20with%20the%20configuration%20of%20the%20current%20transfer.%20Therefore%2C%20each%20transaction%20is%20independent.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20%3C%2FSPAN%3Erecord%20which%20slave%20(PCS)%20you%20want%20to%20%3CSPAN%3Ecommunicate%20%3C%2FSPAN%3Ewith%20before%20start%20a%20transfer%2C%26nbsp%3B%20Then%2C%20in%20the%20common%20callback%2C%20use%20this%20record%20to%20know%20which%20slave%E2%80%99s%20transfer%20has%20finished.%3C%2FP%3E%0A%3CP%3EWith%20this%20method%2C%20you%20can%20support%20multiple%20slaves%20without%20changing%20the%20driver.%3C%2FP%3E%0A%3CP%3EWish%20it%20helps%20you%3C%2FP%3E%0A%3CP%3EBest%20Regards%3C%2FP%3E%0A%3CP%3EMayLiu%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E