Skip to content

Firmware Development

Adrian Blakey edited this page Dec 19, 2024 · 8 revisions

If you are going to attempt this it’s important to have a very good understanding of the ESCape32 code. The code is very terse and efficient because it “orchestrates” the hardware rather than trying to drive it (like AM32).

Key to doing this are a couple of interrupt service routines that are in main.c, namely:

void iftim_isr(void) { // BEMF zero-crossing
void tim3_isr(void) { // Any change on Hall sensor inputs

Timers are explained in this document: https://www.st.com/resource/en/application_note/dm00042534-stm32-crossseries-timer-overview-stmicroelectronics.pdf

In order to add capabilities to the firmware it's necessary have a programming and debugging environment to make changes and test them on the mcu.

This page is a work in progress that describes how to install an environment to extend the ESCape32 code and start hacking.

Hardware

A Remora board
Some lead wire
A power supply
An x64 computer running ArchLinux
A USB programmer dongle - PWLINK2
An oscilloscope
A USB to serial connector

Software

ArchLinux installed on the computer
gnu tools and cross compiler OpenOCD built for the Artery F421 Eclipse IDE Visual Studio Code and some extensions git

Links

https://www.linkedin.com/pulse/mastering-embedded-systems-programming-gnu-development-tools-uemgc/

https://embdev.net/forum/all

https://www.linkedin.com/pulse/buildingcompilation-process-using-gnu-arm-toolchain-mohamed-ali/

https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain

There are several proprietary tools, however we'll use open source tools to do this.

https://openocd.org/pages/about.html

The ESCape32 code builds on ArchLinux. So we'll use Arch on a laptop.

We need a USB dongle to connect to the board. We'll use our PWLINK2 to connect to the SWDIO/COM pins, and we'll attach as serial terminal to the signal pins.

Grab a Remora board and carefully solder a couple of wires to the SWDIO and SWDCOM pads. Connect these to the pins on the dongle.

Solder wires to the power pads.

Use the PA2/PA15 pins on the JST connector and connect these to ...

Install

cmake.
arm-none-eabi-gcc.
arm-none-eabi-binutils.
arm-none-eabi-newlib.
libopencm3.

Install and IDE, eclipse, visual studio code. VSC plugin for arm.

https://mcuoneclipse.com/2021/05/01/visual-studio-code-for-c-c-with-arm-cortex-m-part-1/

To do embedded development for ARM Cortex-M, I recommend the following extensions:

C/C++, ms-vscode.cpptools.
Cortex-Debug, marus25.cortex-debug.
CMake Tools, ms-vscode.cmake-tools.
CMake Syntax highlighting, twxs.cmake.
ARM Assembly highlighting, dan-c-underwood.arm.
Linker Script highlighting, zixuanwang.linkerscript.
The first three are required, the other are optional but recommended.

The easiest way is to install them from the command prompt inside the IDE:

code --install-extension ms-vscode.cpptools
code --install-extension marus25.cortex-debug
code --install-extension twxs.cmake
code --install-extension dan-c-underwood.arm
code --install-extension zixuanwang.linkerscript

Links: https://andybrown.me.uk/2015/03/22/stm32dev-windows/

OpenOCD

OpenOCD is an open source server process that is able to receive commands from ‘gdb’ and convert them internally to the ST-Link Serial Wire Debug (SWD) protocol to send to the discovery board. Eclipse will run gdb. gdb will talk to OpenOCD and openOCD will talk to the ST-Link chip.

Clone this wiki locally