Trying to Write two SDCards at same time using SPI. MK20DX256VLL10

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

Trying to Write two SDCards at same time using SPI. MK20DX256VLL10

947 Views
Pedro_Henrique
Contributor II

Hello, this is my first post here, please tell me if im doing something wrong. Also english is not my main language, sorry if i say something wrong.

I'm trying to write two SDCards at same time using SPI. Why at the same time? Because i need to do as fast as possible.

At the time im writing this, im able to copy 48Mb of hex numbers in 07:10 minutes, using 10Mhz in SPI clock. I use the functions generated by Processor Expert:

"SM*_ReceiveBlock(SM*_DeviceData, &Buffer, qnt*).

After gathering some logs with my logic, i noticed that even if i send:

SM2_ReceiveBlock(SM2_DeviceData, &Suporte, 1);
SM2_SendBlock(SM2_DeviceData, StartBlock, 1);
 
SM3_ReceiveBlock(SM3_DeviceData, &Suporte, 1);
SM3_SendBlock(SM3_DeviceData, StartBlock, 1);


The SPI sends first the SM2 and them SM3. If its the SPI machine who sends the blocks and handle the receiving, i should be able to make these two at same time, no?

Labels (1)
0 Kudos
Reply
5 Replies

862 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Pedro_Henrique,
Sorry for the late reply, in order to support you better, could you please provide me the next information?

-Which IDE are you using to develop your application?
-Are you currently using a custom board? If the response is not, which FDRM are you using?
- How are you connecting the SD cards with your system?
- Which specific pins are assigned to the SPI interfaces in your design?

BR
Habib

800 Views
Pedro_Henrique
Contributor II

Hello @Habib_MS ,
No problem for the later reply! Thanks for stopping by to help me.

- I'm currently using Kinetis Design Studio 3.0.0 with Processor Expert.
- Yes, it is a custom board.
- I'm using MicroSD Sockets, with 200R resistor in series so i don't fry my MK20 by accident.
- About the pins:
for SPI0: MISO - PTC7 / MOSI - PTC6 / CLK - PTC5 / CS - PTC4
for SPI1: MISO - PTB23/ MOSI - PTB22 / CLK - PTB21 / CS - PTB20
for SPI2: MISO - PTE3 / MOSI - PTE1    / CLK - PTE2   / CS - PTE0

Please let me know if you need something more.

0 Kudos
Reply

729 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Pedro_Henrique,

In order to understand better you application, Is SM2_SendBlock blocking?
If the answer is yes, then to allow transfers to occur simultaneously, they must be handled through interrupts; otherwise, the core will execute the transfers sequentially, one after the other. Additionally, DMA can be added for higher speed.

BR
Habib

0 Kudos
Reply

402 Views
Pedro_Henrique
Contributor II

Sorry about the late reply.

Yes, both SM2_SendBlock and SM3_SendBlock are blocking.

Handling trought interrupts you say any interrupt? Like, calling them from a external interrupt?

About DMA, i was looking for this. I think i will try to add DMA, but first i would need executing the transfers simultaneously.

0 Kudos
Reply

321 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Pedro_Henrique,
You need to configure the SPI to use interrupts instead of blocking writes. This approach allows both data transfers to occur simultaneously.
You can achieve this using Processor Expert, and this community post might be helpful as a reference.
Additionally, you can review this guide, which demonstrates a typical use case for SPI interrupts. Although the example is not specifically for the K20, the implementation steps are essentially the same.

BR
Habib

