|
2 | 2 |
|
3 | 3 | The repository contains the Arduino APIs and IDE integration files targeting a generic mbed-enabled board
|
4 | 4 |
|
| 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 | + |
5 | 11 | ## Installation
|
6 | 12 |
|
7 | 13 | ### Clone the repository in `$sketchbook/hardware/arduino-git`
|
@@ -37,32 +43,71 @@ fork/exec /bin/arm-none-eabi-g++: no such file or directory
|
37 | 43 | ```
|
38 | 44 | To install ARM build tools, use the `Boards Manager` option in the Arduino IDE to add the `Arduino mbed-enabled Boards` package.
|
39 | 45 |
|
| 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)) |
40 | 80 |
|
41 |
| -## Adding an mbed target |
| 81 | +Adding a target is a mostly automatic procedure. |
42 | 82 |
|
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: |
45 | 84 |
|
46 |
| -**Minimum Example**: |
47 | 85 | ```
|
48 | 86 | 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 |
50 | 92 | ```
|
51 | 93 |
|
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 |
64 | 103 | ```
|
65 | 104 |
|
| 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 | + |
66 | 111 | ## Using this core as an mbed library
|
67 | 112 |
|
68 | 113 | You can use this core as a standard mbed library; all APIs are under `arduino` namespace (so they must be called like `arduino::digitalWrite()` )
|
|
0 commit comments