forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbed-os-to-arduino
27 lines (21 loc) · 1.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
export BOARDNAME=DISCO_F429ZI
export ARDUINOCORE=~/ArduinoCore-mbed/variant/$BOARDNAME/
mbed new mbed-os-program
cd mbed-os-program
mbed target $BOARDNAME
mbed toolchain GCC_ARM
echo -e "#include \"mbed.h\"\nint main() {Thread thd;}" > main.cpp
mbed compile -v | grep "Macros:" > $BOARDNAME.macros.txt
cat $BOARDNAME.macros.txt | cut -f2 -d":" > $ARDUINOCORE/defines.txt
xargs -n 1 < ./BUILD/$BOARDNAME/GCC_ARM/.include* | sed -e 's#./mbed-os#{build.core.path}/mbed#g' | sed -e 's#-I/.*$##' | tac > $ARDUINOCORE/includes.txt
#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
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"`
cd mbed-os && find . | grep "\.h" | xargs -I % cp --parents % $ARDUINOCORE/../../cores/arduino/mbed
cd BUILD && find . | grep "\.h" | xargs -I % cp % $ARDUINOCORE/../../cores/arduino/mbed
# find a way to extract PinNames.h and device.h
# patch Callback.h
# copy linker script (eg. BUILD/DISCO_F429ZI/GCC_ARM/.link_script.ld)
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