SDIO port to STM32F4x

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

The documentation I have is here: http://www.chibios.org/tmp/MMC-SD.7z

I will remove the file tomorrow so please get it now.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: SDIO port to STM32F4x

Post by barthess »

Done.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: SDIO port to STM32F4x

Post by barthess »

Observe strange behavior. DMA drops last 12 bytes from transaction when functioning without fifo. With fifo it works fine. FAT32 driver successfully mounts volume and reads file tree.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

Hi,

There are two articles regarding SDIO on this blog: http://blog.frankvh.com/

He also noticed an undocumented behavior, is this related to your problem?

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

Hi,

I reviewed the changes so far and I wonder how much of those are related to the objective stated at the start of this thread: "port the driver to the F4". Most changes go far beyond that.

Please stick to the original intention because any other change not related to the simple port effort will have to be discussed first. So please:

- Don't change the API, if it is lacking then discuss the issue first.
- Don't add options and features, if something is missing discuss the issue first.
- Stick to a simple implementation shared between F1, F2 and F4. This driver has to simply read and write blocks, increases in size are not acceptable.
- Did support of unaligned operations disappear? it is required.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: SDIO port to STM32F4x

Post by barthess »

Previous driver have a lot of duplicated code and errors. I wonder how it works on F1x at all.
Giovanni wrote:- Don't add options and features, if something is missing discuss the issue first.

added features:
- parser of CSD register
- fields "capacity" and "errors" in driver
- end of transaction now detects by DMA TCIE interrupt, IMHO it is more reliable.
Giovanni wrote:Stick to a simple implementation shared between F1, F2 and F4

There is only one feature related to F2 and F4 - the fifo mode of DMA. I do not know why but last 12 bytes of reading block drops during transaction without fifo. http://blog.frankvh.com/ does not help to understand why.
Giovanni wrote:Did support of unaligned operations disappear?

Yes, because most of modern cards does not support unaligned operations at all. I propose to add software unaligned functions in hi level part.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SDIO port to STM32F4x

Post by Giovanni »

Previous driver have a lot of duplicated code and errors. I wonder how it works on F1x at all.


Do you mind do a list of errors? I am interested in fixing the current driver because I am releasing it in 2.4.0 with those errors.

added features:
1) parser of CSD register
2) fields "capacity" and "errors" in driver
3) end of transaction now detects by DMA TCIE interrupt, IMHO it is more reliable.


1) OK, could be useful.
2) Where is the need to discriminate between errors? I am only interested in a failure condition, the FS does nothing with errors. What does capacity field report?
3) The ST driver does that without TCIE, why should be it more reliable? Consider that the SD could be still working after TCIE, the operation is not necessarily finished internally.

Yes, because most of modern cards does not support unaligned operations at all. I propose to add software unaligned functions in hi level part.


There is a misunderstanding, the cards are not involved in this, the driver MUST be able to work with unaligned buffers because the File System requires it. It can't go in the upper layer because it is an STM32-specific limitation, other chips might be able to work with unaligned buffers. All the platform specific limitations must be hidden in the low level driver.

In general I prefer proceed in this order:
1) Fix defects as first step.
2) Port to the F4 with the minimal required modifications.
3) Eventually new features.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: SDIO port to STM32F4x

Post by barthess »

Error handling will be useful:
- in case of USB mass storage
- if I do not want to use FS at all

Giovanni wrote:Do you mind do a list of errors? I am interested in fixing the current driver because I am releasing it in 2.4.0 with those errors.

My fault, I just fixed them and forget.
- wrong saving of response data in function sdc_lld_send_cmd_long_crc().
- DTEN bit in DCTRL register must be set in very end of data transfer preparation.
- default timeout is too short for write operations. I have realized separate timeouts for write and read.

Giovanni wrote:What does capacity field report?

It reports the capacity of card in 512B blocks. Used to prevent "overflows".

Giovanni wrote:The ST driver does that without TCIE, why should be it more reliable?

I my case using of DATAEND interrupt cause false starts. My be I do something too wrong.

Giovanni wrote:the driver MUST be able to work with unaligned buffers because the File System requires it

I really misunderstand that. But writing data in that manner will be painfully slow. Is there any workaround in FS driver? May be it is possible to do inside DMA?

Also, I would prefer to reduce code duplication. Separate functions to single and multiple block transactions looks redundant. Read and write functions contain duplicated code too. It will reduce both source and ROM size.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: SDIO port to STM32F4x

Post by barthess »

After some experiments I have identify:
1) DMA fifo usage is mandatory on F4x (may be on F2x too). SDIO just stops to generate DMA requests when SDIO FIFO contains 3 last words. It is true unrelated to DMA_CR_PFCTRL bit. Also RM0090.pdf contain small example that strongly recommend to use DMA fifo.
2) DMA event flags must be cleared manually before any data transaction even if interrupts from DMA disabled.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: SDIO port to STM32F4x

Post by barthess »

I have tested driver with FatFs:
- create 7z archive on SD card with my PC
- create copy of that archive with MCU
- check the copy with PC
Success.
Post Reply