Page 6 of 8

Re: SDIO port to STM32F4x

Posted: Tue Apr 17, 2012 6:02 pm
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

Re: SDIO port to STM32F4x

Posted: Tue Apr 17, 2012 7:15 pm
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.

Re: SDIO port to STM32F4x

Posted: Tue Apr 17, 2012 8:03 pm
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

Re: SDIO port to STM32F4x

Posted: Tue Apr 17, 2012 8:25 pm
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

Re: SDIO port to STM32F4x

Posted: Tue Apr 17, 2012 8:38 pm
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

Re: SDIO port to STM32F4x

Posted: Wed Apr 18, 2012 3:07 pm
by Jacon
Excessive backslash on end of line 92 in
..\testhal\STM32F4xx\RTC\Makefile ;)

Re: SDIO port to STM32F4x

Posted: Wed Apr 18, 2012 5:23 pm
by barthess
Thanks. Fixed.

Re: SDIO port to STM32F4x

Posted: Wed Apr 18, 2012 6:06 pm
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

Re: SDIO port to STM32F4x

Posted: Wed Apr 18, 2012 7:37 pm
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.

Re: SDIO port to STM32F4x

Posted: Wed Apr 18, 2012 7:44 pm
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