AnsweredAssumed Answered

eMMC and DMA, only sporadic values, mostly 0

Question asked by Alter Ratz on Dec 14, 2015
Im trying to get eMMC+DMA working, however when reading using DMA i get ony 0s (with some sporadic data inbetween).

The values in the FIFO seem to be correct, because I get reasonable values when I read the FIFO register directly while HAL_SD_CheckReadOperation waits for the completion of the operation (which will obviously disturb the transaction, but it shows that there are correct values in the fifo)
This are my DMA settings:

    /* Configure DMA Rx parameters */
    dma_rx_handle.Init.Channel             = 4;
    dma_rx_handle.Init.Direction           = DMA_PERIPH_TO_MEMORY;
    dma_rx_handle.Init.PeriphInc           = DMA_PINC_DISABLE;
    dma_rx_handle.Init.MemInc              = DMA_MINC_ENABLE;
    dma_rx_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    dma_rx_handle.Init.MemDataAlignment    = DMA_MDATAALIGN_WORD;
    dma_rx_handle.Init.Mode                = DMA_PFCTRL;
    dma_rx_handle.Init.Priority            = DMA_PRIORITY_VERY_HIGH;
    dma_rx_handle.Init.FIFOMode            = DMA_FIFOMODE_ENABLE;
    dma_rx_handle.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
    dma_rx_handle.Init.MemBurst            = DMA_MBURST_INC4;
    dma_rx_handle.Init.PeriphBurst         = DMA_PBURST_INC4;

    dma_rx_handle.Instance = DMA2_Stream3;

