This repository has been archived on 2021-11-24. You can view files and clone it, but cannot push or open issues or pull requests.
fsfw_example_public/doc/README-stm32-freertos.md

183 lines
6.7 KiB
Markdown
Raw Permalink Normal View History

2021-04-27 17:22:34 +02:00
# FSFW demo with FreeRTOS OSAL on the STM32H743ZI
This demo can be run on a STM32H743ZI-Nucleo board with the FreeRTOS OSAL.
## General Information
The board is flashed and debugged with OpenOCD and this README specifies on how
to make this work with the Eclipse IDE. Other IDEs or the command line can be used as well as long
as long as OpenOCD integration is given. The example demo uses newlib nano. Some system calls were
overriden so the C and C++ stdio functions work. IO is sent via the HUART3, so debug output can be
read directly from the USB connection to the board.
## Prerequisite
1. [MSYS2](https://www.msys2.org/) installed on Windows. Not required on Linux.
2. [GNU ARM Toolchain](https://xpack.github.io/arm-none-eabi-gcc/install/) installed, recommended
to add binaries to system path.
3. Recommended for application code development:
[Eclipse for C/C++](https://www.eclipse.org/downloads/packages/) installed with the Eclipse MCU
plugin
4. [OpenOCD](https://xpack.github.io/openocd/) installed for Eclipse debugging
5. STM32 USB drivers installed, separate steps for
[Windows](https://www.st.com/en/development-tools/stsw-link009.html) or
[Linux](https://fishpepper.de/2016/09/16/installing-using-st-link-v2-to-flash-stm32-on-linux/)
## Building the software with CMake
On Windows, the following steps should be performed inside the MinGW64 console
after installing MSYS2. It is recommended to still use git for Windows for the git
related steps.
1. Clone this repository
```sh
git clone https://egit.irs.uni-stuttgart.de/fsfw/fsfw_example.git
```
2. Set up submodules
```sh
git submodule init
git submodule update
```
3. Navigate into the cloned repository and create a folder for the build. We will create a
Debug build folder.
```sh
mkdir Debug
cd Debug
```
4. Ensure that the ARM compiler has been added to the path and can be called from
the command line. For example, the following command should work:
```sh
arm-none-eabi-gdb --version
```
Now we will create the build configuration for cross-compilation of an ARM target.
On Linux, run the following command:
```sh
cmake -G "Unix Makefiles" -DOS_FSFW=freertos -DCMAKE_BUILD_TYPE=Debug -DTGT_BSP=arm/stm32h743zi-nucleo ..
```
On Windows, use the following command:
```sh
cmake -G "MinGW Makefiles" -DOS_FSFW=freertos -DCMAKE_BUILD_TYPE=Debug -DTGT_BSP=arm/stm32h743zi-nucleo ..
```
The build configuration can also be performed with the shell scripts located inside
`cmake/scripts/FreeRTOS` or the Python helper script `cmake_build_config.py` inside
`cmake/scripts`.
5. Build the application
```sh
cmake --build . -j
```
The application will be located inside the Debug folder and has been compiled for
the flash memory.
6. You can test the application by first connecting the STM32H743ZI-Nucleo via USB.
The device should now show up in the list of connected devices (make sure the USB drivers are
installed as well). Drag and drop the binary file into the connected device to flash it.
The debug output is also sent via the connected USB port and a blink pattern (1 second interval)
can be used to verify the software is running properly.
## Setting up the prerequisites
### Windows
It is recommended to install [MSYS2](https://www.msys2.org/) first.
Open MinGW64 and run the following commands to update it and install make and cmake
(replace x86_64 if compiling on different architecture):
```sh
pacman -Syuuu
```
```sh
pacman -S mingw-w64-x86_64-make mingw-w64-x86_64-cmake
```
The code needs to be compiled for the ARM target system and we will use the
[GNU ARM Toolchain](https://xpack.github.io/arm-none-eabi-gcc/install/).
1. Install NodeJS LTS. Add nodejs folder (e.g. "C:\Program Files\nodejs\")
to system variables. Test by running `npm --version` in command line
2. Install [XPM](https://www.npmjs.com/package/xpm)
```sh
npm install --global xpm
```
3. Install gnu-arm Toolchain for Eclipse (version can be specified)
```sh
xpm install --global @xpack-dev-tools/arm-none-eabi-gcc@latest
xpm install --global @xpack-dev-tools/windows-build-tools@latest
```
Install OpenOCD for STM32 debugging
```sh
xpm install --global @xpack-dev-tools/openocd@latest
```
4. Add arm-none-eabi-gcc binary location in the xPack folder to system variables.
These are usually located in C:\Users\<...>\AppData\Roaming\xPacks\@gnu-mcu-eclipse\arm-none-eabi-gcc\<version>\.content\bin .
Alternatively, if you want to keep the environment and the path clean, add it temporarily
with `SET PATH=%PATH%;c:\pathtotoolchain`.
5. Install the [STM32 USB drivers](https://www.st.com/en/development-tools/stsw-link009.html)
If you don't want to install nodejs you may go with the
[four-command manual installation](https://xpack.github.io/arm-none-eabi-gcc/install/#manual-install).
### Linux
Install the [GNU ARM toolchain](https://xpack.github.io/arm-none-eabi-gcc/install/)
like explained above, but for Linux, the Windows Build Tools package is not required.
On Linux, the a path can be added to the system variables by adding
`export PATH=$PATH:<..../@gnu-mcu-eclipse/arm-none-eabi-gcc/<version>/.content/bin>`
to the `.profile` or `.bashrc` file. Alternatively, if you want to keep the environment and the
path clean, add it temporarily with `export PATH=%PATH%;c:\pathtotoolchain`.
To install general buildtools for the linux binary, run:
```sh
sudo apt-get install build-essential
```
Install the USB drivers on Linux by
[following these instructions](https://fishpepper.de/2016/09/16/installing-using-st-link-v2-to-flash-stm32-on-linux/).
## Setting up Eclipse for OpenOCD debugging
The separate [Eclipse README](README-eclipse#top) specifies how to set up Eclipse.
The STM32 configuration uses the xPacks OpenOCD and the xPacks ARM Toolchain, so those should be
installed as well. OpenOCD should be configured correctly in the STM32 launch configurations.
## Troubleshooting
### OpenOCD errors
If you get the following error in OpenOCD: "Error: auto_probe failed", this could be related from
switching between FreeRTOS and RTEMS. You can try the following steps:
1. First way: Flash the binary manually by drag & droping the binary into the USB drive manually
once
2. Second way: Add -c "gdb_memory_map disable" to the OpenOCD arguments (in Eclipse) and run once.
Debugging might not be possible, so remove it for subsequent runs.
3. Third way: Add the following lines to the `stm32h7x.cfg` file located inside the OpenOCD folder
inside the `scripts/target` folder:
```sh
$_CHIPNAME.cpu configure -event gdb-attach {
halt
}
$_CHIPNAME.cpu configure -event gdb-attach {
reset init
}
```