AnsweredAssumed Answered

Problem using DMA to transfer arrays of 264 bytes via SPI MCU MKW01Z128

Question asked by JOSEP LLUIS MORALES on Dec 3, 2015

Hi!

 

- Im programming the DMA to transfer a bunch of bytes (264 bytes) from memory to SPI and from SPI to memory

- The intended use is to test the  Read and Write the at45db081 flash memory pages

 

To perform a Write Page I use the following code structure:

1-. Send the 4 bytes command via SPI without using the DMA (for code simplicity)

2-. Programming the DMA0 and DMAMUX0 to read from memory array and transfer the contents to the SPI

3-. Launch the DMA0 request4-. Once the transfer has been finished, (the DMA0_BCR counter reaches 0) the DMA0 interrupt occurs and there is performed a reset of the DMA0 channel and clearing of the interrupt byte.

 

To perform a Read Page I use the following code structure:

1-. Send the 8 bytes command via SPI without using the DMA (for code simplicity)

2-. Programming the DMA0 and DMAMUX0 to perform 264 dummy writes to the SPI

3-. Programming the DMA1 and DMAMUX1 to perform the read from SPI data to a array

4-. Launch the DMA0 and DMA1 request

5-. Once the transfer has been finished (the DMA1_BCR counter reaches 0) the DMA1 interrupt occurs and there is performed a reset of the DMA0 channel and clearing of the interrupt byte

 

The two Functions performs without any problem separately, meaning (in the first debug sesion I only call the Write, and then, i close the session, and open a second one call only the Read)

(The bytes written and read are valid and they are loaded correctly from and to the array), (I have checked the waveforms on the oscope)

 

The problem arises when I call the two of them from the main (First the Write and then the Read, using a handler to wait until the interrupt of the write has ocurred and then, the read is called, again using a handler to wait for the interrupt indicating the DMA1 has finished the read)

 

I don't know why separately, the two operations perfom well, and when I use them and call them one before the other in main,  furthermore using a handler to not start the following transfer until the first has come to an end, in that case, the data read in the array is all 0.

 

I post the code project for the completion off the issue, I hope anyone can bring come light on that

 

I use:

- Kinetis design studio 3.0

- GDB PEMicro interface debugging

- PEMIcro multilink for debugging/programming

 

Many thanks!

Original Attachment has been moved to: kw01_bootloader_dma_mincode.rar

Outcomes