-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathmbed-os-to-arduino
executable file
·65 lines (46 loc) · 2.62 KB
/
mbed-os-to-arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash -ex
MBED_CORE_LOCATION=$1
BOARDNAMES=(ENVIE_M4 MBED_CONNECT_ODIN NRF52840_DK)
#always work in /tmp
cd /tmp/
if [ ! -d mbed-os-program ]; then
mbed new mbed-os-program
fi
cd mbed-os-program
# checkout the mbed-os version you prefer
# cd mbed-os && git checkout --track origin/feature-hal-spec-usb-device && cd ..
if [ ! -f gron ]; then
echo "Please copy gron executable here"
exit 1
fi
for BOARDNAME in "${BOARDNAMES[@]}"
do
export ARDUINOCORE=$MBED_CORE_LOCATION/variants/$BOARDNAME/
mbed target $BOARDNAME
mbed toolchain GCC_ARM
echo -e "#include \"mbed.h\"\nint main() {Thread thd;}" > main.cpp
echo -e "{\n\"macros\": [\n\"MBED_HEAP_STATS_ENABLED=1\",\n\"MBED_STACK_STATS_ENABLED=1\",\n\"MBED_MEM_TRACING_ENABLED=1\"\n],\n\"target_overrides\": {\n \"*\": {\n\"platform.stdio-buffered-serial\": true,\n\"platform.stdio-baud-rate\": 115200,\n\"platform.default-serial-baud-rate\": 115200\n}\n}\n}\n" > mbed_app.json
mbed compile -v | grep "Macros:" > $BOARDNAME.macros.txt
cat $BOARDNAME.macros.txt | cut -f2 -d":" > $ARDUINOCORE/defines.txt
echo " -DMBED_NO_GLOBAL_USING_DIRECTIVE=1" >> $ARDUINOCORE/defines.txt
xargs -n 1 < ./BUILD/$BOARDNAME/GCC_ARM/.include* | sed -e 's#-I./mbed-os#-iwithprefixbefore/mbed#g' | sed '/^-I./ d' | tac > $ARDUINOCORE/includes.txt
#TODO: remove -I{build.core.path}/mbed/drivers from includes.txt (name clashing with libraries)
#TODO: remove -MDD from flags
./gron ./BUILD/$BOARDNAME/GCC_ARM/.profile-c | grep json.flags | cut -f2 -d"\"" > $ARDUINOCORE/cflags.txt
./gron ./BUILD/$BOARDNAME/GCC_ARM/.profile-cxx | grep json.flags | cut -f2 -d"\"" > $ARDUINOCORE/cxxflags.txt
./gron ./BUILD/$BOARDNAME/GCC_ARM/.profile-ld | grep json.flags | cut -f2 -d"\"" > $ARDUINOCORE/ldflags.txt
#TODO: sanitize gron output (or move to python)
arm-none-eabi-ar rcs BUILD/mbed-core-$BOARDNAME.a `xargs -n 1 < ./BUILD/$BOARDNAME/GCC_ARM/.link_options.txt | grep "\.o" | grep -v "main.o"`
cp BUILD/mbed-core-$BOARDNAME.a $ARDUINOCORE/libs/libmbed.a
cp ./BUILD/$BOARDNAME/GCC_ARM/.link_script.ld $ARDUINOCORE/linker_script.ld
cp ./BUILD/$BOARDNAME/GCC_ARM/mbed_config.h $ARDUINOCORE/
done
rm -rf $ARDUINOCORE/../../cores/arduino/mbed/*
cd mbed-os && find . | grep "\.h" | xargs -I % cp --parents % $ARDUINOCORE/../../cores/arduino/mbed && cd ..
#TODO: add #include "mbed_config.h" in "mbed.h"
exit 0
##################
Using Arduino as an mbed library
echo -e "arduino/cores/arduino/main.cpp\n arduino/cores/arduino/mbed/\narduino/libraries/" > .mbedignore
#add ARDUINO_AS_MBED_LIBRARY=1 to macros section in mbed_app.json
echo "https://github.com/arduino/ArduinoCore-mbed#bf6e64771ebe20285b0364756dff856ebbc679dc" > arduino.lib