Skip to main content

A Python package for parsing IOC files and generating C++ code.

Project description


License GitHub Repo Documentation GitHub Issues CI/CD - Python Package

libxr is a Python package designed to automate embedded system development by parsing .ioc files and generating C++ code. It significantly reduces manual effort in STM32CubeMX-based projects.

🌟 Features

  • Automatic .ioc parsing: Extracts GPIO, peripherals (UART, SPI, I2C, etc.), and DMA configurations.
  • C++ code generation: Generates fully functional STM32-compatible code.
  • STM32CubeMX & FreeRTOS support: Works seamlessly with STM32 and CMake build systems.
  • Automated Git management: Initializes repositories and creates .gitignore files.
  • CMake automation: Generates CMakeLists.txt for STM32 projects.

📥 Installation

Install via pip

pip install libxr

Install from source

git clone https://github.com/Jiu-xiao/LibXR_CppCodeGenerator.git
cd LibXR_CppCodeGenerator
pip install -e .

📌 API Reference

xr_cubemx_cfg

This command automates STM32CubeMX project setup, including:

  • Parsing .ioc files and generating JSON configuration.
  • Generating C++ code.
  • Modifying STM32 interrupt handlers.
  • Creating CMakeLists.txt with Clang support (if enabled).
  • Initializing Git and setting up .gitignore.
  • Adding the LibXR submodule if missing.

Usage:

xr_cubemx_cfg [-h] -d DIRECTORY [-t TERMINAL] [-c]

Required arguments:

  • -d, --directory (str): Path to the STM32CubeMX project.

Optional arguments:

  • -t, --terminal (str): Specifies the terminal device source.
  • -c, --clang: Enables Clang support for compilation.

xr_parse_ioc

Parses the .ioc file in the specified directory and extracts peripheral configurations into a JSON file.

Usage:

xr_parse_ioc [-h] -d DIRECTORY [-o OUTPUT]

Required arguments:

  • -d, --directory (str): Path to the STM32CubeMX project directory.

xr_gen_code

Generates C++ code from the parsed .ioc JSON configuration and saves an additional JSON file for further modifications.

Usage:

xr_gen_code [-h] -i INPUT [-o OUTPUT]

Required arguments:

  • -i, --input (str): Path to the JSON file generated by libxr_parse_ioc.

Outputs:

  • app_main.cpp: Generated STM32 C++ source file.
  • libxr_config.json: Stores configuration options such as DMA buffer sizes, terminal settings, and peripheral mappings.

xr_stm32_it

Modifies STM32 _it.c interrupt handler files to include necessary callback functions.

Usage:

xr_stm32_it [-h] input_dir

Required arguments:

  • input_dir (str): Path to the STM32CubeMX project source directory.

xr_stm32_clang

Generates gcc-arm-none-eabi.cmake for STM32 projects using Clang.

Usage:

xr_stm32_clang [-h] input_dir

Required arguments:

  • input_dir (str): Path to the STM32CubeMX project.

xr_stm32_cmake

Generates LibXR.CMake for STM32 projects using LibXR.

Usage:

xr_stm32_cmake [-h] input_dir

Required arguments:

  • input_dir (str): Path to the STM32CubeMX project.

.IOC file requirements

  • STM32CubeMX: The .ioc file must be generated using STM32CubeMX.
  • CMake: The project must be built using CMake.
  • DMA: UART, SPI and I2C must have DMA enabled.

After Generation

After the code generation is completed, users need to manually add the following include statement:

#include "app_main.h"

Additionally, ensure that the function app_main(); is called at an appropriate location:

  • For non-RTOS environments: Call app_main(); at the end of the main function.
  • For FreeRTOS environments: Call app_main(); at the beginning of the thread function.

🛠️ Contributing

We welcome community contributions! See our contribution guidelines for details.

Ways to contribute:

  • 📝 Submit pull requests for new features or bug fixes.
  • 🔍 Review pull requests from other contributors.
  • 🐛 Report issues and suggest improvements.
  • 📖 Write documentation and tutorials.
  • 🎨 Design graphics for branding and promotions.

For detailed guidelines, visit our contributing page.


📄 License

libxr is licensed under the Apache-2.0 license. See the LICENSE file for more details.


🔗 Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libxr-0.1.6.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libxr-0.1.6-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file libxr-0.1.6.tar.gz.

File metadata

  • Download URL: libxr-0.1.6.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for libxr-0.1.6.tar.gz
Algorithm Hash digest
SHA256 3115f2d86af41a3ed9552507001857c8a464ce022c4818350dc247fc20bbd9ba
MD5 9faf76f0e8d84d7ffc8c23dd83daa22a
BLAKE2b-256 f183f916ef7e69933ad16fffdb6715bc27c08f15f57b724d3c6622a4d553d036

See more details on using hashes here.

Provenance

The following attestation bundles were made for libxr-0.1.6.tar.gz:

Publisher: python-publish.yml on Jiu-xiao/LibXR_CppCodeGenerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libxr-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: libxr-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for libxr-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0cf2609cda8eb3121b2372d3c506c57a2c35838f7ce996adb9f4788fac629c07
MD5 957dead1dded9de833f6a54718902e84
BLAKE2b-256 08342295a2e9a5857a814e49bfc2cb726a7b4d9cd8772e342c0a2392f5fb0c90

See more details on using hashes here.

Provenance

The following attestation bundles were made for libxr-0.1.6-py3-none-any.whl:

Publisher: python-publish.yml on Jiu-xiao/LibXR_CppCodeGenerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page