STM32F767 SPI interfaced to ICM20948

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

Moderators: barthess, RoccoMarco

prashanth206
Posts: 4
Joined: Sun Dec 09, 2018 7:20 pm

STM32F767 SPI interfaced to ICM20948

Postby prashanth206 » Tue Aug 13, 2019 11:48 am

Hello,
Warm greetings, I have been trying to use the SPI hal driver to interact with ICM20948 interfaced to SPI1 in custom board that i have made.
Following is the SPI configuration which i am using,

Code: Select all

static const SPIConfig spid1_cfg = {
    false,     //circular mode
    NULL,      //complete callback
    SPI_SOCKET_1_CS_PORT,
    SPI_SOCKET_1_CS_PIN,
    SPI_CR1_CPHA | SPI_CR1_CPOL | SPI_CR1_BR_1 | SPI_CR1_MSTR | SPI_CR1_SSM | SPI_CR1_SSI
};


I am trying to use the following,
1. Configure GPIO,

Code: Select all

/*
             * SPI1 I/O pins setup.
             */
             palSetPad(SPI_SOCKET_1_CS_PORT, SPI_SOCKET_1_CS_PIN);
             palSetPadMode(SPI_SOCKET_1_CS_PORT, SPI_SOCKET_1_CS_PIN,
                           PAL_MODE_OUTPUT_PUSHPULL |
                           PAL_STM32_OSPEED_LOWEST);            /*   CS     */

             palSetPadMode(SPI_SOCKET_1_GPIO, SPI_SOCKET_1_SCK,
                           PAL_MODE_ALTERNATE(SPI_SOCKET_1_AF) |
                           PAL_STM32_OSPEED_HIGHEST);            /* SCK.     */

             palSetPadMode(SPI_SOCKET_1_GPIO, SPI_SOCKET_1_MISO,
                           PAL_MODE_ALTERNATE(SPI_SOCKET_1_AF)); /* MISO.    */

             palSetPadMode(SPI_SOCKET_1_GPIO, SPI_SOCKET_1_MOSI,
                           PAL_MODE_ALTERNATE(SPI_SOCKET_1_AF) |
                           PAL_STM32_OSPEED_HIGHEST);            /* MOSI.    */

2. spiStart(SPID, &spid1_cfg);
3. read one byte WHOAMI from the ICM20948

Code: Select all

    /* Slave selection and data send.*/
    spiSelect(SPID);
    spiExchange(SPID, len, (void *)buf_tx, (void *)buf_rx);
    spiUnselect(SPID);


On debugging, I find the call reaches spiStartExchangeI then osalThreadSuspendS suspends and thread is never wokenup, probably by an interrupt.

Kindly let me know what could i be missing or not configured. I had enable debugging and there is no issues there.

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

Re: STM32F767 SPI interfaced to ICM20948

Postby Giovanni » Tue Aug 13, 2019 12:05 pm

Hi,

The thread is woked by the RX DMA interrupt so possible causes:

- Invalid DMA state before operation.
- DMA channel conflict.
- DMA error caused by invalid address.

Pins configuration should not cause this, SPI would function regardless.

If it is a Cortex-M0 then also make sure to use GCC 5.4.1 or below, there is a bug in newer versions.

Try putting a breakpoint in the DMA SPI ISR, that could give an hint, make sure to compiler using -O0 in the makefile.

Giovanni

prashanth206
Posts: 4
Joined: Sun Dec 09, 2018 7:20 pm

Re: STM32F767 SPI interfaced to ICM20948

Postby prashanth206 » Tue Aug 13, 2019 4:04 pm

Hi,
Greetings, I am using the mcuconf as in the stm32f7 demo project

Code: Select all

/*
 * SPI driver system settings.
 */
#define STM32_SPI_USE_SPI1                  TRUE
#define STM32_SPI_USE_SPI2                  TRUE

#define STM32_SPI_SPI1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(2, 0)
#define STM32_SPI_SPI1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(2, 3)


