cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to use SPI emulator (AN4678) on STM32F405

arnaudg
Associate II

Hello,

I'm trying to read some data using the RX mode of the SPI emulator explained in AN4678 but I have a weird bug that I don't know how to fix.

To quickly explain how it works, the SPI emulator uses TIM1 pin to generate a clock and a GPIO pin to behave like a MISO pin. In my case, the STM32 chip is configured as the master (Master Emulation, Slave HW). Using DMA Peripheral to Memory, data is read from the GPIO and stored in a variable at each clock edge of the TIM1 pin. The emulator uses flags to indicate when the transmission is complete.

When I try to read data just once, the data retrieval works fine and the good amount of rising edges are sent. But when I want to use the function several times, it seems that the reading process is not finishing properly and the CLK pin is not sending the right amount of rising edges. I don't know if completely resetting the timer and GPIO clocks might work, because if i "restart" the whole driver from zero it should work like the first time ? I tried briefly but it doesn't seemed to work.

Can anyone give me an advice ?

The application note used is attached.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
arnaudg
Associate II

Quick answer for whose are in the same situation as me.

I used examples from AN4666. I generated a clock signal with TIMx_CHy and used DMA on TIMx to retrieve data on IDR port (using masks). To stop the PWM clock as fast as possible, I set the CCMR register to 0 in the DMA Transfer Complete IRQ Handler.

View solution in original post

3 REPLIES 3
Uwe Bonnes
Principal III

Hello,

 

can you explain why you do not use a real SPI or a bit-banging SPI approach. Otherwise, do you use the same MCU type as in the appnote? Did you check for different behaviour if using anothe MCU type?

Hello, thank you for your answer ! 

 

I do not have access to the SPI pins of the STM chip. I have access to a pin assigned to TIM1 and a GPIO so I thought it would be a good solution to use the emulator presented on the AN.

Also, I need to transfer 64 bytes with a 2 MHz clock, so I don't know if a bit-banging algorithm would be reliable on the chip ?

In the AN, they use the STM32F401RE Nucleo board with a 84 MHz system clock. They also claim that "This example has been tested with STMicroelectronics NUCLEO-F401RE RevC board and can be easily tailored to any other STM32F4 device and development board" so I first tried on the NUCLEO-F411RE board and it seems to have the same behaviour as the STM32F405 : I set the system clock and APB clocks to 84 MHz but it works only the first time. When I try to receive data a second time, it stops before receiving the whole frame as if the timer had not been stopped properly before stopping the first reception (if I want to receive 64 bytes It will receive only 20 or whatever).

I know that the example (and the library in general) is not 100% reliable so I made some little improvements to make it work with Rx only. But, I think that if there is a way to "reset" completely the SPI interface it could solve the problem ? 

(Actually I think that the GPIO and TIM are the main problem because the DMA_SxCR flag to control the Stream seems to disable properly. I don't know why but the disabling is made twice on the SPI driver).

arnaudg
Associate II

Quick answer for whose are in the same situation as me.

I used examples from AN4666. I generated a clock signal with TIMx_CHy and used DMA on TIMx to retrieve data on IDR port (using masks). To stop the PWM clock as fast as possible, I set the CCMR register to 0 in the DMA Transfer Complete IRQ Handler.