%3CLINGO-SUB%20id%3D%22lingo-sub-2205217%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ETrying%20to%20Write%20two%20SDCards%20at%20same%20time%20using%20SPI.%20MK20DX256VLL10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2205217%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%20this%20is%20my%20first%20post%20here%2C%20please%20tell%20me%20if%20im%20doing%20something%20wrong.%20Also%20english%20is%20not%20my%20main%20language%2C%20sorry%20if%20i%20say%20something%20wrong.%3CBR%20%2F%3E%3CBR%20%2F%3EI'm%20trying%20to%20write%20two%20SDCards%20at%20same%20time%20using%20SPI.%20Why%20at%20the%20same%20time%3F%20Because%20i%20need%20to%20do%20as%20fast%20as%20possible.%3CBR%20%2F%3E%3CBR%20%2F%3EAt%20the%20time%20im%20writing%20this%2C%20im%20able%20to%20copy%2048Mb%20of%20hex%20numbers%20in%2007%3A10%20minutes%2C%20using%2010Mhz%20in%20SPI%20clock.%20I%20use%20the%20functions%20generated%20by%20Processor%20Expert%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%22SM*_ReceiveBlock(SM*_DeviceData%2C%20%26amp%3BBuffer%2C%20qnt*).%3CBR%20%2F%3E%3CBR%20%2F%3EAfter%20gathering%20some%20logs%20with%20my%20logic%2C%20i%20noticed%20that%20even%20if%20i%20send%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%3E%3CSPAN%3ESM2_ReceiveBlock(SM2_DeviceData%2C%20%26amp%3BSuporte%2C%201)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ESM2_SendBlock(SM2_DeviceData%2C%20StartBlock%2C%201)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ESM3_ReceiveBlock(SM3_DeviceData%2C%20%26amp%3BSuporte%2C%201)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ESM3_SendBlock(SM3_DeviceData%2C%20StartBlock%2C%201)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CP%3E%3CBR%20%2F%3EThe%20SPI%20sends%20first%20the%20SM2%20and%20them%20SM3.%20If%20its%20the%20SPI%20machine%20who%20sends%20the%20blocks%20and%20handle%20the%20receiving%2C%20i%20should%20be%20able%20to%20make%20these%20two%20at%20same%20time%2C%20no%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2205217%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EKinetis%20M%20Series%20MCUs%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2251364%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Trying%20to%20Write%20two%20SDCards%20at%20same%20time%20using%20SPI.%20MK20DX256VLL10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2251364%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256911%22%20target%3D%22_blank%22%3E%40Pedro_Henrique%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EIn%20order%20to%20understand%20better%20you%20application%2C%20Is%20SM2_SendBlock%20blocking%3F%3CBR%20%2F%3EIf%20the%20answer%20is%20yes%2C%20then%20to%20allow%20transfers%20to%20occur%20simultaneously%2C%20they%20must%20be%20handled%20through%20interrupts%3B%20otherwise%2C%20the%20core%20will%20execute%20the%20transfers%20sequentially%2C%20one%20after%20the%20other.%20Additionally%2C%20DMA%20can%20be%20added%20for%20higher%20speed.%3C%2FP%3E%0A%3CP%3EBR%3CBR%20%2F%3EHabib%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2258122%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Trying%20to%20Write%20two%20SDCards%20at%20same%20time%20using%20SPI.%20MK20DX256VLL10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2258122%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ESorry%20about%20the%20late%20reply.%3CBR%20%2F%3E%3CBR%20%2F%3EYes%2C%20both%26nbsp%3B%3CSPAN%3ESM2_SendBlock%20and%26nbsp%3BSM3_SendBlock%20are%20blocking.%3CBR%20%2F%3E%3CBR%20%2F%3EHandling%20trought%20interrupts%20you%20say%20any%20interrupt%3F%20Like%2C%20calling%20them%20from%20a%20external%20interrupt%3F%3CBR%20%2F%3E%3CBR%20%2F%3EAbout%20DMA%2C%20i%20was%20looking%20for%20this.%20I%20think%20i%20will%20try%20to%20add%20DMA%2C%20but%20first%20i%20would%20need%20executing%20the%20transfers%20simultaneously.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2260393%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Trying%20to%20Write%20two%20SDCards%20at%20same%20time%20using%20SPI.%20MK20DX256VLL10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2260393%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256911%22%20target%3D%22_blank%22%3E%40Pedro_Henrique%3C%2FA%3E%2C%3CBR%20%2F%3EYou%20need%20to%20configure%20the%20SPI%20to%20use%20interrupts%20instead%20of%20blocking%20writes.%20This%20approach%20allows%20both%20data%20transfers%20to%20occur%20simultaneously.%3CBR%20%2F%3EYou%20can%20achieve%20this%20using%20Processor%20Expert%2C%20and%20this%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FProcessor-Expert-Software%2FMC9S12A64-SPI-interrupt-Processor-Expert%2Fm-p%2F211784%22%20target%3D%22_self%22%3Ecommunity%20post%3C%2FA%3E%20might%20be%20helpful%20as%20a%20reference.%3CBR%20%2F%3EAdditionally%2C%20you%20can%20review%20this%20%3CA%20href%3D%22https%3A%2F%2Fmcuxpresso.nxp.com%2Fapi_doc%2Fdev%2F116%2Fgroup__spi.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eguide%3C%2FA%3E%2C%20which%20demonstrates%20a%20typical%20use%20case%20for%20SPI%20interrupts.%20Although%20the%20example%20is%20not%20specifically%20for%20the%20K20%2C%20the%20implementation%20steps%20are%20essentially%20the%20same.%3C%2FP%3E%0A%3CP%3EBR%3CBR%20%2F%3EHabib%3C%2FP%3E%3C%2FLINGO-BODY%3E