The debug output:
Dec 14 2015  11:42:34
void init():113
emmc_init start
MMC and GPIO clocks enabled
emmc_msp_init done
CMD0  (GO_IDLE_STATE): SUCCESS
CMD1  (SEND_OP_COND): SUCCESS
CMD1  (SEND_OP_COND): SUCCESS
CMD2  (ALL_SEND_CID): SUCCESS [Prg, rdy:n, swe:n]
CMD3  (SET_REL_ADDR): SUCCESS [Ident, rdy:y, swe:n]
CMD9  (SEND_CSD): SUCCESS
CMD7  (*SEL*_DESEL_CARD): SUCCESS [Stby, rdy:y, swe:n]
CMD8  (SEND_EXT_CSD): SUCCESS [Tran, rdy:y, swe:n]
reading EXT CSD   START ................ DONE
CMD13 (SEND_STATUS): SUCCESS [Tran, rdy:y, swe:n]
CMD6  (SWITCH): SUCCESS [Tran, rdy:n, swe:n]
CMD13 (SEND_STATUS): SUCCESS
SDMMC SEND_STATUS: 0x0
eMMC INIT OK
mmc_init done
void init():120
void init():127
WRITTEN:
2004fbd4:   00 00 00 00 01 01 01 01  02 02 02 02 03 03 03 03   ................
2004fbe4:   04 04 04 04 05 05 05 05  06 06 06 06 07 07 07 07   ................
2004fbf4:   08 08 08 08 09 09 09 09  0a 0a 0a 0a 0b 0b 0b 0b   ................
2004fc04:   0c 0c 0c 0c 0d 0d 0d 0d  0e 0e 0e 0e 0f 0f 0f 0f   ................
2004fc14:   10 10 10 10 11 11 11 11  12 12 12 12 13 13 13 13   ................
2004fc24:   14 14 14 14 15 15 15 15  16 16 16 16 17 17 17 17   ................
2004fc34:   18 18 18 18 19 19 19 19  1a 1a 1a 1a 1b 1b 1b 1b   ................
2004fc44:   1c 1c 1c 1c 1d 1d 1d 1d  1e 1e 1e 1e 1f 1f 1f 1f   ................
2004fc54:   20 20 20 20 21 21 21 21  22 22 22 22 23 23 23 23       !!!!""""####
2004fc64:   24 24 24 24 25 25 25 25  26 26 26 26 27 27 27 27   $$$$%%%%&&&&''''
2004fc74:   28 28 28 28 29 29 29 29  2a 2a 2a 2a 2b 2b 2b 2b   (((())))****++++
2004fc84:   2c 2c 2c 2c 2d 2d 2d 2d  2e 2e 2e 2e 2f 2f 2f 2f   ,,,,----....////
2004fc94:   30 30 30 30 31 31 31 31  32 32 32 32 33 33 33 33   0000111122223333
2004fca4:   34 34 34 34 35 35 35 35  36 36 36 36 37 37 37 37   4444555566667777
2004fcb4:   38 38 38 38 39 39 39 39  3a 3a 3a 3a 3b 3b 3b 3b   88889999::::;;;;
2004fcc4:   3c 3c 3c 3c 3d 3d 3d 3d  3e 3e 3e 3e 3f 3f 3f 3f   <<<<====>>>>????
READ (direct):
2004fbd4:   00 00 00 00 01 01 01 01  02 02 02 02 03 03 03 03   ................
2004fbe4:   04 04 04 04 05 05 05 05  06 06 06 06 07 07 07 07   ................
2004fbf4:   08 08 08 08 09 09 09 09  0a 0a 0a 0a 0b 0b 0b 0b   ................
2004fc04:   0c 0c 0c 0c 0d 0d 0d 0d  0e 0e 0e 0e 0f 0f 0f 0f   ................
2004fc14:   10 10 10 10 11 11 11 11  12 12 12 12 13 13 13 13   ................
2004fc24:   14 14 14 14 15 15 15 15  16 16 16 16 17 17 17 17   ................
2004fc34:   18 18 18 18 19 19 19 19  1a 1a 1a 1a 1b 1b 1b 1b   ................
2004fc44:   1c 1c 1c 1c 1d 1d 1d 1d  1e 1e 1e 1e 1f 1f 1f 1f   ................
2004fc54:   20 20 20 20 21 21 21 21  22 22 22 22 23 23 23 23       !!!!""""####
2004fc64:   24 24 24 24 25 25 25 25  26 26 26 26 27 27 27 27   $$$$%%%%&&&&''''
2004fc74:   28 28 28 28 29 29 29 29  2a 2a 2a 2a 2b 2b 2b 2b   (((())))****++++
2004fc84:   2c 2c 2c 2c 2d 2d 2d 2d  2e 2e 2e 2e 2f 2f 2f 2f   ,,,,----....////
2004fc94:   30 30 30 30 31 31 31 31  32 32 32 32 33 33 33 33   0000111122223333
2004fca4:   34 34 34 34 35 35 35 35  36 36 36 36 37 37 37 37   4444555566667777
2004fcb4:   38 38 38 38 39 39 39 39  3a 3a 3a 3a 3b 3b 3b 3b   88889999::::;;;;
2004fcc4:   3c 3c 3c 3c 3d 3d 3d 3d  3e 3e 3e 3e 3f 3f 3f 3f   <<<<====>>>>????
HAL_SD_ReadBlocks_DMA:890
HAL_DMA_Start_IT: 200016a0, 40012c80, 2004fbd4, 00000100
1024 bytes left
HAL_SD_CheckReadOperation:1134 BEGIN
HAL_DMA_IRQHandler:831 XferCplt
HAL_SD_IRQHandler:1386 XferCplt
HAL_SD_XferCpltCallback:1448
HAL_SD_DMA_RxCpltCallback:1477
HAL_SD_CheckReadOperation:1160 RX DONE
0 bytes left
HAL_SD_CheckReadOperation:1174 RX WAIT
to: 100000000
HAL_SD_CheckReadOperation:1187 END
READ (DMA): 0 (SD OK)
READ (DMA): 0 (SD OK)
2004fbd4:   00 00 00 00 00 00 00 00  00 00 00 00 03 03 03 03   ................
2004fbe4:   04 04 04 04 05 05 05 05  06 06 06 06 07 07 07 07   ................
2004fbf4:   08 08 08 08 09 09 09 09  0a 0a 0a 0a 00 00 00 00   ................
2004fc04:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc14:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc24:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc34:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc44:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc54:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc64:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc74:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc84:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fc94:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fca4:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fcb4:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
2004fcc4:   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00   ................
READ (direct):
2004fbd4:   00 00 00 00 01 01 01 01  02 02 02 02 03 03 03 03   ................
2004fbe4:   04 04 04 04 05 05 05 05  06 06 06 06 07 07 07 07   ................
2004fbf4:   08 08 08 08 09 09 09 09  0a 0a 0a 0a 0b 0b 0b 0b   ................
2004fc04:   0c 0c 0c 0c 0d 0d 0d 0d  0e 0e 0e 0e 0f 0f 0f 0f   ................
2004fc14:   10 10 10 10 11 11 11 11  12 12 12 12 13 13 13 13   ................
2004fc24:   14 14 14 14 15 15 15 15  16 16 16 16 17 17 17 17   ................
2004fc34:   18 18 18 18 19 19 19 19  1a 1a 1a 1a 1b 1b 1b 1b   ................
2004fc44:   1c 1c 1c 1c 1d 1d 1d 1d  1e 1e 1e 1e 1f 1f 1f 1f   ................
2004fc54:   20 20 20 20 21 21 21 21  22 22 22 22 23 23 23 23       !!!!""""####
2004fc64:   24 24 24 24 25 25 25 25  26 26 26 26 27 27 27 27   $$$$%%%%&&&&''''
2004fc74:   28 28 28 28 29 29 29 29  2a 2a 2a 2a 2b 2b 2b 2b   (((())))****++++
2004fc84:   2c 2c 2c 2c 2d 2d 2d 2d  2e 2e 2e 2e 2f 2f 2f 2f   ,,,,----....////
2004fc94:   30 30 30 30 31 31 31 31  32 32 32 32 33 33 33 33   0000111122223333
2004fca4:   34 34 34 34 35 35 35 35  36 36 36 36 37 37 37 37   4444555566667777
2004fcb4:   38 38 38 38 39 39 39 39  3a 3a 3a 3a 3b 3b 3b 3b   88889999::::;;;;
2004fcc4:   3c 3c 3c 3c 3d 3d 3d 3d  3e 3e 3e 3e 3f 3f 3f 3f   <<<<====>>>>????
FINISHED.


