Git Product home page Git Product logo

stm32-development-in-linux's Introduction

stm32-development-in-linux

If you want/need to develop STM32 MCUs in Linux... (not for running Linux on the MCU)

Environment

  • Mint Linux 18.3 64bit (or equivalent distro)
  • STM32F446RE board (or equivalent board)
  • J-Link debugger

Index

  • Get Basic Tools
  • Get ARM-GCC Compiler
  • Get JLink Package
  • Get OpenJDK
  • Get STM32CubeMX
  • Generate an Example
  • Compile the Example
  • Get VSCode and some useful extentions
  • Set Tasks.json for make/clean
  • Set Launch.json for debugging
  • Tips for Windows Users
  • Conclusion

Get Basic Tools

$ sudo apt update
$ sudo apt install build-essential
$ sudo apt install git

Get ARM-GCC Compiler

$ sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
$ sudo apt update
$ sudo apt install gcc-arm-embedded
$ arm-none-eabi-gcc -v

Tips:

Get JLink Package

Download J-Link Software and Documentation pack for Linux, DEB Installer, 64-bit from https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack

Currently the version is 6.30a

$ sudo dpkg -i JLink_Linux_V630_x86_64.deb

To test it, connect your eval board and JLink to your PC and...

$ JLinkExe -device STM32F446RE -speed 1000 -if swd

// If JLinkExe starts without issue...
  
$ connect

// See the result and exit.

> exit

Tip: After installing, reboot may require.

Get OpenJDK

STM32CubeMX requires 32bit JRE.

$ sudo apt install openjdk-11-jre:i386

Get STM32CubeMX

STM32CubeMX is a util that can be used for biler-plating based on hardeware (>>>).

ST doesn't provide an open link for the util but we need to request.
After the request, ST will send an email to us.

After download, extract the zip file and run its installer as below.

$ sudo ./SetupSTM32CubeMX-4.27.0.linux

Tip

  • After installing JRE, please use a new terminal for STM32CubeMX installation.

Generate an Example

To have a basic code set, we have to run STM32CubeMX.
I designed a minimal setup with the util and the design includes:

  • STM32F446RE
  • 8MHz xtal
  • A pin for LED
  • A pair of UART
  • Full speed USB and its stack.
  • FreeRTOS

The Test_USB_CDC4.ioc file in this repo is the configuration for the project.
To use the configuration:

  • Run STM32CubeMX (The binary can be found from /usr/local/STMicroelectronics/STM32Cube)
  • Load the configuration
  • Go to Project => Settings and check it is Makefile based.
  • Go to Project => Generate Code then the code can be generated.

Compile the Example

Now we can just compile the example generated by STM32CubeMX.

$ cd $PROJECT-ROOT (where the Makefile is)
$ make

Get VSCode and some useful extentions

If the compilation seems good, now install VSCode and some extensions from (>>>).

Must have extensions are:

  • C/C++
  • C++ Intellisense
  • Cortex-Debug
  • Vim (might be good for vim users but not for everyone)

Onde installation is done, open the folder where the project is.

Set Tasks.json for make/clean

To generate a Tasks.json,

  • Press CTRL+Shift+P.
  • Then type task.
  • Lastly click Tasks: Configure Task.

Above action generates a folder(.vscode) and a file(Tasks.json) under .vscode.
By filling the json file, we can invoke make and make clean with shortcuts.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make",
            "command": "make",
            "args": [
                "VERBOSE=1"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        },
        {
            "label": "clean",
            "command": "make",
            "args": [
                "clean"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

With this configuration, we can use CTRL+SHIFT+B to open the task dialog and run make or clean.

The detail can be found from MS' document (>>>).

Set Launch.json for debugging

To generate a launch.json,

  • Press CTRL+Shift+P.
  • Then type launch.
  • Lastly click Debug: Open launch.json.

Above action generates a file(launch.json) under .vscode.
By filling the json file, we can invoke the arm-none-eabi-gdb and JLink GDB server.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug",
            "cwd": "${workspaceRoot}",
            "executable": "./build/THE_EXECUTABLE_NAME.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "jlink",
            "device": "STM32F446RE",
            "interface": "swd",
        }
    ]
}

With this configuration, we can use F5 to start a debugging session.

Two things need to be adjusted based on your project:

  • executable: THE_EXECUTABLE_NAME should ba updated.
  • device: the depends on the target MCU.

The detail can be found from the extension's website (>>>).

Tips for Windows Users

First of all, install bash and make. I prefer MSYS2 (>>>).

Almost same things can be done to have the same environment except:

  • System Environment and the Path should have ARM-GCC's location (C:\Program Files (x86)\GNU Tools ARM Embedded\VERSION_CAN_DIFF\bin)
  • System Environment and the Path should have JLink's location (C:\Program Files (x86)\SEGGER\JLink_VERSION_CAN_DIFF)
  • System Environment and the Path should have MSYS2's location (C:\msys64\usr\bin)
  • System Environment and the MSYS2_PATH_TYPE should have its value as inherit

Also in the MSYS2 terminal, enter these to get make

$ pacman -Syuu 
$ pacman -S tar git tree vim base-devel

Conclusion

So far we followed this short manual to set up STM32 MCU development environment in Linux.

In the manual,

  • Downloaded the compiler, IDE, and SDK
  • Learned how to make your own project by STM32CubeMX
  • Compiled and debugged the project

As software changes everyday, the setup can be changed as well. However the basic step might be not very different.

stm32-development-in-linux's People

Contributors

bus710 avatar

Stargazers

 avatar  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.