Integration of MicroOCPP on STM32F4 Nucleo-F446RE using ESP32-C3 as a Wi-Fi bridge. Implements UART communication, secure WebSocket connections, and Open Charge Point Protocol (OCPP) for EV chargers.
This repository demonstrates the implementation of MicroOCPP on an STM32F4 microcontroller, enabling OCPP 1.6 compliance for Electric Vehicle Supply Equipment (EVSE). It integrates key components like secure WebSocket communication, time synchronization, and FreeRTOS task management to provide a complete OCPP solution on embedded hardware.
The project is designed for:
- Embedded developers implementing OCPP in EV chargers.
- Researchers exploring smart charging infrastructure.
- IoT enthusiasts interested in embedded real-time systems for EVSE.
- OCPP 1.6 Compliance: Implements core functionalities like secure WebSocket communication and OCPP message handling.
- TLS Security: Secure WebSocket connections over TLS 1.2, ensuring data integrity and protection against threats.
- Time Synchronization: Uses an NTP client to synchronize time for accurate certificate validation.
- FreeRTOS Integration: Efficient task management with FreeRTOS, supporting multitasking for communication, logging, and hardware interaction.
- Modular Design: Highly structured project with separate modules for networking, OCPP logic, and hardware abstraction.
- Cross-Platform Capability: Portable code adaptable to other STM32 families or embedded platforms.
- Scalability: Supports integration with additional peripherals like Wi-Fi modules, SD cards, and cloud interfaces.
- MicroOCPP: Open-source lightweight OCPP library.
- Mongoose: Provides WebSocket and HTTP server/client functionality.
- LWIP: Lightweight TCP/IP stack for networking on resource-constrained devices.
- MbedTLS: Enables secure communication via TLS.
- FreeRTOS: Real-time operating system for multitasking.
- Microcontroller: STM32F4 Series (e.g., STM32F407VGT6).
- Ethernet: For networking using the STM32F4's Ethernet MAC.
- UART: Optional communication with Wi-Fi modules like ESP-01.
STM32F4_MicroOCPP
├── config # Configuration files
│ ├── lwipopts.h # LWIP settings
│ ├── FreeRTOSConfig.h # FreeRTOS configuration
│ ├── mbedtls_config.h # TLS settings
├── drivers # HAL/LL drivers
│ ├── ethernet.c # Ethernet driver implementation
│ ├── ethernet.h
│ ├── uart.c # UART driver for Wi-Fi (if applicable)
│ ├── uart.h
├── src # Application source code
│ ├── main.c # Application entry point
│ ├── ocpp_integration.c # OCPP logic
│ ├── wifi_ethernet.c # Networking setup
│ ├── ntp_client.c # NTP synchronization
│ ├── tls_config.c # TLS configuration
│ ├── logging.c # Logging utilities
│ ├── tasks.c # FreeRTOS tasks
├── include # Header files
│ ├── ocpp_integration.h
│ ├── wifi_ethernet.h
│ ├── ntp_client.h
│ ├── tls_config.h
│ ├── logging.h
│ ├── tasks.h
├── third_party # External libraries
│ ├── MicroOcpp/
│ ├── mongoose/
│ ├── lwip/
├── build # Build output (CMake-generated)
├── .github/workflows # GitHub Actions for CI/CD
│ ├── build.yml # CI/CD pipeline
├── CMakeLists.txt # Build configuration
└── README.md # Project documentation
- STM32F4 development board (e.g., STM32F407VG).
- Ethernet connectivity or Wi-Fi module (e.g., ESP-01).
- Debugging tools (e.g., ST-LINK, UART-to-USB converter).
- STM32CubeMX: For hardware initialization.
- CMake: Build system generator.
- Toolchain: GCC ARM Embedded or STM32CubeIDE.
- Git: To manage the repository and submodules.
-
Clone the Repository Clone the repository with all submodules:
git clone --recurse-submodules <repository-url>
-
Configure Hardware Initialization
- Open STM32CubeMX and generate initialization code for:
- Ethernet (with LWIP enabled).
- UART (for optional Wi-Fi support).
- FreeRTOS.
- Export the generated code and integrate it into the
drivers/
directory.
- Open STM32CubeMX and generate initialization code for:
-
Build the Project
- Create a build directory:
mkdir build && cd build
- Generate the build system using CMake:
cmake ..
- Compile the project:
cmake --build .
- Create a build directory:
-
Flash the Firmware Use STM32CubeProgrammer or equivalent to flash the firmware onto the STM32F4.
-
Monitor Logs
- Connect to the UART interface using tools like PuTTY or minicom.
- View runtime logs and debug output.
The entry point initializes peripherals, networking, and the MicroOCPP library. It also starts the FreeRTOS scheduler.
Handles OCPP message formatting, parsing, and WebSocket communication with the backend.
Configures Ethernet or UART-based Wi-Fi for internet access.
Initializes MbedTLS for secure WebSocket communication.
Synchronizes the system clock using SNTP for accurate certificate validation.
Defines tasks for handling communication, logging, and hardware interactions.
- Create a prototype for an OCPP-compliant charging station.
- Test the device's compatibility with OCPP backends like ChargePoint or OCPP Cloud.
- Use the modular codebase to experiment with secure communication and IoT protocols.
- Demonstrates advanced embedded concepts like multitasking, secure communication, and IoT integration.
We welcome contributions! Follow these steps to contribute:
- Fork the repository and create a new branch.
- Implement your changes with detailed comments.
- Submit a pull request describing your changes.
This project is licensed under the MIT License. See the LICENSE
file for details.
- MicroOCPP by Matthias Akstaller for the lightweight OCPP implementation.
- Mongoose by Cesanta for WebSocket support.
- STM32CubeMX by STMicroelectronics for hardware initialization.