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 »

That part is a bit work in progress because there is not yet real handling for the low power settings in the various drivers, anyway I can't disagree on that.

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 »

Hi there.
I have merge SDIO code from development branch (rev.4106). Changes briefly:
1) Added macro function sdcGetCapacity() for usage from userspace code.
2) Added RTC support.
3) File diskio.c moved from fatfs archive to "os/various".
4) Added testhal for F4x platform.
Code tested on testhal suit and on my own project.
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,

Thanks, I can't test it on the F4 yet but I can test it on the F1, I'll post eventual problems here.

Giovanni
chrisjensen
Posts: 10
Joined: Tue Feb 28, 2012 9:53 pm

Re: SDIO port to STM32F4x

Post by chrisjensen »

Great job on porting that driver,

I am trying to get it work on an STM32F4DISCOVERY board, but using SPI3 instead of SPI1. I have deduced that I need to set up the DMA properly, but after checking the documentation for chibiOS, the STM32F4DISCOVERY data sheet, and the STM32F407xx data sheet, as well as the chibiOS forums, and the ST Micro forums, (along with many other google results) I haven't found a clear explanation with how the DMA is configured physically.

I understand there are 2 DMAs, with 16 streams total, but I have no idea what stream is connected to what peripheral. I understand that the function in chibiOS is of this format:

STM32_DMA_STREAM_ID(dma, stream)

Is it even possible to use SPI3 for the SDC driver currently? If so, How would I configure the STM32_DMA_STREAM_ID in the mcuconfig.h file?


I am declaring it as shown below, trying to match up with the STM32_SPI_SPI3_TX_DMA_STREAM:

Code: Select all

/*
 * SDC driver system settings.
 */
#define STM32_SDC_SDIO_DMA_STREAM           STM32_DMA_STREAM_ID(1, 7)
//#define STM32_SDC_SDIO_DMA_STREAM           STM32_DMA_STREAM_ID(2, 3)
#define STM32_SDC_SDIO_DMA_PRIORITY         3
#define STM32_SDC_SDIO_IRQ_PRIORITY         9
#define STM32_SDC_SDIO_UNALIGNED_SUPPORT    TRUE


thanks
Christopher
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,

The SDC driver does not use SPI, you are looking for the MMC_SPI driver I think :-)

The mapping between DMA channels/streams and peripherals can be found in the STM32F4 Reference Manual (not the Datasheet).

Giovanni
Jacon
Posts: 143
Joined: Wed Dec 08, 2010 7:52 am
Has thanked: 50 times
Been thanked: 5 times

Re: SDIO port to STM32F4x

Post by Jacon »

Excessive backslash on end of line 92 in
..\testhal\STM32F4xx\RTC\Makefile ;)
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 »

Thanks. Fixed.
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 am trying to compile the code on the F1 but it fails because several errors, I already fixed some but I am uncertain on how to proceed with the following:

Code: Select all

  /* Wait until DMA channel enabled to be sure that all data transferred.*/
  while (sdcp->dma->stream->CR & STM32_DMA_CR_EN)
    ;

  /* DMA event flags must be manually cleared.*/
  dmaStreamClearInterrupt(sdcp->dma);


The above does not compile because the field names are different in the F1, accessing DMA registers is wrong anyway because it means bypassing the abstraction, register names are different too. The above code should be equivalent to:

Code: Select all

  dmaWaitCompletion(sdcp->dma);


Is there any particular reason for this or I can replace it?

The second problem:

Code: Select all

  /* Wait until interrupt flags to be cleared.*/
  while (((DMA2->LISR) >> (sdcp->dma->ishift)) & STM32_DMA_ISR_TCIF)
    dmaStreamClearInterrupt(sdcp->dma);


This does not compile too, why putting the clear inside that loop? any specific reason? it appears redundant too because the previous "clear", probably could be entirely removed.

Third (minor) problem:

Code: Select all

#if CH_DBG_ENABLE_ASSERTS
  SDIO_TypeDef              *sdio;
#endif


Apparently this is not used anywhere, can it be removed?

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 »

Giovanni wrote:Code: Select all
#if CH_DBG_ENABLE_ASSERTS
SDIO_TypeDef *sdio;
#endif
Apparently this is not used anywhere, can it be removed?

This provide convenient access to SDIO registers via Eclipse debugging tools (Variables) eliminating need of looking in memory.

Giovanni wrote:Code: Select all
/* Wait until DMA channel enabled to be sure that all data transferred.*/
while (sdcp->dma->stream->CR & STM32_DMA_CR_EN)
;

/* DMA event flags must be manually cleared.*/
dmaStreamClearInterrupt(sdcp->dma);
The above does not compile because the field names are different in the F1, accessing DMA registers is wrong anyway because it means bypassing the abstraction, register names are different too. The above code should be equivalent to:

Probably that code have been written before your DMA improvements. I think, it can be replaced.

Giovanni wrote:why putting the clear inside that loop? any specific reason? it appears redundant too because the previous "clear"

There were some DMA quirks in SDIO. If I remember correct, flags does not cleared if this done too quick. That multiple clear needs to be safe.
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 »

Do you have the embsys register plugin for Eclipse installed? it allows to inspect HW registers for many MCUs (not sure if SDIO is included).

https://sourceforge.net/projects/embsysregview/

It is often very useful.

I replaced the code and commented out the part I think it is not necessary, now it compiles on the F1 but testing will have to wait weekend. I still have to update all the halconf.h and mcuconf.h in all the demos (this is the part I hate most...).

Any feedback about this new driver is welcome (all STM32 variants).

Giovanni
Post Reply