Commit 1e12ff81 authored by Mikaël BRIDAY's avatar Mikaël BRIDAY
Browse files

update doc

parent f005b5c7
No preview for this file type
# Setting up programming environment
# Cross-compiler
This project contains the practical work for the MICRO course.
This file contains important information about the configuration of the host computer,
and some basics on the C compiler suite usage.
The target is a ST Nucleo32 board STM32F303K8. We assume that the host computer is either a Linux (tested with Ubuntu 18.04) or a Mac computer.
The target is a ST Nucleo32 board STM32F303K8.
## Required tools
We do not use any IDE, but a C code editor (Vim, Emacs, Gedit, …).
The compilation and flash phases are based on a provided Makefile
The compiler suite is arm-none-eabi-gcc. The debugging is done using directly arm-none-eabi-gdb (or ddd for a GUI).
The compiler suite is arm-none-eabi-gcc and the debugger is arm-none-eabi-gdb (that can be used in command line interface, or through a gui like QtCreator).
### Linux
On Linux (Debian/Ubuntu flavor), you should install:
* `build-essential`
* `gcc-arm-none-eabi`
* `gdb-arm-none-eabi` (to debug)
* [st-link](https://github.com/texane/stlink)
First the essential build tools:
......@@ -25,7 +16,8 @@ First the essential build tools:
sudo apt-get install build-essential
```
Ubuntu provides a compiler version, but no more the associated debugger! The best way is to use [the one provided by ARM](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads).
The compiler can be downloaded through packages, but there are some problems with it. You can download [a version provided by ARM](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads).
The archive may be decompressed, and the environment variable PATH should be updated (here if the archive has been decompressed to `/path/to/gcc-arm`):
```sh
export PATH=/path/to/gcc-arm/bin:$PATH
......@@ -50,44 +42,3 @@ export PATH=/path/to/stlink/bin:$PATH
```
This environment variable should be defined each time a terminal is opened, so you can add it in the file `~/.profile`, which is a script that is executed each time a terminal is opened on Mac.
## Compile/Run
### Compile
To compile, just use the makefile:
```sh
make
```
### Flash
To flash the application (st-link should be installed first):
```sh
make flash
```
### Debug
to debug the application (using gdb), first run `st-util` in another terminal, and run:
```sh
arm-none-eabi-gdb -tui test.elf
```
a gdb script is provided to initiate communication with target, load the application and run until main. You just hae to call the init script inside gdb:
```gdb
source init.gdb
```
see file [gdb.md](./gdb.md) to have basic command to start debug your application!
### Clean
To remove generated files (obj/exec):
```sh
make flash
```
......@@ -114,7 +114,7 @@ The 1.8" color TFT display is an [Adafruit product](https://www.adafruit.com/pro
| name | STM32 pin | description |
|----------|-----------------|------------------------|
| TFT_CS | PB2 | Chip select |
| TFT_CS | PA4 | Chip select |
| SCK | PB3 / SPI1_SCK | Serial clock |
| MOSI | PB5 / SPI1_MOSI | Master Out, Slave In |
| MISO | PB4 / SPI1_MISO | Master In, Slave Out |
......
......@@ -7,16 +7,16 @@ QtCreator is eator is a cross-platform integrated development environment (IDE)
We focus here on how to use the debugger (instead of the command line gdb).
Tested with QtCreator 4.11.0. GCC for ARM should be installed first (compiler)
Tested with QtCreator 4.13.2. GCC for ARM should be installed first (compiler)
## Installation
* install [QtCreator](https://www.qt.io/development-tools)
* check for the BareMetal plugin in Help->About plugins…, and Device Support->BareMetal ![plugin](./img/pluginQtCreator.png)
* check for the BareMetal plugin in Help->About plugins… (on Mac:`Qt Creator->About Plugins…`), and Device Support->BareMetal ![plugin](./img/pluginQtCreator.png)
## Configuration
Qt Creator should be configured in 2 sections`tools->options`:
Qt Creator should be configured in 2 sections`tools->options` (on Mac: `Qt Creator->Preferences…`):
* the `Devices` part
* the `Kits` part
......@@ -25,69 +25,75 @@ Qt Creator should be configured in 2 sections`tools->options`:
Define the Device (how to connect to the device), in the `Devices` part:
* In the tab `Bare Metal`, click `add->ST-LINK utility`
In the tab `Bare Metal`, click `add->ST-LINK utility`:
![](./img/qtCreatorConfigDevice.png)
* In the tab `Devices`, add a new device and associate it to the ST-LINK utility.
* There is also a `peripheraldescription file` edit line. You can give the file `sys/CMSIS/SVD/STM32F303x.svd`. The SVD file give the information on the register set of the MCU, so that we can inspect the full configuration of the target chip during debug (peripheral view)
![](./img/qtCreatorConfigDevice2.png)
There is a `peripheraldescription file` edit line. You can give the file `sys/CMSIS/SVD/STM32F303x.svd`. The SVD file give the information on the register set of the MCU, so that we can inspect the full configuration of the target chip during debug (peripheral view)
Don't forget to click on `Apply` button!
With Macs in `D102`, the full path is: `/opt/stlink/bin/st-util`
Then, in the `Devices` tab, click `add…` and add a bare-metal device that uses st-link:
![](./img/qtCreatorAddDevice.png)
### Kits
In the `Kits` part:
* First define the debugger `Debugger` tab:
![](img/qtCreatorConfigBR.png)
To know where is your gdb version, you can simply type in a terminal:
```sh
which arm-none-eabi-gdb
```
With Macs in `D102`, the fullepath is: `/opt/gcc-arm/bin/arm-none-eabi-gdb-py`
QtCreator requires to use a gdb version that embeddeds the python extension. it is the `arm-none-eabi-gdb-py` version in the GCC version provided by ARM.
* You can set the cross-compiler. This is not required if you wants to debug only. Here, I have both set the C compiler (`gcc`) and the c++ compiler (`g++`). It is exactly the same configuration, just rename the compiler path from gcc to g++:
![](./img/qtCreatorConfigBRCompiler.png)
* You can set the cross-compiler (This is not required if you wants to debug only). Here, I have both set the C compiler (`gcc`) and the c++ compiler (`g++`). It is exactly the same configuration, just rename the compiler path from gcc to g++:
* The we can define the `kit` that contains all the stuff (device/debugger) in `Kits` section:
![](./img/qtCreatorConfigBRKits.png)
There is a warning in the Kit configuration if no compiler is associated.
(./img/qtCreatorConfigBRCompiler.png)
## Debugging session
* The we can define the `kit` that contains all the stuff (device/debugger) in `Kits` section:
### Debug session start
![](./img/qtCreatorConfigBRKits.png)
To start a debugging session, the binary `.elf` should be generated:
There is a warning in the Kit configuration if no compiler is associated. By default, `cmake` will try to compile on the host. To configure it as a cross compiler, We have to change the `CMake configuration` in the kit:
```sh
make
```
![](./img/qtCreatorConfigBRKitsCMake.png)
Then, the `st-util` tool should be called. The utility makes the connection between the board and the computer (using the STLink protocol). In a terminal:
~~~~
CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
CMAKE_CXX_COMPILER_FORCED:INTERNAL=TRUE
CMAKE_CXX_COMPILER_ID:INTERNAL=GNU
CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
CMAKE_C_COMPILER_FORCED:INTERNAL=TRUE
CMAKE_C_COMPILER_ID:INTERNAL=GNU
CMAKE_SYSTEM_NAME:INTERNAL=Generic
CMAKE_SYSTEM_PROCESSOR:INTERNAL=arm
~~~~
```sh
$ st-util
st-util 1.5.1-12-g30de1b3
2019-12-13T08:22:40 INFO common.c: Loading device parameters....
2019-12-13T08:22:40 INFO common.c: Device connected is: F3xx medium density device, id 0x10016438
2019-12-13T08:22:40 INFO common.c: SRAM size: 0x3000 bytes (12 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 2048 bytes
2019-12-13T08:22:40 INFO gdb-server.c: Chip ID is 00000438, Core ID is 2ba01477.
2019-12-13T08:22:40 INFO gdb-server.c: Listening at *:4242...
```
## Debugging session
If all is ok, st-util waits to a connection on `localhost:4242` port.
### Debug session start
Then, we can connect to st-link using Qt Creator, in `Debug->Start debugging->Attach to Running Debug Server...`:
* define the server port to 4242 (ST-util server port)
* give the `Local executable` full path (path to the .elf file)
To start a debugging session, the binary `.elf` should be generated. Then start the debugger using: `Debug->Start and break on main`.
![](./img/qtCreatorStartDebug.png)
It should launch `st-util`, the tool that communicates between the board and qtCreator.
### Using debug session
Qt Creator acts only as a graphical user interface, and all the gdb command are now available using the GUI:
Qt Creator acts only as a graphical user interface, and all the `gdb` commands are available using the GUI:
In the image just below:
* the yellow arrow shows the next instruction that will be executed
* the red dot is a `breakpoint`, where the program should stop. It is inserted/removed by a simple click just before the line number.
![](./img/qtCreatorDebugBreak.png)
The program execution is controlled by the commands ![](./img/qtCreatorDebugStartStop.png) (A tip label is displayed when the mouse gets over the buttons):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment