i.MX RT1060 API's LPSPI_MasterTransferEDMA does not support 24bit framesize?

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

i.MX RT1060 API's LPSPI_MasterTransferEDMA does not support 24bit framesize?

427 Views
azone
Contributor II

I’m trying to write 24bit frames via DMA with LPSPI. The application is not important but for my example it is to send data from memory to an external DAC. I want to get this working with DMA because I will eventually use a link-list of TCD’s together with PIT to update the DAC continuously w/o CPU overhead. This is a common application with external ADC and DAC. It is also common that 16bit DAC/ADC’s have 24bit frame requirements (top byte is for command, lower bytes for data). I don’t want to use uint8_t data and split the transfer into 3 bytes, I want to use uint32_t data and send with 24bits frame size, the top byte to be ignored.

Now, onto the LPSPI and DMA configuration.

1. The lpspi_master_config_t structure of the imxRT1060 SDK’s API LPSPI_MasterInit function allows me to set bitsPerFrame to 24. This is no problem when doing a standard transfer w/o DMA.

2. However, when using DMA w/ the API's LPSPI_MasterTransferEDMA function, the case for 24-bits frame size is not handled or supported by the eDMA hardware? In LPSPI_MasterTransferEDMALite the DMA transfer width is set in the edma_transfer_config_t struct. Specifically, the srcTransferSize and destTransferSize fields are configured based on the bytesEachRead and bytesLastWrite values, which are derived from the SPI frame size (bytesPerFrame) by….

/* LPSPI_MasterTransferPrepareEDMALite */

uint32_t bytesPerFrame = ((base->TCR & LPSPI_TCR_FRAMESZ_MASK) >> LPSPI_TCR_FRAMESZ_SHIFT) / 8U + 1U;

if (bytesPerFrame <= 4U)
{
	handle->bytesEachWrite = (uint8_t)bytesPerFrame; // for 24bit frames = 3
	handle->bytesEachRead  = (uint8_t)bytesPerFrame; // ....
	handle->bytesLastRead  = (uint8_t)bytesPerFrame; // ....
}
/* now back in LPSPI_MasterTransferEDMALite */

switch (handle->bytesEachRead) //bytes each transfer
{
	case (1U):
	transferConfigRx.srcTransferSize = kEDMA_TransferSize1Bytes;
	transferConfigRx.minorLoopBytes  = 1;
	if (handle->isByteSwap)
	{
		addrOffset = 3;
	}
	break;

	case (2U):
	transferConfigRx.srcTransferSize = kEDMA_TransferSize2Bytes;
	transferConfigRx.minorLoopBytes  = 2;
	if (handle->isByteSwap)
	{
		addrOffset = 2;
	}
	break;

	case (4U):
	transferConfigRx.srcTransferSize = kEDMA_TransferSize4Bytes;
	transferConfigRx.minorLoopBytes  = 4;
	break;

	default:
	transferConfigRx.srcTransferSize = kEDMA_TransferSize1Bytes;
	transferConfigRx.minorLoopBytes  = 1;
	assert(false);
	break;
}

 

We get the default case and an error as the case of 3 bytes is not handled. Does the EDMA hardware support 3-byte transfers? Basically I want to use uint32_t data and frame as 3 bytes and transfer via DMA, ignoring the most significant byte. Is it possible?

0 Kudos
Reply
2 Replies

250 Views
mayliu1
NXP Employee
NXP Employee

Hi @azone ,

Thank you so much for your interest in our products and for using our community.

Please check the following link, it describe that eDMA support transfer sizes of  1, 2, 4, 8, 16, 32, 64 bytes, it does not support 24bit(3 bytes) transfer size.

MCUXpresso SDK API Reference Manual: EDMA: Enhanced Direct Memory Access (eDMA) Controller Driver

mayliu1_0-1768271744223.png

Best Regards

MayLiu

0 Kudos
Reply

235 Views
azone
Contributor II

ok thank you for confirmation, so I don't waste time trying to get it to work! So the only way really is to use make everything uint8_t data and send as three bytes w/ kLPSPI_MasterPcsContinuous. This is ok, as this is how we do it for all other peripherals, but it adds unnecessary overhead in the case of the 16-bit DAC implementation. Thank you. 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2291180%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Ei.MX%20RT1060%20API's%20LPSPI_MasterTransferEDMA%20does%20not%20support%2024bit%20framesize%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2291180%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%E2%80%99m%20trying%20to%20write%2024bit%20frames%20via%20DMA%20with%20LPSPI.%20The%20application%20is%20not%20important%20but%20for%20my%20example%20it%20is%20to%20send%20data%20from%20memory%20to%20an%20external%20DAC.%20I%20want%20to%20get%20this%20working%20with%20DMA%20because%20I%20will%20eventually%20use%20a%20link-list%20of%20TCD%E2%80%99s%20together%20with%20PIT%20to%20update%20the%20DAC%20continuously%20w%2Fo%20CPU%20overhead.%20This%20is%20a%20common%20application%20with%20external%20ADC%20and%20DAC.%20It%20is%20also%20common%20that%2016bit%20DAC%2FADC%E2%80%99s%20have%2024bit%20frame%20requirements%20(top%20byte%20is%20for%20command%2C%20lower%20bytes%20for%20data).%20I%20don%E2%80%99t%20want%20to%20use%20uint8_t%20data%20and%20split%20the%20transfer%20into%203%20bytes%2C%20I%20want%20to%20use%20uint32_t%20data%20and%20send%20with%2024bits%20frame%20size%2C%20the%20top%20byte%20to%20be%20ignored.%3C%2FP%3E%3CP%3ENow%2C%20onto%20the%20LPSPI%20and%20DMA%20configuration.%3C%2FP%3E%3CP%3E1.%20The%20%3CEM%3Elpspi_master_config_t%3C%2FEM%3E%20structure%20of%20the%20imxRT1060%20SDK%E2%80%99s%20API%20%3CFONT%20color%3D%22%23808080%22%3ELPSPI_MasterInit%3C%2FFONT%3E%20function%20allows%20me%20to%20set%20%3CEM%3EbitsPerFrame%20%3C%2FEM%3Eto%2024.%20This%20is%20no%20problem%20when%20doing%20a%20standard%20transfer%20w%2Fo%20DMA.%3C%2FP%3E%3CP%3E2.%20However%2C%20when%20using%20DMA%20w%2F%20the%20API's%20LPSPI_MasterTransferEDMA%20function%2C%20the%20case%20for%2024-bits%20frame%20size%20is%20not%20handled%20or%20supported%20by%20the%20eDMA%20hardware%3F%20In%20LPSPI_MasterTransferEDMALite%20the%20DMA%20transfer%20width%20is%20set%20in%20the%20edma_transfer_config_t%20struct.%20Specifically%2C%20the%26nbsp%3BsrcTransferSize%26nbsp%3Band%26nbsp%3BdestTransferSize%26nbsp%3Bfields%20are%20configured%20based%20on%20the%26nbsp%3BbytesEachRead%26nbsp%3Band%26nbsp%3BbytesLastWrite%26nbsp%3Bvalues%2C%20which%20are%20derived%20from%20the%20SPI%20frame%20size%20(bytesPerFrame)%20by%E2%80%A6.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%2F*%20LPSPI_MasterTransferPrepareEDMALite%20*%2F%0A%0Auint32_t%20bytesPerFrame%20%3D%20((base-%26gt%3BTCR%20%26amp%3B%20LPSPI_TCR_FRAMESZ_MASK)%20%26gt%3B%26gt%3B%20LPSPI_TCR_FRAMESZ_SHIFT)%20%2F%208U%20%2B%201U%3B%0A%0Aif%20(bytesPerFrame%20%26lt%3B%3D%204U)%0A%7B%0A%09handle-%26gt%3BbytesEachWrite%20%3D%20(uint8_t)bytesPerFrame%3B%20%2F%2F%20for%2024bit%20frames%20%3D%203%0A%09handle-%26gt%3BbytesEachRead%20%20%3D%20(uint8_t)bytesPerFrame%3B%20%2F%2F%20....%0A%09handle-%26gt%3BbytesLastRead%20%20%3D%20(uint8_t)bytesPerFrame%3B%20%2F%2F%20....%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%2F*%20now%20back%20in%20LPSPI_MasterTransferEDMALite%20*%2F%0A%0Aswitch%20(handle-%26gt%3BbytesEachRead)%20%2F%2Fbytes%20each%20transfer%0A%7B%0A%09case%20(1U)%3A%0A%09transferConfigRx.srcTransferSize%20%3D%20kEDMA_TransferSize1Bytes%3B%0A%09transferConfigRx.minorLoopBytes%20%20%3D%201%3B%0A%09if%20(handle-%26gt%3BisByteSwap)%0A%09%7B%0A%09%09addrOffset%20%3D%203%3B%0A%09%7D%0A%09break%3B%0A%0A%09case%20(2U)%3A%0A%09transferConfigRx.srcTransferSize%20%3D%20kEDMA_TransferSize2Bytes%3B%0A%09transferConfigRx.minorLoopBytes%20%20%3D%202%3B%0A%09if%20(handle-%26gt%3BisByteSwap)%0A%09%7B%0A%09%09addrOffset%20%3D%202%3B%0A%09%7D%0A%09break%3B%0A%0A%09case%20(4U)%3A%0A%09transferConfigRx.srcTransferSize%20%3D%20kEDMA_TransferSize4Bytes%3B%0A%09transferConfigRx.minorLoopBytes%20%20%3D%204%3B%0A%09break%3B%0A%0A%09default%3A%0A%09transferConfigRx.srcTransferSize%20%3D%20kEDMA_TransferSize1Bytes%3B%0A%09transferConfigRx.minorLoopBytes%20%20%3D%201%3B%0A%09assert(false)%3B%0A%09break%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EWe%20get%20the%20default%20case%20and%20an%20error%20as%20the%20case%20of%203%20bytes%20is%20not%20handled.%20Does%20the%26nbsp%3B%3CSPAN%3EEDMA%20hardware%20support%203-byte%20transfers%3F%20Basically%20I%20want%20to%20use%20uint32_t%20data%20and%20frame%20as%203%20bytes%20and%20transfer%20via%20DMA%2C%20ignoring%20the%20most%20significant%20byte.%20Is%20it%20possible%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2292305%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20i.MX%20RT1060%20API's%20LPSPI_MasterTransferEDMA%20does%20not%20support%2024bit%20framesize%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292305%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Eok%20thank%20you%20for%20confirmation%2C%20so%20I%20don't%20waste%20time%20trying%20to%20get%20it%20to%20work!%20So%20the%20only%20way%20really%20is%20to%20use%20make%20everything%20uint8_t%20data%20and%20send%20as%20three%20bytes%20w%2F%26nbsp%3B%3CSPAN%3EkLPSPI_MasterPcsContinuous.%20This%20is%20ok%2C%20as%20this%20is%20how%20we%20do%20it%20for%20all%20other%20peripherals%2C%20but%20it%20adds%20unnecessary%20overhead%20in%20the%20case%20of%20the%2016-bit%20DAC%20implementation.%20Thank%20you.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2292109%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20i.MX%20RT1060%20API's%20LPSPI_MasterTransferEDMA%20does%20not%20support%2024bit%20framesize%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2292109%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%2F231967%22%20target%3D%22_blank%22%3E%40azone%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3EThank%20you%20so%20much%20for%20your%20interest%20in%20our%20products%20and%20for%20using%20our%20community.%3C%2FP%3E%0A%3CP%3EPlease%20check%20the%20following%20link%2C%20it%20describe%20that%20eDMA%20support%20transfer%20sizes%20of%26nbsp%3B%201%2C%202%2C%204%2C%208%2C%2016%2C%2032%2C%2064%20bytes%2C%20it%20does%20not%20support%2024bit(3%20bytes)%20transfer%20size.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmcuxpresso.nxp.com%2Fapi_doc%2Fdev%2F2207%2Fa00015.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EMCUXpresso%20SDK%20API%20Reference%20Manual%3A%20EDMA%3A%20Enhanced%20Direct%20Memory%20Access%20(eDMA)%20Controller%20Driver%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mayliu1_0-1768271744223.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22mayliu1_0-1768271744223.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F372558i46B4A47729056CDE%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22mayliu1_0-1768271744223.png%22%20alt%3D%22mayliu1_0-1768271744223.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EBest%20Regards%3C%2FP%3E%0A%3CP%3EMayLiu%3C%2FP%3E%3C%2FLINGO-BODY%3E