Giter Site home page Giter Site logo

lukezsmith / stm32-dev Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 46.12 MB

A bare metal C project template and development environment for STM32 microcontrollers using Docker and Visual Studio Code. This template includes the GoogleTest testing framework and HAL/CMSIS drivers.

License: Apache License 2.0

Dockerfile 0.01% Shell 0.01% CMake 0.01% Makefile 0.01% C 96.89% Assembly 3.00% C++ 0.09%
bare-metal baremetal cmake docker embedded stm32 vscode googletest gtest hal makefile

stm32-dev's Introduction

stm32-dev

A bare metal C project template and development environment for STM32 microcontrollers using Docker and Visual Studio Code. This template includes the GoogleTest testing framework and HAL/CMSIS drivers.

Getting Started

Dependencies

Installation

To install run git clone https://github.com/lukezsmith/stm32-dev to clone the repository.

Following installation, open the directory in Visual Studio Code.

Once the directory has been opened in Visual Studio Code, re-open the directory using the provided Docker container. It will take a while to install.

Configuration

There are a number of configurable properties within the template.

Project/Executable Name

To rename the project and executable edit the CMakeLists.txt file in the root directory.

Adding Test Modules

To test new modules it is necessary to follow these steps:

  1. Copy the src/modules/simple_module/ folder to src/modules/<your_module_name>/.
  2. Rename src/modules/<your_module_name>/simple_module.c to src/modules/<your_module_name>/your_module_name.c
  3. Edit src/modules/<your_module_name>/CMakeLists.txt so <your-module-name> is the MODULE_NAME variable.
  4. Append add_subdirectory(<your-module-name>) to src/modules/CMakeLists.txt.
  5. Create the file test/test_<your_module_name>.c and add the following lines to test/CMakeLists.txt:
    list(APPEND tests_names "test_<your_module_name>") list(APPEND tests_flags " ")

HAL Drivers

In CMakeLists.txt only a subset of HAL drivers have been added to the executable build. It may be necessary to update this list if you use a HAL driver that is not already included in the executable. Note: To use the HAL driver you will also need to enable it in the include/stm32f4xx_hal_conf.h file, also.

Building

The template uses CMake to build the code. To automate the process there is a Makefile in the root directory which can be run to automate the build.

This template has cross-compilation set up. There is a test build which compiles on the host machine. I use this to unit test the code. To run this simply run make or make TEST_MODE=TRUE in the terminal from the root directory of the repository. The build will be saved in /build/test.

To build for the STM32 microcontroller run make to build a version for debugging. To create a release build run make BUILD_TYPE=Release. These build will be saved in /build/release.

Testing

This template includes GoogleTest. The process for adding test modules is explained above. Testing runs automatically when the test target is built with make BUILD_TYPE=test. There is also a Visual Studio Code Task included with this template that automatically runs the test build (and associated tests) when the task is run. For me the keyboard shortcut to run this task is CMD+SHIFT+B. This task can be found in /.vscode/tasks.json.

Debugging

The project is ready for debugging via gdb through the Debug build. I usually use the cortex-debug Visual Studio Code extension. A configuration file for debugging with cortex-debug (with openocd, stlink) can be found at .vscode/launch.json. You will need to modify this file based on your debugging server/microcontroller setup.

Flashing

Included in the Makefile is a flash command to flash the program to the STM32.

To flash the release build to the microcontroller run make flash.

NOTE: I haven't yet implemented USB pass-through for flashing (or debugging) whilst in the development container so flashing will fail if ran in the container. A workaround is to simply run the flash command from your host machine after building the project in the container.

References

I used a couple of different repositories to build this template:

stm32-dev's People

Contributors

lukezsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stm32-dev's Issues

Error when building make in the root directory

Hi, thank you for your repository.

I tried to build your project and dev container in Vscode loaded your package successfully. I followed your guide in README but I got this error :

image

Can you tell me how to solve this ? Im using Wsl (subsystem Linux) with my Windows machine. Thank you a lot.

Enable debug session error

Hi, thank you for your repo.

I managed to configure your template and build my STM32 project successfully.
However, when I started the debug session, I got the error like this:

image

I checked the Dockerfile and I saw OpenOCD was installed. I followed this link https://stackoverflow.com/questions/65872178/openocd-gdb-executable-arm-none-eabi-gdb-was-not-found-please-configure-cort

and added "cortex-debug.gdbPath": "gdb-multiarch" to settings.json. New error poped up :

image

image

image

Can you tell me or at least guide me on how to solve this error? I am a beginner in this field. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.