SDMMC2 on STM32F7 Discovery Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
dflogeras
Posts: 134
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 1 time
Been thanked: 2 times

SDMMC2 on STM32F7 Discovery  Topic is solved

Postby dflogeras » Wed Jan 17, 2018 8:44 pm

Hi,

I've got a STM32F769I Discovery board here, and wanted to get the SDCard going.

I'm using ChibiOS_17.6.3

I've started with the RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB demo, and deleted any of the LWIP/http related stuff. I just figured it shares the most in common with my board. I then switched to use the STM32F769 board file and linker script.

The first thing I noted is that on this board, the MicroSD connector is electrically connected to SDMMC2.

I augmented mcuconf.h to the following:

Code: Select all

#define STM32_SDC_USE_SDMMC1                FALSE
#define STM32_SDC_USE_SDMMC1                TRUE
....
#define STM32_SDC_SDMMC2_DMA_STREAM         STM32_DMA_STREAM_ID(2, 5) // I also tried STREAM_ID(2, 0)
#define STM32_SDC_SDMMC2_DMA_PRIORITY       3
#define STM32_SDC_SDMMC2_IRQ_PRIORITY       9


This also required making a change in the fatfs_bindings, since by default it is hardcoded to only use SDCD1. I just made a copy, changed from SDCD1->SDCD2 and pointed my project at that.

Finally, in order to link, I had to add to os/hal/ports/STM32/STM32F7xx/stm32_rcc.h

Code: Select all

#define rccEnableSDMMC2(lp) rccEnableAPB2(RCC_APB2ENR_SDMMC2EN, lp)


When I step into sdcConnect(), it gets to the point where it "Switches to high speed.". At that point it gets stuck waiting for DMA with the following backtrace:

Code: Select all

#0  0x0020ccd4 in sdc_lld_wait_transaction_end.lto_priv.263 (sdcp=0x20000c08 <SD
CD2>, n=1, resp=0x200006c4) at ../os/hal/ports/STM32/LLD/SDMMCv1/hal_sdc_lld.c:2
63
#1  0x0020aaf8 in sdc_lld_read_special (sdcp=0x20000c08 <SDCD2>, buf=0x200006d8
"UUUU\354\006", bytes=64, cmd=6 '\006', arg=0) at ../os/hal/ports/STM32/LLD/SDMM
Cv1/hal_sdc_lld.c:761
#2  0x0020fa70 in sdc_detect_bus_clk (sdcp=0x20000c08 <SDCD2>, clk=0x2000076f) a
t ../os/hal/src/hal_sdc.c:334
#3  0x0020fb88 in detect_bus_clk (sdcp=0x20000c08 <SDCD2>, clk=0x2000076f) at ..
/os/hal/src/hal_sdc.c:411
#4  0x0020fe3c in sdcConnect (sdcp=0x20000c08 <SDCD2>) at ../os/hal/src/hal_sdc.
c:680
#5  0x002011ec in InsertHandler.lto_priv.474 (id=0) at main.c:192
#6  0x0021357c in chEvtDispatch (handlers=0x80173b4 <evhndl.9927.lto_priv>, even
ts=0) at ../os/rt/src/chevents.c:358
#7  0x002013ca in main () at main.c:317


I'm guessing I'm blazing a new trail here, but am at my limit as far as I can go without help.

User avatar
Giovanni
Site Admin
Posts: 10571
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 267 times
Been thanked: 228 times
Contact:

Re: SDMMC2 on STM32F7 Discovery

Postby Giovanni » Wed Jan 17, 2018 11:03 pm

Hi,

You should verify if SDMMC pins are programmed correctly in board.h. Another possible cause are bad clock settings.

Are assertions enabled in chconf.h? those would detect problems with DMAs.

Giovanni

dflogeras
Posts: 134
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 1 time
Been thanked: 2 times

Re: SDMMC2 on STM32F7 Discovery

Postby dflogeras » Wed Jan 17, 2018 11:34 pm

I forgot to mention, I did make my own copy of the board file as the schematic indicates there are external pull-ups, and in the original board file two of the SD data lines had the internal pull-ups enabled. I set them all the FLOATING.

I didn't realize that the assertions were disabled by default in the demos. I enabled them, but to no avail; the program just sticks at dmaWaitCompletion() and gives no hints with panic/asserts.

User avatar
Giovanni
Site Admin
Posts: 10571
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 267 times
Been thanked: 228 times
Contact:

Re: SDMMC2 on STM32F7 Discovery

Postby Giovanni » Thu Jan 18, 2018 8:46 am

I think it is I/O or clock related, check all alternate functions for SDIO and clock settings.

A logic analyser would greatly help here.

Giovanni

dflogeras
Posts: 134
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 1 time
Been thanked: 2 times

