Page 1 of 1

STM32F767zi: ICM200948 over SPI

Posted: Sun Jun 13, 2021 7:55 pm
by tsm
Hi,

I'm working on a driver for this IMU device on some custom hardware based on the stm32f767zi. There might be something wrong with my configuration as I can't read the device's ID.

This is what I have currently:

relevant parts from board.h

Code: Select all

#define GPIOB_SPI2_NSS               12U
#define GPIOB_SPI2_SCK               13U
#define GPIOB_SPI2_MISO              14U
#define GPIOB_SPI2_MOSI              15U

#define LINE_SPI2_NSS                PAL_LINE(GPIOB, 12U)
#define LINE_SPI2_SCK                PAL_LINE(GPIOB, 13U)
#define LINE_SPI2_MISO              PAL_LINE(GPIOB, 14U)
#define LINE_SPI2_MOSI              PAL_LINE(GPIOB, 15U)

PIN_MODE_OUTPUT(GPIOB_SPI2_NSS) |                \
PIN_MODE_ALTERNATE(GPIOB_SPI2_SCK) |           \
PIN_MODE_ALTERNATE(GPIOB_SPI2_MISO) |          \
PIN_MODE_ALTERNATE(GPIOB_SPI2_MOSI))


PIN_OTYPE_PUSHPULL(GPIOB_SPI2_NSS) |       \
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_SCK) |        \
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_MISO) |       \
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_MOSI))

PIN_OSPEED_HIGH(GPIOB_SPI2_NSS) |          \
PIN_OSPEED_HIGH(GPIOB_SPI2_SCK) |          \
PIN_OSPEED_HIGH(GPIOB_SPI2_MISO) |        \
PIN_OSPEED_HIGH(GPIOB_SPI2_MOSI))

PIN_PUPDR_FLOATING(GPIOB_SPI2_NSS) |      \
PIN_PUPDR_FLOATING(GPIOB_SPI2_SCK) |      \
PIN_PUPDR_FLOATING(GPIOB_SPI2_MISO) |    \
PIN_PUPDR_FLOATING(GPIOB_SPI2_MOSI))

PIN_AFIO_AF(GPIOB_SPI2_NSS, 0U) |       \
PIN_AFIO_AF(GPIOB_SPI2_SCK, 5U) |       \
PIN_AFIO_AF(GPIOB_SPI2_MISO, 5U) |      \
PIN_AFIO_AF(GPIOB_SPI2_MOSI, 5U))




This is the SPI configuration I'm setting:

Code: Select all


static const SPIConfig SPID2_CONFIG = {
    // circular mode
    .circular = false,
    // callback
    .end_cb = nullptr,
    // chip select port
    .ssport = GPIOB,
    // chip select pad number
    .sspad = GPIOB_SPI2_NSS,
    // control register 1
    .cr1 = SPI_CR1_BR_0 | SPI_CR1_CPOL | SPI_CR1_CPHA,
    // control register 2
    .cr2 = SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2
};



Then after calling spiStart I just call spiExchange to read from the proper register where the device ID should be. I'm controlling chip select with spiSelect. I'm not very experience with SPI so I might failing to configure properly the pins?

Thank you

Re: STM32F767zi: ICM200948 over SPI

Posted: Sun Jun 13, 2021 8:35 pm
by Giovanni
Hi,

If you use spiSelect() then NSS should be a normal GPIO output.

Giovanni

Re: STM32F767zi: ICM200948 over SPI

Posted: Sun Jun 13, 2021 9:01 pm
by tsm
Hi Giovanni,

thanks for taking the time.
I'm not sure what you mean. Isn't the configuration I showed for NSS PIN_MODE_OUTPUT(GPIOB_SPI2_NSS) , etc enough to set it as an output GPIO?

Best

Re: STM32F767zi: ICM200948 over SPI

Posted: Mon Jun 14, 2021 7:50 am
by Giovanni
Hi,

I think you should look at signals using a logic analyser, that would help understanding the problem. Do you see anything on those pins?

Giovanni

Re: STM32F767zi: ICM200948 over SPI

Posted: Thu Jun 17, 2021 3:18 pm
by rew
Giovanni's first remark is on target:

The hardware CAN do something with the NSS line, but chibios considers that "not handy to work with", so the driver expects the NSS pin to be GPIO, and when it needs it low, it will simply palClearPad (spicfg->ssport, spicfg->sspad);