-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathmbed-os-to-arduino
48 lines (31 loc) · 2.54 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
export BOARDNAME=DISCO_F429ZI
export ARDUINOCORE=~/ArduinoCore-mbed/variants/$BOARDNAME/
mbed new mbed-os-program
cd mbed-os-program
# cd mbed-os && git checkout --track origin/feature-hal-spec-usb-device && cd ..
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/
# add #include "mbed_config.h" in "mbed.h"
cd mbed-os && find . | grep "\.h" | xargs -I % cp --parents % $ARDUINOCORE/../../cores/arduino/mbed && cd ..
openocd -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfg -c "init" -c "reset init" -c "halt" -c "flash write_image erase ./BUILD/$BOARDNAME/GCC_ARM/mbed-os-program.elf" -c "verify_image ./BUILD/$BOARDNAME/GCC_ARM/mbed-os-program.elf" -c "reset run" -c shutdown
##################
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