All Projects → alejoseb → Modbus-STM32-HAL-FreeRTOS

alejoseb / Modbus-STM32-HAL-FreeRTOS

Licence: LGPL-2.1 license
Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS

Programming Languages

c
50402 projects - #5 most used programming language
Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to Modbus-STM32-HAL-FreeRTOS

lwow
Lightweight onewire protocol library optimized for UART hardware on embedded systems
Stars: ✭ 98 (-63.97%)
Mutual labels:  stm32, usart, dma
stm32 tiny monitor
A tiny external monitor for PC using STM32 and ST7789. Connects to PC over USB and displays the captured screen on ST7789 (240x240) display.
Stars: ✭ 61 (-77.57%)
Mutual labels:  usb, stm32, bluepill
node-drivers
Industrial protocol drivers in node.js
Stars: ✭ 20 (-92.65%)
Mutual labels:  tcp, modbus, plc
platformio-libopencm3-freertos
Sample blinky project for PlatformIO using libopencm3 and FreeRTOS
Stars: ✭ 14 (-94.85%)
Mutual labels:  stm32, freertos, bluepill
Iotclient
这是一个物联网设备通讯协议实现客户端,将会包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。本组件终身开源免费,采用最宽松的MIT开源协议,您可以随意修改和商业使用(商业使用请做好评估和测试)。
Stars: ✭ 311 (+14.34%)
Mutual labels:  tcp, modbus, plc
stm32-tkg-hid-bootloader
A HID driverless bootloader and flash tool companion for the STM32F1 line
Stars: ✭ 30 (-88.97%)
Mutual labels:  stm32, bluepill
STM32 XPD
STM32 eXtensible Peripheral Drivers
Stars: ✭ 38 (-86.03%)
Mutual labels:  usb, stm32
Teenyusb
Lightweight USB device and host stack for STM32 and other MCUs.
Stars: ✭ 287 (+5.51%)
Mutual labels:  usb, stm32
Usbdevice
Highly flexible Composite USB Device Library
Stars: ✭ 144 (-47.06%)
Mutual labels:  usb, stm32
stm32 i2c to usb hid multitouch
i2c to usb hid multi touch with stm32
Stars: ✭ 55 (-79.78%)
Mutual labels:  usb, stm32
Libusb stm32
Lightweight USB device Stack for STM32 microcontrollers
Stars: ✭ 372 (+36.76%)
Mutual labels:  usb, stm32
Sboot stm32
Secure USB DFU1.1 bootloader for STM32
Stars: ✭ 181 (-33.46%)
Mutual labels:  usb, stm32
kikpad
KiKPad : the Midiplus SmartPad reinvented !
Stars: ✭ 31 (-88.6%)
Mutual labels:  usb, stm32
STM32 USB CH341
STM32 USB simulates CH341.
Stars: ✭ 52 (-80.88%)
Mutual labels:  usb, stm32
ISASTM
STM32-based ISA-over-USB-adapter
Stars: ✭ 86 (-68.38%)
Mutual labels:  usb, stm32
Stm32f103 Usb Cdc Cmsis
STM32F103 USB CDC CMSIS
Stars: ✭ 40 (-85.29%)
Mutual labels:  usb, stm32
XC-OS
Open source graphics operating system for microcontroller
Stars: ✭ 66 (-75.74%)
Mutual labels:  stm32, freertos
stm32 framework
一个志在实现STM32F1、F2和F4工程模板的项目,集成了FreeRTOS、LWIP、FATFS、DSP、USB、IAP、菜单库、有限状态机模板等等的组件,以及未来将加入的加密、BPNN、最小二乘、音频图片视频解码、LittlevGL等诸多常用的算法或组件,并具有良好的易用性、解耦性和可剪裁性!
Stars: ✭ 91 (-66.54%)
Mutual labels:  stm32, freertos
f1usb
Einfaches Beispiel für die Entwicklung eines USB FullSpeed Device auf Basis des STM32F103 ohne die Verwendung externer Bibliotheken
Stars: ✭ 27 (-90.07%)
Mutual labels:  usb, stm32
DfuBootloader
STM32 USB device bootloader using DFU class interface
Stars: ✭ 79 (-70.96%)
Mutual labels:  usb, stm32

Modbus library for STM32 Microcontrollers

TCP, USART and USB-CDC Modbus RTU Master and Slave library for STM32 microcontrollers based on Cube HAL and FreeRTOS.

Includes multiple examples for popular development boards including BluePill, NUCLEO-64, NUCLEO-144 and Discovery Boards (Cortex-M3/M4/M7).

This is a port of the Modbus library for Arduino: https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino

Video demo for STM32F4-discovery board and TouchGFX: https://youtu.be/XDCQvu0LirY

NEW Script examples to test the library based on Pymodbus

NEW TCP slave (server) multi-client with configurable auto-aging algorithm for management of TCP connections

Translations supported by the community:

Traditional Chinese: 繁體中文

