Code Monkey home page Code Monkey logo

hands-on-rtos-with-microcontrollers-chapter-7's Introduction

Hands-On-RTOS-With-Microcontrollers-Chapter-7

LED-blinking application for Chapter 7 of Hands-On RTOS With Microcontrollers. This application is built for the STM32F767ZI Nucleo board. As opposed to the source code provided by the book for the STM32CubeIDE, this project utilizes CMake as the build system. The stm32-cmake project is used to incorporate the necessary source code directly from STMicroelectronic’s GitHub repositories and the FreeRTOS GitHub repository.

ℹ️

This project also deviates from the book according to the debugging software. The Segger hooks are not present and OpenOCD is used instead of the J-Link software.

Getting Started

This section describes how to setup the build environment required to build the project. The instructions here are for Ubuntu 20.04.

  1. Install the necessary system packages.

    ➜ sudo apt -y install binutils ccache clang-format gcc-arm-none-eabi gdb-multiarch git ninja-build qt5-default python3 \
      python3-pip
  2. Install the cmakelang Python package via Pip.

    ➜ python3 -m pip install --user cmakelang[yaml]
    ℹ️

    ~/.local/bin will need to be on your PATH.

  3. Install a newer version of CMake.

    1. Download the latest version.

      x86_64
      ➜ wget -LP ~/Downloads/ https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1-Linux-x86_64.sh
      aarch64
      ➜ wget -LP ~/Downloads/ https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1-Linux-aarch64.sh
    2. Make the installer executable.

      ➜ chmod +x ~/Downloads/cmake-*.sh
    3. Change to the /usr/local directory.

      cd /usr/local
    4. Install CMake in /usr/local.

      ➜ sudo ~/Downloads/cmake-*.sh
    5. Press q to skip reading the license.

    6. Enter y and press enter to accept the license.

    7. Enter n and press enter to install to the subdirectories in /usr/local.

    8. Remove the installer.

      ➜ rm ~/Downloads/cmake-*.sh

OpenOCD

OpenOCD is used to flash the executable to the STM32F7 MCU as well as debugging.

Ubuntu 20.04 ships with a version of OpenOCD without support for the STM32F7 Nucleo board. Installing the latest version of OpenOCD solves the problem. The following instructions build the latest source code available for the project on Ubuntu 20.04.

  1. Download and install the necessary packages.

    ➜ sudo apt -y install gcc libusb-1.0-0-dev libftdi-dev libhidapi-dev libgpiod-dev libcapstone-dev make
  2. Clone the OpenOCD repository.

    ➜ git clone git://git.code.sf.net/p/openocd/code openocd
  3. Change in to the OpenOCD directory.

    cd openocd
  4. Configure the Autotools project.

    ➜ ./bootstrap
  5. Configure the Autotools project.

    ➜ ./configure
💡
To install OpenOCD to /usr, configure with the flag --prefix=/usr.
  1. Build OpenOCD.

    fish
    ➜ make -j(nproc)
    Bash
    ➜ make -j$(nproc)
  2. Install OpenOCD.

    ➜ sudo make install

Udev

OpenOCD requires Udev rules to permit access to the Nucleo board. The instructions here describe how to do this.

  1. Plug the STM32F767ZI Nucleo board into a computer using the MicroUSB port opposite the ethernet port.

  2. Create the necessary Udev rule for the STM32F767ZI Nucleo board in the file /etc/udev/rules.d/99-openocd.rules.

    /etc/udev/rules.d/99-openocd.rules
    # STM32F767ZI Nucleo - ST-LINK/V2.1
    ATTRS{idVendor}=="0438", ATTRS{idProduct}=="374b", MODE:="0666"
  3. Unplug the STM32F767ZI Nucleo board from the computer.

  4. Now plug it back in to ensure the new Udev rule is applied to it.

Build

Required source code is pulled in with CMake using stm32-cmake and FetchContent. When using a single configuration generator with CMake, set the appropriate build type when configuring the build. Likely, this build type will be either Debug or Release, but may also be MinSizeRel in order to produce the smallest executable possible. Examples for each build type are provided below. The examples also enable several helpful options to improve performance of the build and the resulting binaries. These examples assume you are in the top-level directory of the project and using a build directory named build.

  1. First, clone the source code of this repository locally.

    ➜ git clone https://github.com/jwillikers/Hands-On-RTOS-With-Microcontrollers-Chapter-7.git
  2. Then change into the project directory.

    cd Hands-On-RTOS-With-Microcontrollers-Chapter-7
  3. Configure the build using the provided toolchain file.

    Debug
    ➜ cmake \
      -GNinja \
      -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_UNITY_BUILD=yes \
      -DCLANG_FORMAT_PROGRAM=/usr/bin/clang-format \
      -B build -S .
    Release
    ➜ cmake \
      -GNinja \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_UNITY_BUILD=yes \
      -DCLANG_FORMAT_PROGRAM=/usr/bin/clang-format \
      -B build -S .
    MinSizeRel
    ➜ cmake \
      -GNinja \
      -DCMAKE_BUILD_TYPE=MinSizeRel \
      -DCMAKE_UNITY_BUILD=yes \
      -DCLANG_FORMAT_PROGRAM=/usr/bin/clang-format \
      -B build -S .
  4. Build the project with CMake.

    ➜ cmake --build build
    ℹ️

    This will also produce a build/blinky.bin binay file and a build/blinky.hex hex file.

  5. To flash the ELF file directly to the STM32F7 Nucleo board with OpenOCD, build the flash target with CMake.

    ➜ cmake --build build --target flash

Format

The clang-format and cmake-format tools are used to format the source code files. The Format.cmake module provides build targets to simplify the use of these tools.

Format the source files by building the CMake target fix-format.

➜ cmake --build build --target fix-format

Contributing

Contributions in the form of issues, feedback, and even pull requests are welcome. Make sure to adhere to the project’s Code of Conduct.

Open Source Software

This project is built on the hard work of countless open source contributors. Several of these projects are enumerated below.

Code of Conduct

The project’s Code of Conduct is available in the Code of Conduct file.

License

This repository is licensed under the GPLv3, available in the license file.

© 2021 Jordan Williams

Authors

hands-on-rtos-with-microcontrollers-chapter-7's People

Contributors

jwillikers avatar

Watchers

 avatar  avatar

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.