Writing works, reading (polling) works, reading (DMA) fails, reading (polling) works again. Each transaction is 2 Blocks (1024 Bytes, not everything is dumped to the debugging port)

As mentioned above, i put a little debugging loop in HAL_SD_CheckReadOperation to print the contents of the DMA FIFO
every few cycles and it counts up correctly. Also capturing the data on the bus using a logic analzer shows that the correct data is received from the eMMC device.

I am running out of ideas, so if anybody can help it would be very appreciated.

I attached my version of the eMMC routines. Additionally I commented out the following lines in HAL_SD_CheckReadOperation

#if 0
    /* Wait until the Rx transfer is no longer active */
    while ((__HAL_SD_SDMMC_GET_FLAG(hsd, SDMMC_FLAG_RXACT)) && (timeout > 0))
    {
        timeout--;
    }
#endif

Additionally i tried filling the buffer with 0xff (instead of 0) before reading and I get the following:

READ (DMA): 0 (SD OK)
2004fbd4:   ff ff ff ff ff ff ff ff  ff ff ff ff 03 03 03 03   ................
2004fbe4:   04 04 04 04 05 05 05 05  06 06 06 06 07 07 07 07   ................
2004fbf4:   08 08 08 08 09 09 09 09  0a 0a 0a 0a 0b 0b 0b 0b   ................
2004fc04:   0c 0c 0c 0c 0d 0d 0d 0d  0e 0e 0e 0e 0f 0f 0f 0f   ................
2004fc14:   10 10 10 10 11 11 11 11  12 12 12 12 ff ff ff ff   ................
2004fc24:   ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff   ................
2004fc34:   ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff   ................
2004fc44:   ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff   ................
2004fc54:   ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff   ................
2004fc64:   ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff   ................
2004fc74:   ff ff ff ff ff ff ff ff  ff ff ff ff 2b 2b 2b 2b   ............++++
2004fc84:   2c 2c 2c 2c 2d 2d 2d 2d  2e 2e 2e 2e 2f 2f 2f 2f   ,,,,----....////
2004fc94:   30 30 30 30 31 31 31 31  32 32 32 32 33 33 33 33   0000111122223333
2004fca4:   34 34 34 34 35 35 35 35  36 36 36 36 37 37 37 37   4444555566667777
2004fcb4:   38 38 38 38 39 39 39 39  3a 3a 3a 3a ff ff ff ff   88889999::::....
2004fcc4:   ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff   ................


Best Regards,
Bernhard

Attachments

Outcomes