Skip to content

Commit 1d0256e

Browse files
authored
Merge pull request #497 from facchinm/new_readme
Improve readme and add flag to turn debug info ON for libmbed
2 parents 0b317c9 + b54cfbf commit 1d0256e

File tree

2 files changed

+72
-18
lines changed

2 files changed

+72
-18
lines changed

README.md

+62-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The repository contains the Arduino APIs and IDE integration files targeting a generic mbed-enabled board
44

5+
## FAQ
6+
### Source-Code Level Debugging
7+
**Question**: "I want to debug my ArduinoCore-mbed based sketch using traditional debugging tools, i.e. gdb via SWD interface. However, the debugger is unable to locate the sources for all files, particular the mbed-os files."
8+
9+
**Answer**: This is due to the fact that we pre-compile the mbed-os code into a static library `libmbed.a`. Information on how to recompile `libmbed.a` for source code debugging can be found [here](#recompiling-libmbed-with-source-level-debug-support). The [Arduino Documentation](https://docs.arduino.cc/) also contains articles explaining how to debug via [Segger J-Link](https://docs.arduino.cc/tutorials/portenta-breakout/breakout-jlink-setup) and [Lauterbach TRACE32](https://docs.arduino.cc/tutorials/portenta-h7/lauterbach-debugger).
10+
511
## Installation
612

713
### Clone the repository in `$sketchbook/hardware/arduino-git`
@@ -37,32 +43,71 @@ fork/exec /bin/arm-none-eabi-g++: no such file or directory
3743
```
3844
To install ARM build tools, use the `Boards Manager` option in the Arduino IDE to add the `Arduino mbed-enabled Boards` package.
3945

46+
## mbed-os-to-arduino script
47+
48+
The backbone of the packaging process is the https://github.com/arduino/ArduinoCore-mbed/blob/master/mbed-os-to-arduino script. It basically compiles a blank Mbed OS project for any supported target board, recovering the files that will be needed at compile time and copying them to the right location.
49+
50+
It can be used for a variety of tasks including:
51+
52+
### Recompiling libmbed with source level debug support
53+
54+
```
55+
cd $sketchbook/hardware/arduino-git/mbed
56+
./mbed-os-to-arduino -a -g PORTENTA_H7_M7:PORTENTA_H7_M7
57+
```
58+
59+
In this case `-a` applies all the patches from `patches` folder into a mainline `mbed-os` tree, and `-g` restores the debug info.
60+
61+
### Selecting a different optimization profile
62+
63+
```
64+
cd $sketchbook/hardware/arduino-git/mbed
65+
PROFILE=release ./mbed-os-to-arduino -a NANO_RP2040_CONNECT:NANO_RP2040_CONNECT
66+
```
67+
68+
The `PROFILE` environment variable tunes the compilation profiles (defaults to `DEVELOP`). Other available profiles are `DEBUG` and `RELEASE`.
69+
70+
### Selecting a different Mbed OS tree
71+
72+
```
73+
cd $sketchbook/hardware/arduino-git/mbed
74+
./mbed-os-to-arduino -r /path/to/my/mbed-os-fork NICLA_VISION:NICLA_VISION
75+
```
76+
77+
`-r` flag allows using a custom `mbed-os` fork in place of the mainline one; useful during new target development.
78+
79+
### Adding a new target ([core variant](https://arduino.github.io/arduino-cli/latest/platform-specification/#core-variants))
4080

41-
## Adding an mbed target
81+
Adding a target is a mostly automatic procedure.
4282

43-
Adding a target is a mostly automatic procedure that involves running https://github.com/arduino/ArduinoCore-mbed/blob/master/mbed-os-to-arduino after setting the `BOARDNAME` and `ARDUINOCORE` env variables.
44-
Actions marked as TODO must be executed manually.
83+
For boards already supported by Mbed OS, the bare minimum is:
4584

46-
**Minimum Example**:
4785
```
4886
cd $sketchbook/hardware/arduino-git/mbed
49-
./mbed-os-to-arduino -r /home/alex/projects/arduino/cores/mbed-os-h747 PORTENTA_H7_M7:PORTENTA_H7_M7
87+
mkdir -p variants/$ALREADY_SUPPORTED_BOARD_NAME/{libs,conf}
88+
./mbed-os-to-arduino $ALREADY_SUPPORTED_BOARD_NAME:$ALREADY_SUPPORTED_BOARD_NAME
89+
# for example, to create a core for LPC546XX
90+
# mkdir -p variants/LPC546XX/{libs,conf}
91+
# ./mbed-os-to-arduino LPC546XX:LPC546XX
5092
```
5193

52-
### How to build a debug version of the Arduino mbed libraries
53-
* Modify `mbed-os-to-arduino `
54-
```diff
55-
mbed_compile () {
56-
- PROFILE_FLAG=""
57-
if [ x"$PROFILE" != x ]; then
58-
PROFILE_FLAG=--profile="$ARDUINOVARIANT"/conf/profile/$PROFILE.json
59-
export PROFILE=-${PROFILE^^}
60-
+ else
61-
+ export PROFILE="-DEBUG"
62-
+ PROFILE_FLAG="--profile=debug"
63-
fi
94+
This will produce almost all the files needed. To complete the port, add the board specifications to [`boards.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardstxt) (giving it a unique ID) and provide `pins_arduino.h` and `variants.cpp` in `variants/$ALREADY_SUPPORTED_BOARD_NAME` folder.
95+
Feel free to take inspirations from the existing variants :)
96+
97+
For boards not supported by mainline Mbed OS, the same applies but you should provide the path of your Mbed OS fork
98+
99+
```
100+
cd $sketchbook/hardware/arduino-git/mbed
101+
mkdir -p variants/$BRAND_NEW_BOARD_NAME/{libs,conf}
102+
./mbed-os-to-arduino -r /path/to/mbed-os/fork/that/supports/new/board $BRAND_NEW_BOARD_NAME:$BRAND_NEW_BOARD_NAME
64103
```
65104

105+
### Customizing Mbed OS build without modifying the code
106+
107+
Most Mbed OS defines can be tuned using a project file called `mbed_app.json` . In case you need to tune a build you can add that file to your variant's `conf` folder. One example is https://github.com/arduino/ArduinoCore-mbed/blob/master/variants/PORTENTA_H7_M7/conf/mbed_app.json .
108+
Providing an invalid json or replacing a non-existing property will make the build fail silently, so it's always better to validate that file with a standard Mbed OS project.
109+
110+
66111
## Using this core as an mbed library
67112

68113
You can use this core as a standard mbed library; all APIs are under `arduino` namespace (so they must be called like `arduino::digitalWrite()` )

mbed-os-to-arduino

+10-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ apply_patches () {
112112
cd -
113113
fi
114114
echo " done."
115+
if [ "$RESTORE_GDB_INFO" -eq 1 ]; then
116+
echo "Restoring gdb info (this increases libmbed binary size, not suitable for release)"
117+
cd mbed-os
118+
git checkout tools/profiles/develop.json
119+
cd -
120+
fi
115121
fi
116122
}
117123

@@ -277,11 +283,12 @@ patch_spi_h () {
277283
# MAIN LOOP #
278284
#############
279285

280-
while getopts "cuar:b:p:" opt; do
286+
while getopts "cuagr:b:p:" opt; do
281287
case $opt in
282288
c ) export MBED_CLEAN=1 ;;
283289
u ) export MBED_UPDATE=1 ;;
284290
a ) export APPLY_PATCHES=1 ;;
291+
g ) export RESTORE_GDB_INFO=1 ;;
285292
r ) export LOCAL_REPO="$OPTARG" ;;
286293
b ) export REMOTE_BRANCH="$OPTARG" ;;
287294
p )
@@ -329,13 +336,15 @@ export MBED_CORE_LOCATION=${MBED_CORE_LOCATION:-$PWD}
329336
export MBED_CLEAN=${MBED_CLEAN:-0}
330337
export MBED_UPDATE=${MBED_UPDATE:-0}
331338
export APPLY_PATCHES=${APPLY_PATCHES:-0}
339+
export RESTORE_GDB_INFO=${RESTORE_GDB_INFO:-0}
332340
export LOCAL_REPO=${LOCAL_REPO:-""}
333341
export REMOTE_BRANCH=${REMOTE_BRANCH:-""}
334342

335343
echo
336344
echo MBED_CLEAN=$MBED_CLEAN
337345
echo MBED_UPDATE=$MBED_UPDATE
338346
echo APPLY_PATCHES=$APPLY_PATCHES
347+
echo RESTORE_GDB_INFO=$RESTORE_GDB_INFO
339348
echo LOCAL_REPO="$LOCAL_REPO"
340349
echo REMOTE_BRANCH="$REMOTE_BRANCH"
341350
echo MBED_CORE_LOCATION="$MBED_CORE_LOCATION"

0 commit comments

Comments
 (0)