SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Laurent »

Hi

I'm trying to test a SPI device (a BMA250 accelerometer) on an Olimex STM32-P407 development board. I've connected my SPI wires to the UEXT port of the board; I'm not sure if it is supposed to work but anyway I don't think it is related to my problem.

The problem is that I get a DMA error when I call spiSend: STM32_SPI_DMA_ERROR_HOOK is called by spi_lld_serve_tx_interrupt, apparently because the STM32_DMA_ISR_TEIF flag is set (the debugger shows flags == 0x09).

Here is my SPI code:

Code: Select all

const SPIConfig spiConfig =
{
    0,
    GPIOF,
    GPIOF_SPI3_SS,
    SPI_CR1_BR_2
};

palSetPadMode(GPIOC, GPIOC_SPI3_CLK, PAL_MODE_ALTERNATE(6));
palSetPadMode(GPIOC, GPIOC_SPI3_MISO, PAL_MODE_ALTERNATE(6));
palSetPadMode(GPIOC, GPIOC_SPI3_MOSI, PAL_MODE_ALTERNATE(6));
palSetPadMode(GPIOF, GPIOF_SPI3_SS, PAL_MODE_OUTPUT_PUSHPULL);

spiStart(&SPID3, &spiConfig);

spiSelect(&SPID3);

uint8_t address = 0x00;
spiSend(&SPID3, 1, &address); // <--- error here

uint8_t chipid = 0;
spiReceive(&SPID3, 1, &chipid);


Any idea what could be causing this error?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Giovanni »

Probably you are passing an invalid pointer as data bufer to the spiSend(). A DMA error happens when it hits unmapped memory.

Giovanni
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Laurent »

Thanks for the fast answer.

How could my pointer be invalid? I'm just doing this:

Code: Select all

uint8_t address = 0x00;
spiSend(&SPID3, 1, &address);

(this is my real code, not a simplified version)

I've always done similarly in other projects (using other hardware) and it has always worked fine.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Giovanni »

I don't know how, step into and verify. Also verify alignment if you are using 16bits SPI frames.

Giovanni
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Laurent »

Verify what? :|
I'm using 8-bits frames, so there shouldn't be alignment issues.

Anyway, after trying stupid things I managed to make it work: if I declare the buffer in global scope rather than on the stack, it works. Of course I have no idea why :) This has never been an issue with STM32F40x on other projects.

And thanks for the hint, I would have never thought of trying this without your help.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Giovanni »

Do you have stacks in CCM RAM? if so that could be the problem, that RAM is not accessible by the DMA.

Giovanni
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Laurent »

I don't think so, I'm using the default linker script of ChibiOS.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Giovanni »

The TEIF flag can be asserted in one of the following two conditions, from the RM:

Code: Select all

– A bus error occurs during a DMA read or a write access
– A write access is requested by software on a memory address register in Double
buffer mode whereas the stream is enabled and the current target memory is the
one impacted by the write into the memory address register (refer to
Section 10.3.9: Double buffer mode)


I think only the first one applies. Are you calling spiSend() from thread context? are debug options enabled in chconf.h?

Giovanni
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Post by Laurent »

Are you calling spiSend() from thread context?

Nop.

are debug options enabled in chconf.h?

Yes, all debug options are enabled.
Post Reply