Re: SDMMC2 on STM32F7 Discovery

Postby dflogeras » Thu Jan 18, 2018 3:04 pm

Hey Giovanni,

I double-checked all SDIO pins/AF, comparing the Discovery schematic to the mappings in board.h, all seems correct (with the exception noted that I disabled the internal pull-ups from the default board.h supplied with ChibiOS_17.6.3)

The clock configuration seems OK. There isn't an option to set the SDMMC2 clock source in mcucfg.h, however the reset value of the related clock register sets it to PLL48 which is what I would do anyway. I can verify that PLL48 is 48MHz (25Mhz crystal, PLLM /25, PLLN x432, PLLQ /9 = 48Mhz)

I can scope the CLK pin of the SDCard when it is enabled, and is running @ 400kHz to start. I can see activity on the CMD line and D0 line.

I do have a logic analyser, but the probe clips are just big enough that I can only easily connect to every second pin on the SDCard holder. Before I make a mess soldering breakout leads to it, is there anything to be learned by just watching CLK, CMD, and D0. None of these are adjacent. I'm not sure when the device (if ever) switches to 2-bit or 4-bit mode.

User avatar
Giovanni
Site Admin
Posts: 10571
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 267 times
Been thanked: 228 times
Contact:

Re: SDMMC2 on STM32F7 Discovery

Postby Giovanni » Thu Jan 18, 2018 3:42 pm

Hi,

Are the SDIO signals also available on the connectors? maybe there is nothing to solder.

SDMMC2 settings should be added anyway but I don't think it is affecting you.

Giovanni

dflogeras
Posts: 134
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 1 time
Been thanked: 2 times

Re: SDMMC2 on STM32F7 Discovery

Postby dflogeras » Thu Jan 18, 2018 3:53 pm

Are the SDIO signals also available on the connectors? maybe there is nothing to solder.


Unfortunately not, they only break out the "Arduino" compatible header signals which are all different pins. Also, this device is a BGA so can't tap it at the source either.

It seems to read the device capacity correctly, ie. reads leading up to the first use of DMA look OK. Here's the state of the driver while hung waiting on DMA. The registers/offsets look correct to me (Using DMA2 stream0).

Code: Select all

$30 = {
  vmt = 0x8018798,
  state = 0x3,
  cid = {0xd400a39c, 0x8080c02b, 0x55313647, 0x3534453},
  csd = {0xa404012, 0x76b27f80, 0x5b590000, 0x400e0032},
  capacity = 0x0,
  config = 0x8018aa4,
  cardmode = 0x11,
  errors = 0x0,
  rca = 0x959d0520,
  thread = 0x0,
  dmamode = 0x8a35420,
  dma = 0x80189c8,
  sdmmc = 0x40011c00
}
(gdb) p *sdcp.dma
$31 = {
  stream = 0x40026410,
  ifcr = 0x40026408,
  ishift = 0 '\000',
  selfindex = 8 '\b',
  vector = 56 '8'
}

User avatar
Giovanni
Site Admin
Posts: 10571
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 267 times
Been thanked: 228 times
Contact:

Re: SDMMC2 on STM32F7 Discovery

Postby Giovanni » Thu Jan 18, 2018 3:56 pm

You should look at the DMA stream and see if the transfer is only partially done or not started at all.

Giovanni

dflogeras
Posts: 134
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 1 time
Been thanked: 2 times

Re: SDMMC2 on STM32F7 Discovery

Postby dflogeras » Thu Jan 18, 2018 3:58 pm

It seems to read the device capacity correctly, ie. reads leading up to the first use of DMA look OK


Sorry, I misspoke. If I use GDB's jump command to skip the offending "detect_bus_clk()" call, and continue sdcConnect()'s initialization it seems to read the capacity OK. The final state is:

Code: Select all

$32 = {
  vmt = 0x8018798,
  state = 0x5,
  cid = {0xd400a39c, 0x8080c02b, 0x55313647, 0x3534453},
  csd = {0xa404012, 0x76b27f80, 0x5b590000, 0x400e0032},
  capacity = 0x1dacc00,
  config = 0x8018aa4,
  cardmode = 0x11,
  errors = 0x0,
  rca = 0x959d0520,
  thread = 0x0,
  dmamode = 0x8a35420,
  dma = 0x80189c8,
  sdmmc = 0x40011c00
}


I don't know if that says anything, as I'm just hacking now.

dflogeras
Posts: 134
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 1 time
Been thanked: 2 times

Re: SDMMC2 on STM32F7 Discovery

Postby dflogeras » Thu Jan 18, 2018 3:59 pm

How do I inspect the DMA stream? Just peek into the HW registers for the specific DMA/stream/chan?


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 3 guests