Skip to main content
Graduate
April 23, 2025
Question

Serial decoder 4b5b

  • April 23, 2025
  • 2 replies
  • 748 views

Hello Dear Community,

I want to capture and decode a bitstream on STM32F746. The bit rate is 60ns/bit. Data is encoded using 4b5b and has a unique code for start of frame and no end of frame.

What I have tried so far, is to configure TIM2 (APB1 timer clock is 108MHz) with a prescalar of 0 and counter 1. Then, each time the interrupt is fired I sample the input data: Briefly, I try to implement an oversampling mechanism. This approach seems not working. I tried to toggle a pin in the same interrupt and the maximum frequency I get is 146.7KHz. Maybe it is not possible to fire a timer interrupt higher than this frequency (NVIC latency...).

How can I acquire my serial data efficiently? What will be the correct approach to implement my solution? I have seen some input capture using Timer/DMA and I am considering theme. Maybe some GPIO-DMA access?

One constraint I have is that the data rate might change from application to an other. Ideally, I would extract the clock from data stream using a PLL, I would do it easily using FPGA but we want to implement it on STM32.

    This topic has been closed for replies.

    2 replies

    Super User
    April 23, 2025

    One way to do this is to set up a timer in IC mode and capture the time between edges and postprocess to interpret 1s and 0s. At 16 MHz bit rate, it may be doable but barely.

    Another way is to do determine the clock rate as above, then set up a new CLK signal (that resets on an edge) to act as SPI_SCK. Feed the data into SPO_MISO and read it as an SPI stream. Works well for any encoding which doesn't have a ton of consecutive 0s or 1s.

     

    In any case, interrupts at every edge in a 16 MHz bitstream isn't at all viable.

    Graduate II
    April 23, 2025

    DMA could be used to timestamp the edges into a longer pattern buffer, and thus decimate the interrupt loading, but long term it's probably not sustainable. Sampling GPIO with TIM+DMA would generate more data to digest.

    An FPGA or CPLD, with enough buffering depth probably still a better choice so the F7 can do more useful work. The TIM's inputs can also be used as a make-shift DMA DRQ.

    Graduate
    April 23, 2025

    do you think it is achievable to sample my data stream (60ns/bit) and treat them fast enough with STM32F7? There is no issue if some samples were lost. I would like to know only the approach to implement such application. Thank you

    Graduate II
    April 23, 2025

    Well it's not our project.. you'll have to invest the effort to prototype and evaluate the efficacy of different approaches.

    Does the F7 need to do anything with the data it receives? Save it to some storage medium? Do something transformative with it?