Page 1 of 1

SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 10:48 am
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?

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 11:23 am
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

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 11:30 am
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.

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 1:51 pm
by Giovanni
I don't know how, step into and verify. Also verify alignment if you are using 16bits SPI frames.

Giovanni

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 3:31 pm
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.

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 4:08 pm
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

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 4:15 pm
by Laurent
I don't think so, I'm using the default linker script of ChibiOS.

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Tue Feb 04, 2014 4:28 pm
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

Re: SPI/DMA error (STM32_SPI_DMA_ERROR_HOOK)

Posted: Wed Feb 05, 2014 8:44 am
by Laurent
Are you calling spiSend() from thread context?

Nop.

are debug options enabled in chconf.h?

Yes, all debug options are enabled.