diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8be22ed65..d76bf654e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: with: path: checkout/ - - name: Build OpenCR and Teensy 3.2/4.1 + - name: Build run: | apt update apt install -y git curl lib32z1 wget libfontconfig libxft2 xz-utils rsync @@ -28,21 +28,34 @@ jobs: - https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json''' > arduino-cli.yaml export PATH=$PATH:/github/workspace/bin:/__w/micro_ros_arduino/micro_ros_arduino/bin arduino-cli core install OpenCR:OpenCR -v + arduino-cli core install arduino:samd -v + arduino-cli core install arduino:sam -v + # + # INSTALLING TEENSY SUPPORT wget https://downloads.arduino.cc/arduino-1.8.13-linux64.tar.xz tar -xf arduino-1.8.13-linux64.tar.xz wget https://www.pjrc.com/teensy/td_153/TeensyduinoInstall.linux64 chmod 755 TeensyduinoInstall.linux64 ./TeensyduinoInstall.linux64 --dir=arduino-1.8.13 - # Faking loader + # Faking Teensy loader TRUE_PATH=$(which true) rm -rf arduino-1.8.13/hardware/tools/teensy_post_compile cp $TRUE_PATH arduino-1.8.13/hardware/tools/teensy_post_compile cp -R arduino-1.8.13/hardware/teensy/ /github/home/.arduino15/packages/ rsync -a arduino-1.8.13/hardware/tools/ /github/home/.arduino15/packages/tools/ - rm -rf arduino-1.8.13 - curl https://raw.githubusercontent.com/micro-ROS/micro_ros_arduino/foxy/extras/library_generation/platform_teensy.txt > /github/home/.arduino15/packages/teensy/avr/platform.txt + rm -rf arduino-1.8.13 arduino-1.8.13-linux64.tar.xz + # + # PATCHING TEENSY AND SAM + cat checkout/extras/patching_boards/platform_teensy.txt > /github/home/.arduino15/packages/teensy/avr/platform.txt + # remove when https://github.com/arduino/ArduinoCore-sam/pull/115 merged + cat checkout/extras/patching_boards/platform_arduinocore_sam.txt > /github/home/.arduino15/packages/arduino/hardware/sam/1.6.12/platform.txt + # + # BUILDING EXAPLE FOR EACH PLATFORM arduino-cli core update-index arduino-cli lib update-index arduino-cli compile --fqbn OpenCR:OpenCR:OpenCR /github/home/Arduino/libraries/micro_ros_arduino-0.0.1/examples/micro-ros_publisher -v arduino-cli compile --fqbn teensy:avr:teensy31 /github/home/Arduino/libraries/micro_ros_arduino-0.0.1/examples/micro-ros_publisher -v arduino-cli compile --fqbn teensy:avr:teensy41 /github/home/Arduino/libraries/micro_ros_arduino-0.0.1/examples/micro-ros_publisher -v + arduino-cli compile --fqbn arduino:samd:arduino_zero_native /github/home/Arduino/libraries/micro_ros_arduino-0.0.1/examples/micro-ros_publisher -v + arduino-cli compile --fqbn arduino:sam:arduino_due_x /github/home/Arduino/libraries/micro_ros_arduino-0.0.1/examples/micro-ros_publisher -v + arduino-cli compile --fqbn arduino:sam:arduino_due_x /github/home/Arduino/libraries/micro_ros_arduino-0.0.1/examples/micro-ros_custom_transport -v diff --git a/README.md b/README.md index 0a4519f03..f29de47f9 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@ Supported boards are: | [Teensy 4.1](https://www.pjrc.com/store/teensy41.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon.meta` | | [Teensy 3.2/3.1](https://www.pjrc.com/store/teensy32.html) | v1.8.5 | Supported | [Based on Teensyduino](https://www.pjrc.com/teensy/td_download.html) | `colcon_lowmem.meta` | +Community contributed boards are: + +| Board | Min version | Contributor | Details | Prebuild meta | +| ----------------------------------------------------- | ----------- | ------------ | ------- | ------------------------ | +| [Arduino Due](https://store.arduino.cc/arduino-due) | - | @lukicdarkoo | | `colcon_verylowmem.meta` | +| [Arduino Zero](https://store.arduino.cc/arduino-zero) | - | @lukicdarkoo | | `colcon_verylowmem.meta` | + + You can find the available precompiled ROS 2 types for messages and services in [available_ros2_types](available_ros2_types). ## How to use the precompiled library @@ -42,14 +50,25 @@ docker run -it --rm -v $(pwd):/arduino_project microros/micro_ros_arduino_builde ``` Note that folders added to `extras/library_generation/extra_packages` and entries added to `extras/library_generation/extra_packages/extra_packages.repos` will be taken into account by this build system. -## Patch Teensyduino +## Patch Arduino board for support precompiled libraries +### Patch Teensyduino Go inside your Arduino + Teensyduino installation and replace `platform.txt`: ```bash export ARDUINO_PATH=[Your Arduino + Teensiduino path] cd $ARDUINO_PATH/hardware/teensy/avr/ -curl https://raw.githubusercontent.com/micro-ROS/micro_ros_arduino/foxy/extras/library_generation/platform_teensy.txt > platform.txt +curl https://raw.githubusercontent.com/micro-ROS/micro_ros_arduino/foxy/extras/patching_boards/platform_teensy.txt > platform.txt +``` + +### Patch SAMD + +Go inside your Arduino + Teensyduino installation and replace `platform.txt`: + +```bash +export ARDUINO_PATH=[Your Arduino path] +cd $ARDUINO_PATH/hardware/sam/1.6.12/ +curl https://raw.githubusercontent.com/micro-ROS/micro_ros_arduino/foxy/extras/patching_boards/platform_arduinocore_sam.txt > platform.txt ``` ## Purpose of the Project diff --git a/examples/micro-ros_custom_transport/micro-ros_custom_transport.ino b/examples/micro-ros_custom_transport/micro-ros_custom_transport.ino new file mode 100644 index 000000000..16af1f8ab --- /dev/null +++ b/examples/micro-ros_custom_transport/micro-ros_custom_transport.ino @@ -0,0 +1,87 @@ +#include + +#include +#include +#include +#include +#include + +#include + +rcl_publisher_t publisher; +std_msgs__msg__Int32 msg; +rclc_executor_t executor; +rclc_support_t support; +rcl_allocator_t allocator; +rcl_node_t node; +rcl_timer_t timer; + +#define LED_PIN 13 + +#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}} +#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}} + + +void error_loop(){ + while(1){ + digitalWrite(LED_PIN, !digitalRead(LED_PIN)); + delay(100); + } +} + +void timer_callback(rcl_timer_t * timer, int64_t last_call_time) +{ + RCLC_UNUSED(last_call_time); + if (timer != NULL) { + RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL)); + msg.data++; + } +} + +void setup() { + + pinMode(LED_PIN, OUTPUT); + digitalWrite(LED_PIN, HIGH); + + delay(2000); + + allocator = rcl_get_default_allocator(); + + //create init_options + RCCHECK(rclc_support_init(&support, 0, NULL, &allocator)); + + // create node + node = rcl_get_zero_initialized_node(); + RCCHECK(rclc_node_init_default(&node, "micro_ros_arduino_node", "", &support)); + + // create publisher + RCCHECK(rclc_publisher_init_default( + &publisher, + &node, + ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), + "micro_ros_arduino_node_publisher")); + + // create timer, + timer = rcl_get_zero_initialized_timer(); + const unsigned int timer_timeout = 1000; + RCCHECK(rclc_timer_init_default( + &timer, + &support, + RCL_MS_TO_NS(timer_timeout), + timer_callback)); + + // create executor + executor = rclc_executor_get_zero_initialized_executor(); + RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator)); + + unsigned int rcl_wait_timeout = 100; // in ms + RCCHECK(rclc_executor_set_timeout(&executor, RCL_MS_TO_NS(rcl_wait_timeout))); + RCCHECK(rclc_executor_add_timer(&executor, &timer)); + + msg.data = 0; +} + +void loop() { + delay(100); + RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100))); +} diff --git a/examples/micro-ros_custom_transport/my_custom_transport.cpp b/examples/micro-ros_custom_transport/my_custom_transport.cpp new file mode 100644 index 000000000..32f35b216 --- /dev/null +++ b/examples/micro-ros_custom_transport/my_custom_transport.cpp @@ -0,0 +1,45 @@ +#include + +// This is a working example of how to use micro-ROS with user defined transports. +// These functions should be filled with custom transport code and they will replace +// the weak functions defined in the custom transport in the library. + +extern "C" +{ +#include +#include +#include + + bool arduino_serial_platform_open() + { + // Place here your initialization platform code + // Return true if success + Serial2.begin(115200); + return true; + } + + bool arduino_serial_platform_close() + { + // Place here your closing platform code + // Return true if success + return true; + } + + size_t arduino_serial_platform_write(uint8_t *buf, size_t len, uint8_t *errcode) + { + // Place here your writing bytes platform code + // Return number of bytes written + (void)errcode; + size_t sent = Serial2.write(buf, len); + return sent; + } + + size_t arduino_serial_platform_read(uint8_t *buf, size_t len, int timeout, uint8_t *errcode) + { + // Place here your reading bytes platform code + // Return number of bytes read (max bytes: len) + (void)errcode; + Serial2.setTimeout(timeout); + return Serial2.readBytes((char *)buf, len); + } +} diff --git a/extras/library_generation/Dockerfile b/extras/library_generation/Dockerfile index 8535e2416..d721e2878 100644 --- a/extras/library_generation/Dockerfile +++ b/extras/library_generation/Dockerfile @@ -18,7 +18,10 @@ RUN git clone https://github.com/micro-ROS/micro-ros-build.git src/micro-ros-bui && rm -rf gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2 gcc-arm-none-eabi-5_4-2016q2/share/doc \ && wget https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 \ && tar -xvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 \ - && rm -rf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 gcc-arm-none-eabi-5_4-2016q3/share/doc + && rm -rf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 gcc-arm-none-eabi-5_4-2016q3/share/doc \ + && wget https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 \ + && tar -xvf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 \ + && rm -rf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 gcc-arm-none-eabi-4_8-2014q1/share/doc COPY ./entrypoint.sh /entrypoint.sh diff --git a/extras/library_generation/colcon_verylowmem.meta b/extras/library_generation/colcon_verylowmem.meta new file mode 100644 index 000000000..26afdb583 --- /dev/null +++ b/extras/library_generation/colcon_verylowmem.meta @@ -0,0 +1,51 @@ +{ + "names": { + "tracetools": { + "cmake-args": [ + "-DTRACETOOLS_DISABLED=ON", + "-DTRACETOOLS_STATUS_CHECKING_TOOL=OFF" + ] + }, + "rosidl_typesupport": { + "cmake-args": [ + "-DROSIDL_TYPESUPPORT_SINGLE_TYPESUPPORT=ON" + ] + }, + "rcl": { + "cmake-args": [ + "-DBUILD_TESTING=OFF", + "-DRCL_COMMAND_LINE_ENABLED=OFF", + "-DRCL_LOGGING_ENABLED=OFF" + ] + }, + "rcutils": { + "cmake-args": [ + "-DENABLE_TESTING=OFF", + "-DRCUTILS_NO_FILESYSTEM=ON", + "-DRCUTILS_NO_THREAD_SUPPORT=ON", + "-DRCUTILS_NO_64_ATOMIC=ON", + "-DRCUTILS_AVOID_DYNAMIC_ALLOCATION=ON" + ] + }, + "microxrcedds_client": { + "cmake-args": [ + "-DUCLIENT_PIC=OFF", + "-DUCLIENT_PROFILE_UDP=OFF", + "-DUCLIENT_PROFILE_DISCOVERY=OFF", + "-DUCLIENT_PROFILE_SERIAL=ON", + "-DUCLIENT_EXTERNAL_SERIAL=ON" + ] + }, + "rmw_microxrcedds": { + "cmake-args": [ + "-DRMW_UXRCE_MAX_NODES=1", + "-DRMW_UXRCE_MAX_PUBLISHERS=2", + "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=1", + "-DRMW_UXRCE_MAX_SERVICES=0", + "-DRMW_UXRCE_MAX_CLIENTS=1", + "-DRMW_UXRCE_MAX_HISTORY=1", + "-DRMW_UXRCE_TRANSPORT=custom_serial" + ] + } + } +} diff --git a/extras/library_generation/cortex_m0_toolchain.cmake b/extras/library_generation/cortex_m0_toolchain.cmake new file mode 100644 index 000000000..5b7754331 --- /dev/null +++ b/extras/library_generation/cortex_m0_toolchain.cmake @@ -0,0 +1,16 @@ +SET(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_CROSSCOMPILING 1) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc) +set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++) + +SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "") +SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "") + +set(FLAGS "-O2 -fsingle-precision-constant -ffunction-sections -fdata-sections -fno-exceptions -mcpu=cortex-m0 -nostdlib -mthumb -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE) + +set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) + +set(__BIG_ENDIAN__ 0) diff --git a/extras/library_generation/cortex_m3_toolchain.cmake b/extras/library_generation/cortex_m3_toolchain.cmake new file mode 100644 index 000000000..57e4d0948 --- /dev/null +++ b/extras/library_generation/cortex_m3_toolchain.cmake @@ -0,0 +1,16 @@ +SET(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_CROSSCOMPILING 1) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc) +set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++) + +SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "") +SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "") + +set(FLAGS "-O2 -ffunction-sections -fdata-sections -fno-exceptions -mcpu=cortex-m3 -nostdlib -DARDUINO=10813 -mthumb --param max-inline-insns-single=500 -DF_CPU=84000000L -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE) + +set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_INIT "-std=c++11 ${FLAGS} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE) + +set(__BIG_ENDIAN__ 0) diff --git a/extras/library_generation/library_generation.sh b/extras/library_generation/library_generation.sh index 7ecf912aa..268258892 100755 --- a/extras/library_generation/library_generation.sh +++ b/extras/library_generation/library_generation.sh @@ -13,6 +13,8 @@ if [ $OPTIND -eq 1 ]; then PLATFORMS+=("opencr1") PLATFORMS+=("teensy4") PLATFORMS+=("teensy3") + PLATFORMS+=("cortex_m0") + PLATFORMS+=("cortex_m3") fi shift $((OPTIND-1)) @@ -94,6 +96,34 @@ if [[ " ${PLATFORMS[@]} " =~ " teensy4 " ]]; then cp -R firmware/build/libmicroros.a /arduino_project/src/imxrt1062/fpv5-d16-hard/libmicroros.a fi +######## Build for SAMD (e.g. Arduino Zero) ######## +if [[ " ${PLATFORMS[@]} " =~ " cortex_m0 " ]]; then + rm -rf firmware/build + + export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi- + ros2 run micro_ros_setup build_firmware.sh /arduino_project/extras/library_generation/cortex_m0_toolchain.cmake /arduino_project/extras/library_generation/colcon_verylowmem.meta + + find firmware/build/include/ -name "*.c" -delete + cp -R firmware/build/include/* /arduino_project/src/ + + mkdir -p /arduino_project/src/cortex-m0plus + cp -R firmware/build/libmicroros.a /arduino_project/src/cortex-m0plus/libmicroros.a +fi + +######## Build for SAM (e.g. Arduino Due) ######## +if [[ " ${PLATFORMS[@]} " =~ " cortex_m3 " ]]; then + rm -rf firmware/build + + export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-4_8-2014q1/bin/arm-none-eabi- + ros2 run micro_ros_setup build_firmware.sh /arduino_project/extras/library_generation/cortex_m3_toolchain.cmake /arduino_project/extras/library_generation/colcon_lowmem.meta + + find firmware/build/include/ -name "*.c" -delete + cp -R firmware/build/include/* /arduino_project/src/ + + mkdir -p /arduino_project/src/cortex-m3 + cp -R firmware/build/libmicroros.a /arduino_project/src/cortex-m3/libmicroros.a +fi + ######## Generate extra files ######## find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > /arduino_project/available_ros2_types find firmware/mcu_ws/extra_packages \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' >> /arduino_project/available_ros2_types diff --git a/extras/patching_boards/platform_arduinocore_sam.txt b/extras/patching_boards/platform_arduinocore_sam.txt new file mode 100644 index 000000000..a0aa8de9d --- /dev/null +++ b/extras/patching_boards/platform_arduinocore_sam.txt @@ -0,0 +1,109 @@ + +# Arduino SAM Core and platform. +# ------------------------------ +# +# For more info: +# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification + +name=Arduino ARM (32-bits) Boards +version=1.6.12 + +# SAM3 compile variables +# ---------------------- + +compiler.warning_flags=-w +compiler.warning_flags.none=-w +compiler.warning_flags.default= +compiler.warning_flags.more=-Wall +compiler.warning_flags.all=-Wall -Wextra + +compiler.path={runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path}/bin/ +compiler.c.cmd=arm-none-eabi-gcc +compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD +compiler.c.elf.cmd=arm-none-eabi-gcc +compiler.c.elf.flags=-Os -Wl,--gc-sections +compiler.S.cmd=arm-none-eabi-gcc +compiler.S.flags=-c -g -x assembler-with-cpp -MMD +compiler.cpp.cmd=arm-none-eabi-g++ +compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD +compiler.ar.cmd=arm-none-eabi-ar +compiler.ar.flags=rcs +compiler.objcopy.cmd=arm-none-eabi-objcopy +compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 +compiler.elf2hex.flags=-O binary +compiler.elf2hex.cmd=arm-none-eabi-objcopy +compiler.ldflags= +compiler.size.cmd=arm-none-eabi-size +compiler.define=-DARDUINO= +compiler.combine.flags=-u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid + +# This can be overridden in boards.txt +build.extra_flags= + +# These can be overridden in platform.local.txt +compiler.c.extra_flags= +compiler.c.elf.extra_flags= +compiler.cpp.extra_flags= +compiler.S.extra_flags= +compiler.ar.extra_flags= +compiler.elf2hex.extra_flags= +compiler.libraries.ldflags= + + +compiler.libsam.c.flags="-I{build.system.path}/libsam" "-I{build.system.path}/CMSIS/CMSIS/Include/" "-I{build.system.path}/CMSIS/Device/ATMEL/" + +# USB Flags +# --------- +build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' + +# Default usb manufacturer will be replaced at compile time using +# numeric vendor ID if available or by board's specific value. +build.usb_manufacturer="Unknown" + + +# SAM3 compile patterns +# --------------------- + +## Compile c files +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mcpu={build.mcu} -mthumb -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" + +## Compile c++ files +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -mthumb -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" + +## Compile S files +recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -mcpu={build.mcu} -mthumb -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}" + +## Create archives +# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value +archive_file_path={build.path}/{archive_file} +recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" + +## Combine gc-sections, archives, and objects +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group {compiler.combine.flags} {object_files} {compiler.libraries.ldflags} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -lgcc + +## Create output (.bin file) +recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin" + +## Save hex +recipe.output.tmp_file={build.project_name}.bin +recipe.output.save_file={build.project_name}.{build.variant}.bin + +## Compute size +recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" +recipe.size.regex=\.text\s+([0-9]+).* + + +# SAM3 Uploader tools +# ------------------- + +# BOSSA +tools.bossac.path={runtime.tools.bossac.path} +tools.bossac.cmd=bossac +tools.bossac.cmd.windows=bossac.exe + +tools.bossac.upload.params.verbose=-i -d +tools.bossac.upload.params.quiet= +tools.bossac.upload.params.verify=-v +tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -e -w {upload.verify} -b "{build.path}/{build.project_name}.bin" -R + +tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v -b /tmp/sketch.bin -R diff --git a/extras/library_generation/platform_teensy.txt b/extras/patching_boards/platform_teensy.txt similarity index 100% rename from extras/library_generation/platform_teensy.txt rename to extras/patching_boards/platform_teensy.txt diff --git a/library.properties b/library.properties index 22bda293a..4631b6903 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=micro-ROS Arduino library url=https://github.com/micro-ROS precompiled=true category=Other -architectures=OpenCR,Teensyduino +architectures=OpenCR,Teensyduino,samd,sam diff --git a/src/arduino_transports.c b/src/arduino_transports.c index 6f5c0b9c7..069b2cb86 100644 --- a/src/arduino_transports.c +++ b/src/arduino_transports.c @@ -5,11 +5,8 @@ #include "teensy_transports.c.in" #elif defined(ARDUINO_ARCH_OPENCR) #include "opencr_transports.c.in" -#else -#error micro-ROS Library not supported for this platform #endif - // TODO: This should be fixed #if defined(ARDUINO_TEENSY32) diff --git a/src/cortex-m0plus/libmicroros.a b/src/cortex-m0plus/libmicroros.a new file mode 100644 index 000000000..94622203f Binary files /dev/null and b/src/cortex-m0plus/libmicroros.a differ diff --git a/src/cortex-m3/libmicroros.a b/src/cortex-m3/libmicroros.a new file mode 100644 index 000000000..40098007e Binary files /dev/null and b/src/cortex-m3/libmicroros.a differ diff --git a/src/default_transport.cpp b/src/default_transport.cpp new file mode 100644 index 000000000..19052ab48 --- /dev/null +++ b/src/default_transport.cpp @@ -0,0 +1,48 @@ +#include + +extern "C" +{ +#include +#include +#include + + int clock_gettime(clockid_t unused, struct timespec *tp) __attribute__ ((weak)); + bool arduino_serial_platform_open() __attribute__ ((weak)); + bool arduino_serial_platform_close() __attribute__ ((weak)); + size_t arduino_serial_platform_write(uint8_t *buf, size_t len, uint8_t *errcode) __attribute__ ((weak)); + size_t arduino_serial_platform_read(uint8_t *buf, size_t len, int timeout, uint8_t *errcode) __attribute__ ((weak)); + + int clock_gettime(clockid_t unused, struct timespec *tp) + { + (void)unused; + uint64_t m = micros(); + tp->tv_sec = m / 1000000; + tp->tv_nsec = (m % 1000000) * 1000; + return 0; + } + + bool arduino_serial_platform_open() + { + Serial.begin(115200); + return true; + } + + bool arduino_serial_platform_close() + { + return true; + } + + size_t arduino_serial_platform_write(uint8_t *buf, size_t len, uint8_t *errcode) + { + (void)errcode; + size_t sent = Serial.write(buf, len); + return sent; + } + + size_t arduino_serial_platform_read(uint8_t *buf, size_t len, int timeout, uint8_t *errcode) + { + (void)errcode; + Serial.setTimeout(timeout); + return Serial.readBytes((char *)buf, len); + } +}