- Invalid DMA state before operation.
Could you please suggest me how it can be checked.

- DMA channel conflict.
Verified DMA stream is configured only for the specific device.

- DMA error caused by invalid address.
The board config is selected properly for STM32F767xx

I was using GCC 7 and now moved to GCC 5.4.1, just to avoid any uncertainties.

As recommended removed any optimization and tried to put break point at SPI DMA RX ISR in hal_lld_spi but interrupt is still not triggered.

Guru Prashanth Sridhar

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

Re: STM32F767 SPI interfaced to ICM20948

Postby Giovanni » Tue Aug 13, 2019 4:11 pm

Are those DMA channels used by some other active driver? that would create a conflict.

Also, make sure to enable checks, assertions and state checker in chconf.h, it halts the system in case of an error detection. After halt look at the stack trace to understand where it was triggered.

Giovanni

prashanth206
Posts: 4
Joined: Sun Dec 09, 2018 7:20 pm

Re: STM32F767 SPI interfaced to ICM20948

Postby prashanth206 » Tue Aug 13, 2019 5:29 pm

Hi,

Greetings, the only other peripheral i have enabled is I2C using DMA.
I had also had enabled checks, assertions and state checker in chconf.h, no system halt due to assert is observed.
When interrupted system is at Idle thread and waits for interrupt.
Do i need to do any configuration of function call specific to DMA? I see that the DMA is managed by SPIV2 in case of stm32f767.

Best regards,
Guru Prashanth Sridhar

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

Re: STM32F767 SPI interfaced to ICM20948

Postby Giovanni » Tue Aug 13, 2019 7:32 pm

Could you try the F7 test application? If it works then it is something specific in your setup else it could be a bug (unlikely).

Giovanni

mikeprotts
Posts: 40
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 3 times
Been thanked: 7 times

Re: STM32F767 SPI interfaced to ICM20948

Postby mikeprotts » Tue Aug 13, 2019 10:22 pm

It's worth double checking the config, I had to set SPI_CR2 for my code when I moved from STM32F407 to STM32F767 code:
SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2 | SPI_CR2_DS_3

What code are you expecting to run from the data received from spiExchange? Should there be a callback?

Have you tried with spiPolledExchange, which I found to be easier to debug. Once everything works that way, swapping to a callback is not too difficult.

Mike

prashanth206
Posts: 4
Joined: Sun Dec 09, 2018 7:20 pm

Re: STM32F767 SPI interfaced to ICM20948

Postby prashanth206 » Thu Aug 15, 2019 11:31 am

Hello,
Greetings, I think i'm running into some serious issues here. I figured this out when trying to run the SPI test application for my board.

I had designed the custom hardware with STM32F767VIT6 with 100 pin package, its different from the general STM32F767xx and more similar to STM32F765xx.

As descibed in secction STM32F765xx, STM32F767xx, STM32F768Ax and STM32F769xx features and peripheral counts in document below.

https://www.st.com/resource/en/datasheet/stm32f767vi.pdf

Could you let me know if it still should work? or suggest me a solution or workaround.
I find no specific option for this in stm32_registry.h

Best regards,
Guru Prashanth Sridhar

mikeprotts
Posts: 40
Joined: Wed Jan 09, 2019 12:37 pm
Has thanked: 3 times
Been thanked: 7 times

Re: STM32F767 SPI interfaced to ICM20948

Postby mikeprotts » Thu Aug 15, 2019 3:25 pm

I've used the STM32F767ZIT6 144 pin chip on the Nucleo-144 board and the STM32F767VIT6 100 pin chip on a custom board. There's no special code for any difference other than the board files (in os/hal/boards/XXX).

I've disabled a lot of pins as I'm not using USB or SD card. I use Ethernet for comms (LAN8710A on custom board, LAN8742A on Nucleo). I have serial lines to GPS and Raspberry Pi, and use GPIO from Pi for programming.

Mike


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 4 guests