forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbed-os-to-arduino
executable file
·80 lines (59 loc) · 3.58 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash -ex
MBED_CORE_LOCATION=$1
BOARDNAMES=(ARDUINO_NANO33BLE)
#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/
if [ -d $ARDUINOCORE ]; then
mkdir -p $ARDUINOCORE/libs
fi
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\"rtos.main-thread-stack-size\": 32768,\n\"platform.stdio-baud-rate\": 115200,\n\"platform.default-serial-baud-rate\": 115200\n}\n}\n}\n" > mbed_app.json
if [ $BOARDNAME == "ARDUINO_NANO33BLE" ]; then
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\"rtos.main-thread-stack-size\": 32768,\n\"target.mbed_app_start\": \"0x10000\"}\n}\n}\n" > mbed_app.json
fi
rm -rf BUILD
mbed compile -v | grep "Macros:" > $BOARDNAME.macros.txt
cat $BOARDNAME.macros.txt | cut -f2 -d":" | sed 's# #\n#g' | sed 's#\"#\\"#g' | sort > $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
./gron ./BUILD/$BOARDNAME/GCC_ARM/.profile-c | grep json.flags | cut -f2 -d"\"" | grep -v "json.flags" | grep -v "MMD" > $ARDUINOCORE/cflags.txt
./gron ./BUILD/$BOARDNAME/GCC_ARM/.profile-cxx | grep json.flags | cut -f2 -d"\"" | grep -v "json.flags" | grep -v "MMD" > $ARDUINOCORE/cxxflags.txt
./gron ./BUILD/$BOARDNAME/GCC_ARM/.profile-ld | grep json.flags | cut -f2 -d"\"" | grep -v "json.flags" | grep -v "MMD" > $ARDUINOCORE/ldflags.txt
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 ..
cp mbed-os/platform/cxxsupport/mstd_* $ARDUINOCORE/../../cores/arduino/mbed/platform/cxxsupport/
#TODO: add #include "mbed_config.h" in "mbed.h"
#TODO: rename drivers/SPI.h in drivers/SPIMaster.h and modify include in mbed.h
mv $ARDUINOCORE/../../cores/arduino/mbed/drivers/SPI.h $ARDUINOCORE/../../cores/arduino/mbed/drivers/SPIMaster.h
# TODO
# - Add -DUSE_ARDUINO_PINOUT to targets with a variant.cpp
# - Add include path for rpc library to envie
# - Remove -fno-exception from Envie cppflags
#
#
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