[STM32GENERIC] SDIO DMA

Discussions about the STM32generic core
User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Fri Jun 16, 2017 4:47 pm

Still, in about 20% of cases, while opening the card (after reset) I get

Code: Select all

 Opening the SDcard's bmp file..
State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 80000000
R1 value: 0
HAL Return value (HAL_...): 1
C:\Users\pito\MyCode\Arduino\hardware\Arduino_STM32\STM32DE\libraries\SDIO\src\SDIO.cpp
121
begin
### Error opening the SDcard's file..
pointing to

Code: Select all

state = HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B);
That is with basic 168/24MHz.
Pukao Hats Cleaning Services Ltd.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: [STM32GENERIC] SDIO DMA

Post by danieleff » Fri Jun 16, 2017 6:06 pm

I get the same.
It seems to be stuck in:
HAL_SD_Init -> HAL_SD_InitCard -> SD_PowerON -> SDMMC_CmdGoIdleState -> SDMMC_GetCmdError

Basically it sends CMD0, and then timeouts there, waiting for SDIO_FLAG_CMDSENT (The problem is already there in HAL_SD_Init, and not in HAL_SD_ConfigWideBusOperation)

stevestrong
Posts: 1609
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [STM32GENERIC] SDIO DMA

Post by stevestrong » Fri Jun 16, 2017 6:30 pm

I use this line to detect end of command, because also had problems with the CMDEND flag:

Code: Select all

while ( (SDIO->STA&SDIO_STA_CMDACT) ) ; // wait for actual command to be sent
This was working so far in 100% of cases.
Response checking, if needed, comes after this.

BTW, Pito, can you please post here your sketch with BMP writing to card?
I would like to test it on my board using (preliminary) libmaple-based SDIO driver.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: [STM32GENERIC] SDIO DMA

Post by danieleff » Fri Jun 16, 2017 6:49 pm

Yes it seems to be stuck waiting for the command to be sent, so it is not properly initialized.
If you have SdFat, can you just use the bench example?

If I put `HAL_Delay(1);` between `SDIO_PowerState_ON` and `__HAL_SD_ENABLE`, I get way better results (seems to always initialize): https://github.com/danieleff/STM32GENER ... _sd.c#L379

stevestrong
Posts: 1609
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [STM32GENERIC] SDIO DMA

Post by stevestrong » Fri Jun 16, 2017 6:56 pm

danieleff wrote:If you have SdFat, can you just use the bench example?
Bench example uses aligned addresses, and is working so far quite good.
But I would like to test the case Pito had with misaligned address of the passed buffer.

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Fri Jun 16, 2017 7:49 pm

@Steve: If you want a misaligment of a block of data, simply do myFile.write('X') before you start to write the block with myFile.write(block, size).
It writes byte X and the first 511 bytes from the block into the cache and onto the card, then it starts to write the block via DMA from block's address 511 (misaligned). There is now the fix in SDIO.cpp such you will not see an error, it will write without DMA instead. You have to uncomment the while(1) there such it Hangs with misaligned (see above).
I will prepare the Mandelbrot demo soon.

@Daniel: I've done some reading on "sdio problem stm32f407" and found a lot of desperate topics at community.st.com. Frankly, I am quite surprised our SDIO works so well :)
I've seen somewhere in that forum they inserted delay(10) somewhere in init and then before CMD55 and before CMD10, as I can remember. I have to find that discussion again :roll:
Last edited by Pito on Fri Jun 16, 2017 9:38 pm, edited 5 times in total.
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Fri Jun 16, 2017 9:13 pm

danieleff wrote:If I put `HAL_Delay(1);` between `SDIO_PowerState_ON` and `__HAL_SD_ENABLE`, I get way better results (seems to always initialize): https://github.com/danieleff/STM32GENER ... _sd.c#L379
I've increased both to 10ms :) and it seems it works :) Needs more testing..

Code: Select all

  /* Set Power State to ON */
  SDIO_PowerState_ON(hsd->Instance);
  
  HAL_Delay(10U);
  
  /* Enable SDIO Clock */
  __HAL_SD_ENABLE(hsd);
  
  /* Required power up waiting time before starting the SD initialization 
  sequence */
  HAL_Delay(10U);
  
  /* Identify card operating voltage */
  errorstate = SD_PowerON(hsd);
Pukao Hats Cleaning Services Ltd.

stevestrong
Posts: 1609
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [STM32GENERIC] SDIO DMA

Post by stevestrong » Sat Jun 17, 2017 8:03 am

Pito wrote:@Steve: If you want a misaligment of a block of data, simply do myFile.write('X') before you start to write the block with myFile.write(block, size).
It writes byte X and the first 511 bytes from the block into the cache and onto the card, then it starts to write the block via DMA from block's address 511 (misaligned).
Well, I am not sure, but what about ANDing the last 3 bits of the address to 0 and write then with DMA?
The bytes are anyway written into the cache and the cache is supposed to be a mirror of the active block and be anyway aligned.

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Sat Jun 17, 2017 1:05 pm

When you are DMAing the block you read from block's direct ram address - therefore the alignment matters. You do not write via cache when doing DMA.
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Sun Jun 18, 2017 4:43 pm

While working with the Zmodem example, I rarely (2x out of maybe 20 transfers) got following error (168/24MHz, Samsung CL10):

Code: Select all

State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 10
R1 value: 100100000000
HAL Return value (HAL_...): 1
C:\Users\pito\MyCode\Arduino\hardware\Arduino_STM32\STM32DE\libraries\SDIO\src\SDIO.cpp
270
writeBlocks
but the transfer has continued.
Pukao Hats Cleaning Services Ltd.

Post Reply