-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathmbed-os-to-arduino
executable file
·134 lines (107 loc) · 4.09 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash -ex
MBED_CORE_LOCATION=$1
BOARDNAMES=(MTB_MURATA_ABZ)
#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
rm -rf .mbedignore
mbed target $BOARDNAME
mbed toolchain GCC_ARM
echo -e "#include \"mbed.h\"\nint main() {}" > main.cpp
echo -e "{
\"macros\": [
\"MBED_HEAP_STATS_ENABLED=1\",
\"MBED_STACK_STATS_ENABLED=1\",
\"MBED_MEM_TRACING_ENABLED=1\"
],
\"target_overrides\": {
\"*\": {
\"platform.stdio-buffered-serial\": true,
\"platform.stdio-baud-rate\": 115200,
\"platform.default-serial-baud-rate\": 115200
}
}
}" > mbed_app.json
if [ $BOARDNAME == "ARDUINO_NANO33BLE" ]; then
echo -e "{
\"macros\": [
\"MBED_HEAP_STATS_ENABLED=1\",
\"MBED_STACK_STATS_ENABLED=1\",
\"MBED_MEM_TRACING_ENABLED=1\",
\"NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=8\"
],
\"target_overrides\": {
\"*\": {
\"platform.stdio-buffered-serial\": true,
\"platform.stdio-baud-rate\": 115200,
\"platform.default-serial-baud-rate\": 115200,
\"rtos.main-thread-stack-size\": 32768,
\"target.mbed_app_start\": \"0x10000\"
}
}
}" > mbed_app.json
fi
if [ -d $ARDUINOCORE/conf ]; then
cp -r $ARDUINOCORE/conf/* .
fi
if [ -d $ARDUINOCORE/conf/profile/ ]; then
PROFILE=$ARDUINOCORE/conf/profile/custom.json
fi
#set +e
#mbed update
#set -e
rm -rf BUILD
if [ $PROFILE == "" ]; then
FOLDER=GCC_ARM
else
FOLDER=GCC_ARM-CUSTOM
fi
if [ $PROFILE == "" ]; then
mbed compile --source . --source ./mbed-os/features/unsupported/dsp/ -v | grep "Macros:" > $BOARDNAME.macros.txt
else
mbed compile --profile $PROFILE --source . --source ./mbed-os/features/unsupported/dsp/ -v | grep "Macros:" > $BOARDNAME.macros.txt
fi
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/$FOLDER/.include* | sed -e 's#-I./mbed-os#-iwithprefixbefore/mbed#g' | sed '/^-I./ d' | tac > $ARDUINOCORE/includes.txt
./gron ./BUILD/$BOARDNAME/$FOLDER/.profile-c | grep json.flags | cut -f2 -d"\"" | grep -v "json.flags" | grep -v "MMD" > $ARDUINOCORE/cflags.txt
./gron ./BUILD/$BOARDNAME/$FOLDER/.profile-cxx | grep json.flags | cut -f2 -d"\"" | grep -v "json.flags" | grep -v "MMD" > $ARDUINOCORE/cxxflags.txt
./gron ./BUILD/$BOARDNAME/$FOLDER/.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/$FOLDER/.link_options.txt | grep "\.o" | grep -v "/main\.o"`
cp BUILD/mbed-core-$BOARDNAME.a $ARDUINOCORE/libs/libmbed.a
cp ./BUILD/$BOARDNAME/$FOLDER/.link_script.ld $ARDUINOCORE/linker_script.ld
cp ./BUILD/$BOARDNAME/$FOLDER/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