Skip to main content
Visitor II
December 20, 2015
Question

Circular buffer

  • December 20, 2015
  • 2 replies
  • 6839 views
Posted on December 20, 2015 at 20:58

Someone knows how to implement a circular buffer with HAL Drivers F1? 

    This topic has been closed for replies.

    2 replies

    Visitor II
    December 20, 2015
    Posted on December 20, 2015 at 22:54

    You can find several good implementations around on the web. Google knows about them.

    There are no special requirements for using a ring buffer on a STM32 MCU. For example, you can consider

    https://github.com/cnoviello/mastering-stm32/tree/master/nucleo-f103RB/Middlewares/RingBuffer

     even if I don't like it too much (it could be implemented in a faster way if it's ok to lose a bit of ''safeness''). Please, consider that this library works well only if you have just two ''threads'' operating on it. Otherwise, you have to add locking mechanisms. 

    Graduate II
    March 6, 2024

    Hi Carmine,

    Thanks for your post.

    One question for you and I would be very glad if you could answer. I am using STM32F407VG-DISC1 board.

    I have checked the repo you ve provided. I wonder that, is that OK if I copy ringbuffer.c under core-->src and also ringbuffer.h under core -->inc.

    Then, can I use ringbuffer functions with ease ?

    demir_0-1709749501221.png

     

    Graduate II
    March 6, 2024

    You're responding to a very old post, I think several forum transitions ago, the OP might not respond.

    I'd imagine you can use C rule to determine how best to integrate this into your build. Ring / Circular buffers being a pretty basic concept.

    Visitor II
    December 21, 2015
    Posted on December 21, 2015 at 12:44

    Check this ''thread'' safe implementation.

    https://github.com/MaJerle/stm32fxxx_hal_libraries/blob/master/00-STM32_LIBRARIES/tm_stm32_buffer.h

    If you don't use my libs, then just remove includes for libraries in this library:

    //Remove these 2 lines:

    #include ''stm32fxxx_hal.h''

    #include ''defines.h''

    And you are ready to go.

    Lib supports memory allocation with malloc, or if you want, you specify it by yourself.

    Ask here for more info, if needed.