2024-07-04 05:00 PM - edited 2024-07-04 05:01 PM
Hi,
I have a custom master PCB connected to a few slave custom PCBs via serial. In some systems they are connected via I2C and in other systems they are connected via RS232.
They all run STM32 micros.
I am looking for two out-of-the-box protocols with source code available, one for the I2C and one for the RS232. They need to be very simple because only very little and simple data is exchanged (enable motor, change state machine state, turn LED on/off, etc) and none of it is time critical either.
Which protocol would you suggest and where can I find the source code?
Is there any such or similar solution provided by ST?
Thank you :)
Solved! Go to Solution.
2024-07-08 08:11 AM
Hello @Ricko
Yes, you could try FreeRTOS that is a real-time operating system kernel for embedded devices that is popular for STM32. It provides task management, inter-task communication, and synchronization.
As examples, we have:
This example shows how to use semaphores for task synchronization.
This example shows how to use mutexes to manage resource access.
This example demonstrates the use of queues for inter-task communication.
You can also find many examples in other STM32Cubes such as: STM32CubeH7, STM32CubeF7, STM32CubeG4...
I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.
Thanks for your contribution.
Dor_RH
2024-07-05 06:20 AM
Hello @Ricko ,
I2C: It is widely used and supported by many microcontrollers, including STM32. You could use STM32CubeMX and STM32Cube firmware packages.
RS232: you can use open-source libraries for RS232 communication and refer to STM32Cube firmware packages for UART examples.
Also, for very simple data exchanges, you can create custom protocols based on STM32 HAL libraries. This involves defining a set of commands and responses that both master and slave devices understand.
I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.
Thanks for your contribution.
Dor_RH
2024-07-07 03:08 PM - edited 2024-07-07 03:12 PM
Thank you @Dor_RH
I am aware of the I2C drivers.
What I was wondering about was whether there are some ready-made libraries for some very simple protocol, not for the peripherals (i.e. not the drivers for the peripherals).
I mean libraries that have already the state machine, parser, and storing of the received data into a predefined data structure. For some very simple protocol ad described in the OP.
I mentioned the I2C and RS232 just to list the peripheral am using. But it obviously can be over any peripheral.
Thank you :)
2024-07-08 08:11 AM
Hello @Ricko
Yes, you could try FreeRTOS that is a real-time operating system kernel for embedded devices that is popular for STM32. It provides task management, inter-task communication, and synchronization.
As examples, we have:
This example shows how to use semaphores for task synchronization.
This example shows how to use mutexes to manage resource access.
This example demonstrates the use of queues for inter-task communication.
You can also find many examples in other STM32Cubes such as: STM32CubeH7, STM32CubeF7, STM32CubeG4...
I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.
Thanks for your contribution.
Dor_RH
2024-07-08 11:24 AM - edited 2024-07-09 03:27 AM
Thank you @Dor_RH
but that is not what I asked. :) Not sure how FreeRTOS came into this discussion either... :)
I asked if there are "libraries that have already the state machine, parser, and do the storing of the received data into a predefined data structure." For some any simple software protocol (like SLIP or any other point to point one) and not a peripheral drivers.
A library that:
- on the sender side, when I want to send a packet I just call a function and pass the parameters with the payload I want to send (or a pointer to a data structure I want to send)
- on the receiver side, I just get a interrupt or a callback function that is called whenever a message has been received, CRC checked and the data has been put directly into a data structure and is now ready for me to use
- on both sides it handles all the timeout and error conditions
Thank you again for your help :)
2024-07-09 06:25 AM
Hello @Ricko ,
Unfortunately, the STM32Cube Firmware does not provide such kind of specific application libraries.
Thanks for your contribution.
Dor_RH
2024-07-09 01:20 PM
Thank you @Dor_RH