Characteristics:

  • Portable to any STM32 MCU supported by ST Cube HAL.
  • Portable to other Microcontrollers, like the Raspberry PI Pico, requiring little engineering effort.
  • Multithread-safe implementation based on FreeRTOS.
  • Multiple instances of Modbus (Master and/or Slave) can run concurrently in the same MCU, only limited by the number of available UART/USART of the MCU.
  • RS232 and RS485 compatible.
  • USART DMA support for high baudrates with idle-line detection.
  • USB-CDC RTU master and Slave support for F103 Bluepill board.
  • TCP master and slave support with examples for F429 and H743 MCUs

File structure

├── LICENSE
├── README.md
├── Examples
    ├── ModbusBluepill --> STM32F103C8 USART Slave
    ├── ModbusBluepillUSB --> STM32F103C8 USART + USB-CDC Master and Slave 
    ├── ModbusF103 --> NUCLEO-F103RB Modbus Master and Slave
    ├── ModbusF429 --> NUCLEO-F429ZI Modbus Slave 
    ├── ModbusF429TCP --> NUCLEO-F429ZI Modbus TCP
    ├── ModbusF429DMA --> NUCLEO-F429ZI Modbus RTU DMA master and slave 
    ├── ModbusL152DMA --> NUCLEO-L152RE Modbus RTU DMA slave
    ├── ModbusH743 --> NUCLEO-H743ZI Modbus Slave
    ├── ModbusH743TCP --> NUCLEO-H743ZI Modbus TCP
    ├── ModbusF303 --> NUCLEO-F303RE Modbus Slavee
    ├── ModbusSTM32F4-discovery --> STM32F4-discovery TouchGFX + Modbus Master
├── MODBUS-LIB --> Library Folder
    ├── Inc
    │   └── Modbus.h 
    ├── Config
    │   └── ModbusConfigTemplate.h --> Configuration Template
    └── Src
        ├── Modbus.c 
        └── UARTCallback.c
 

How to use the examples

Examples provided for STM32CubeIDE Version: 1.8.0 https://www.st.com/en/development-tools/stm32cubeide.html.

  • Import the examples in the STM32Cube IDE from the system folder
  • Connect your NUCLEO board
  • Compile and start your debugging session!
  • If you need to adjust the Baud rate or any other parameter use the Cube-MX assistant (recommended). If you change the USART port you need to enable the interrupts for the selected USART. Check UARTCallback.c for more details.

Notes and Known issues :

  • The standard interrupt mode for Modbus RTU USART is suitable for 115200 bps or lower baud rates. For Higher baud rates---tested up to 2 Mbps---it is recommended to use the DMA mode. Check the corresponding examples. It will require extra configurations for the DMA channels in the Cube HAL.

  • The USB-CDC example supports only the Bluepill development board. It has not been validated with other development boards. To use this example, you need to activate USB-CDC in your ModbusConfig.h file.

  • The TCP examples have been validated with NUCLEO F429ZI and H743ZI. To use these examples, you need to activate TCP in your ModbusConfig.h file.

  • The HAL implementation for LWIP TCP of the CubeMX generates code that might not work if the cable is not connected from the very beginning. This is a known issue that can be solved manually changing the generated code as detailed here: https://community.st.com/s/question/0D50X0000CDolzDSQR/ethernet-does-not-work-if-uc-starts-with-the-cable-disconnected

Check the TCP example for the NUCLEO F429, which includes the manual modifications.

How to port to your own MCU

  • Create a new project in STM32Cube IDE for your MCU
  • Enable FreeRTOS CMSIS_V2 in the middleware section of Cube-MX
  • Configure a USART and activate the global interrupt
  • If you are using the DMA mode for USART, configure the DMA requests for RX and TX
  • Configure the Preemption priority of USART interrupt to a lower priority (5 or a higher number for a standard configuration) than your FreeRTOS scheduler. This parameter is changed in the NVIC configuration pane.
  • Import the Modbus library folder (MODBUS-LIB) using drag-and-drop from your host operating system to your STM32Cube IDE project
  • When asked, choose link folders and files
  • Update the include paths in the project's properties to include the Inc folder of MODBUS-LIB folder
  • Create a ModbusConfig.h using the ModbusConfigTemplate.h and add it to your project in your include path
  • Instantiate a new global modbusHandler_t and follow the examples provided in the repository
  • Note: If your project uses the USART interrupt service for other purposes you have to modify the UARTCallback.c file accordingly

Recommended Modbus Master and Slave testing tools for Linux and Windows

Master and slave Python library

Linux/Windows: https://github.com/riptideio/pymodbus

Master client Qmodbus

Linux: https://launchpad.net/~js-reynaud/+archive/ubuntu/qmodbus

Windows: https://sourceforge.net/projects/qmodbus/

Slave simulator

Linux: https://sourceforge.net/projects/pymodslave/

Windows: https://sourceforge.net/projects/modrssim2/

TODOs:

  • Implement wrapper functions for Master function codes. Currently, telegrams are defined manually.
  • Improve function documentation
  • MODBUS TCP implementation improvement to support multiple clients and TCP session management (10/24/2021)
  • Improve the queue for data reception; the current method is too heavy it should be replaced with a simple buffer, a stream, or another FreeRTOS primitive. Solved Queue replaced by a Ring Buffer (03/19/2021)
  • Test with Rs485 transceivers (implemented but not tested) Verified with MAX485 transceivers (01/03/2021)
  • MODBUS TCP implementation (28/04/2021)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].