|
| 1 | +/***************************************************************************//** |
| 2 | + * @file HelloMo.ino |
| 3 | + * @brief Arduino RT-Thread library "HelloMo" example |
| 4 | + * @author onelife <onelife.real[at]gmail.com> |
| 5 | + ******************************************************************************/ |
| 6 | +#include <rtt.h> |
| 7 | + |
| 8 | +/* ATTENTION |
| 9 | + The following flags in "rtconfig.h" must be turned on: |
| 10 | + - CONFIG_USING_MODULE |
| 11 | + */ |
| 12 | + |
| 13 | +/* NOTES |
| 14 | + To build code as "MO" file: |
| 15 | + 1. Compile |
| 16 | + - you may copy the compiling command from Arduino's output window (select |
| 17 | + [File-> Preferences-> Show verbose output during: compilation] if you |
| 18 | + can't see the command) |
| 19 | + - add options "-mlong-calls -fPIC" |
| 20 | + |
| 21 | + 2. Link |
| 22 | + - you may copy the compiling command from Arduino's output window |
| 23 | + - keep only "hello_mo.c.o" |
| 24 | + - remove option "-Wl,--unresolved-symbols=report-all" |
| 25 | + - remove option "-LC:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_362673" |
| 26 | + - remove option "-TC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\variants\\mkrzero/linker_scripts/gcc/flash_with_bootloader.ld" |
| 27 | + - remove option: "-Wl,--start-group ... -Wl,--end-group" |
| 28 | + - add options "-shared -fPIC -nostdlib -Wl,-marmelf -Wl,-z,max-page-size=0x4" |
| 29 | + - add option to set entry point (e.g. "-Wl,-esay_hello") |
| 30 | + |
| 31 | + 3. Strip |
| 32 | + - use "arm-none-eabi-strip" |
| 33 | + |
| 34 | + To build code as "SO" file: |
| 35 | + 1. Compile |
| 36 | + - same as above |
| 37 | + |
| 38 | + 2. Link |
| 39 | + - same as above, but |
| 40 | + - add option to set entry point to NULL (e.g. "-Wl,-e0") |
| 41 | + |
| 42 | + 3. Strip |
| 43 | + - use "arm-none-eabi-strip" |
| 44 | + */ |
| 45 | + |
| 46 | +void setup() { |
| 47 | + RT_T.begin(); |
| 48 | + // no code here as RT_T.begin() never return |
| 49 | +} |
| 50 | + |
| 51 | +// this function will be called by "Arduino" thread |
| 52 | +void loop() { |
| 53 | + // may put some code here that will be run repeatedly |
| 54 | +} |
| 55 | + |
| 56 | +/* EXAMPLE |
| 57 | + |
| 58 | +To build "hello_mo.c" as "SO" file: |
| 59 | + |
| 60 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m0plus -mthumb -c -g -Os -mlong-calls -fPIC -Wall -Wextra -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_MKRZERO -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804f -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKRZero\"" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\4円.5.0/CMSIS/Include/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\1円.1.0/CMSIS/Device/ATMEL/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\cores\\arduino" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\variants\\mkrzero" "-IC:\\Users\\onelife\\Documents\\Arduino\\libraries\\RT-Thread\\src" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\libraries\\SPI" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c.o" |
| 61 | + |
| 62 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-g++" -Os -shared -fPIC -nostdlib -Wl,-e0 -Wl,-marmelf -Wl,-z,max-page-size=0x4 -Wl,--gc-sections -save-temps "-Wl,-Map,C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--warn-common -Wl,--warn-section-align -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c.o" |
| 63 | + |
| 64 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-strip" -R .hash -R .comment -R .ARM.attributes "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello.so" |
| 65 | + |
| 66 | + |
| 67 | +To build "load_mo.c" as "MO" file: |
| 68 | + |
| 69 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m0plus -mthumb -c -g -Os -mlong-calls -fPIC -Wall -Wextra -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_MKRZERO -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804f -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKRZero\"" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\4円.5.0/CMSIS/Include/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\1円.1.0/CMSIS/Device/ATMEL/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\cores\\arduino" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\variants\\mkrzero" "-IC:\\Users\\onelife\\Documents\\Arduino\\libraries\\RT-Thread\\src" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\libraries\\SPI" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\load_mo.c" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\load_mo.c.o" |
| 70 | + |
| 71 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-g++" -Os -shared -fPIC -nostdlib -Wl,-eload_hello -Wl,-marmelf -Wl,-z,max-page-size=0x4 -Wl,--gc-sections -save-temps "-Wl,-Map,C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load_mo.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--warn-common -Wl,--warn-section-align -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load_mo.elf" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\load_mo.c.o" |
| 72 | + |
| 73 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-strip" -R .hash -R .comment -R .ARM.attributes "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load_mo.elf" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load.mo" |
| 74 | + |
| 75 | + |
| 76 | +To build "hello_mo.c" as "MO" file (change a link option and output name): |
| 77 | + |
| 78 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-g++" -Os -shared -fPIC -nostdlib -Wl,-esay_hello -Wl,-marmelf -Wl,-z,max-page-size=0x4 -Wl,--gc-sections -save-temps "-Wl,-Map,C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--warn-common -Wl,--warn-section-align -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c.o" |
| 79 | + |
| 80 | +"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-strip" -R .hash -R .comment -R .ARM.attributes "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello.mo" |
| 81 | + |
| 82 | + */ |
0 commit comments