spiPolledExchange difference STM32F4xx, STM32F7xx Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
mikeprotts
Posts: 5
Joined: Wed Jan 09, 2019 12:37 pm
Been thanked: 1 time

spiPolledExchange difference STM32F4xx, STM32F7xx  Topic is solved

Postby mikeprotts » Wed Jan 09, 2019 1:10 pm

Hi,

I'm using spiPolledExchange to read data from an external ADC, one 16 bit sample at a time. The conversion is triggered using PWM (@109375 sps) and then I collect the result once I detect BUSY has cleared. I use SPI1 with PB3/4/5 pins.

I have this working using STM32F4 (tested with STM32F407-DISC board, Olimex STM32-E407 and NUCLEO-F429ZG). I originally developed this using ChibiOS 3.0.4, but have now upgraded to 18.2.1, and this works quite well.

I have also attempted to port this to STM32F7 (testing with NUCLEO-F746ZG and NUCLEO-F767ZI), but the data always comes back as zeros. This is the same code and hardware attached to the board as I used with the STM32F429 processor, so it's not a hardware problem. There is minimal code change to support the STM32F7 processor, mainly the config has flags SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2 | SPI_CR2_DS_3
instead of SPI_CR1_DFF (as it's using the SPIv2 code rather than SPIv1).

I traced the lines, and the difference I see is that the SPI clock is always driving the pin (from spiStart to spiStop), whereas with the F4 processors, the SPI clock starts and stops driving the pin as I issue the spiPolledExchange call. This means that in the F7 case, the read is triggered by hardware (the clock pin) before I try to read the data, so when I attempt to read, I just get the zero values (as there is no more data at this stage).

I assume it's a change between the SPIv1 and SPIv2 code, but I've not worked out what the difference is yet, and I don't know if the F4 (clock driving pin when needed) or the F7 (clock always driving pin) method is the one expected. I'd assumed it was the F4 method - which helps as it keeps the crosstalk down while the ADC reads the values.

I'll probably change to circular mode, once I understand my current issue, but I wanted to understand why there is this difference first.

Any help much appreciated.
Mike

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

Re: spiPolledExchange difference STM32F4xx, STM32F7xx

Postby Giovanni » Wed Jan 09, 2019 1:34 pm

Hi,

The behavior of the function should be the same at API level, it is possible there is a bug.

Moving this topic in "bug reports". Please comment if you find the reason.

Giovanni

mikeprotts
Posts: 5
Joined: Wed Jan 09, 2019 12:37 pm
Been thanked: 1 time

Re: spiPolledExchange difference STM32F4xx, STM32F7xx

Postby mikeprotts » Wed Jan 09, 2019 2:47 pm

A bit more detail. I'm using gcc and openocd with Linux building with make:

arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]

Open On-Chip Debugger 0.10.0+dev-00586-g42f1cc57 (2018-12-15-17:20)

ChibiOS 18.2.1 with fix for bug #957 updating ChibiOS_18.2.1/os/hal/ports/STM32/LLD/TIMv1/hal_gpt_lld.c

I'll try to test with the testhal code (ChibiOS_18.2.1/testhal/STM32/STM32F7xx/SPI), but I've not got that working yet (on the NUCLEO boards I have available).

Thanks
Mike

Edit:
Attachment added showing F4 (Red) and F7 (Blue) SPI CK lines. The clock frequency is the same, but one is continuously firing, the other only when transferring.
Attachments
Screenshot from 2019-01-09 14-04-53.png

mikeprotts
Posts: 5
Joined: Wed Jan 09, 2019 12:37 pm
Been thanked: 1 time

Re: spiPolledExchange difference STM32F4xx, STM32F7xx

Postby mikeprotts » Wed Jan 09, 2019 4:12 pm

I'm checking my code again. With the F7 code it starts driving the SPI SCK pin within spiStart, but that may be a config issue. It's likely I'd misconfigured the CR1 and CR2 setting flags, so I'm checking those.

Cheers
Mike

mikeprotts
Posts: 5
Joined: Wed Jan 09, 2019 12:37 pm
Been thanked: 1 time

Re: spiPolledExchange difference STM32F4xx, STM32F7xx

Postby mikeprotts » Wed Jan 09, 2019 4:23 pm

It was user error.

I'd changed the flags (as mentioned above), but I'd used them in the wrong fields in SPIConfig, so not surprising it wasn't working as expected.

Please close this as user error - and thanks for your help.

Mike

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

Re: spiPolledExchange difference STM32F4xx, STM32F7xx

Postby Giovanni » Wed Jan 09, 2019 4:28 pm

No problems, thanks for confirming.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest