linux - Handle corrupted SPI data using STM32F1 MCU -


i'm developing application custom board stm32f1 mcu needs able recover unexpected data corruption.

the data flow follows: master device (a linux machine) sends request slave parses message , gets ready send reply. master reads reply. exchange fast (@18mhz) , implemented this:

if (::ioctl(_fd, spi_ioc_message(2), &transaction) < 0) {     warn("message not sent");     return false; } 

the delay between these 2 messages ~50us. message length fixed.

on stm side use dma-driven spi driver implemented in way i'm going write below.

i'm using spi2 clocked off apb1@36mhz (hse@24 mhz; ahb@72mhz; apb1@36mhz).

after spi configured read message (fixed length!) issuing dma request on rxneie (cr2->rxdmaen). after message processed answer getting transmitted via dma1 (cr2->txdmaen).

everything works charm until interfere somehow. scenario i'm trying recover unplugging sclk line while transferring.

i'm struggling recover this. i'm going lay out thoughts because i'm not sure bug is.

the dma configured handle fixed length messages. that's why when interfere somehow, dma controller waits until whole message processed , buffer gets shifted. suppose, got 1 third of message when sclk vanished. dma waiting rest 2 thirds. master continues send requests. hence after sclk back, 2/3 of next message placed in buffer. dma interrupt issued remaining trail of last message lost. it's lost sure, can detect using errie flag issue interrupt on ovr flag going set.

i've tried handle interrupt no avail.

the interrupt handler have checks if bsy flag set (the trail getting process spi controller). if it's set kill dma (that starts handle next message) , leave ovr flag. once bsy cleared clear ovr , reset dma reception.

this doesn't much.

another option might use dedicated timer gets reset on rising edge on sclk (an3109 application note inspired solution). way implement dma timeout. if got part of message can generate interrupt on timer overflow if sclk not long time. solution has issues, though.

i know description vague i've tried best , hope greater insight might help.

install interrupt handler on cs line. on rising edge, abort , start on dma if transfer not yet complete. use ssi bit in spi_cr1, set on rising edge, clear on falling edge.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -