Skip to content

Commit bd86253

Browse files
committed
Add Arduino Due support
1 parent 26ae158 commit bd86253

File tree

6 files changed

+100
-2
lines changed

6 files changed

+100
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <Arduino.h>
2+
3+
extern "C"
4+
{
5+
#include <stdio.h>
6+
#include <stdbool.h>
7+
#include <sys/time.h>
8+
9+
int clock_gettime(clockid_t unused, struct timespec *tp)
10+
{
11+
(void)unused;
12+
uint64_t m = micros();
13+
tp->tv_sec = m / 1000000;
14+
tp->tv_nsec = (m % 1000000) * 1000;
15+
return 0;
16+
}
17+
18+
bool arduino_serial_platform_open()
19+
{
20+
// Place here your initialization platform code
21+
// Return true if success
22+
SerialUSB.begin(115200);
23+
return true;
24+
}
25+
26+
bool arduino_serial_platform_close()
27+
{
28+
// Place here your closing platform code
29+
// Return true if success
30+
return true;
31+
}
32+
33+
size_t arduino_serial_platform_write(uint8_t *buf, size_t len, uint8_t *errcode)
34+
{
35+
// Place here your writing bytes platform code
36+
// Return number of bytes written
37+
(void)errcode;
38+
size_t sent = SerialUSB.write(buf, len);
39+
return sent;
40+
}
41+
42+
size_t arduino_serial_platform_read(uint8_t *buf, size_t len, int timeout, uint8_t *errcode)
43+
{
44+
// Place here your reading bytes platform code
45+
// Return number of bytes read (max bytes: len)
46+
(void)errcode;
47+
uint32_t start_time = micros() * 1000;
48+
size_t readed = 0;
49+
50+
while ((readed < len) && ((micros() * 1000) - start_time) < (uint32_t)timeout)
51+
{
52+
if (SerialUSB.available())
53+
{
54+
buf[readed++] = SerialUSB.read();
55+
}
56+
}
57+
58+
return readed;
59+
}
60+
}

extras/cortex_m3_toolchain.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SET(CMAKE_SYSTEM_NAME Generic)
2+
set(CMAKE_CROSSCOMPILING 1)
3+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
4+
5+
set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_PREFIX}gcc)
6+
set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++)
7+
8+
SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
9+
SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
10+
11+
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)
12+
13+
set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
14+
set(CMAKE_CXX_FLAGS_INIT "-std=c++11 ${FLAGS} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
15+
16+
set(__BIG_ENDIAN__ 0)

extras/library_generation/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ RUN git clone https://github.com/micro-ROS/micro-ros-build.git src/micro-ros-bui
1717
&& rm -rf gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2 gcc-arm-none-eabi-5_4-2016q2/share/doc \
1818
&& 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 \
1919
&& tar -xvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 \
20-
&& rm -rf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 gcc-arm-none-eabi-5_4-2016q3/share/doc
20+
&& rm -rf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 gcc-arm-none-eabi-5_4-2016q3/share/doc \
21+
&& 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 \
22+
&& tar -xvf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 \
23+
&& rm -rf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 gcc-arm-none-eabi-4_8-2014q1/share/doc
2124

2225
COPY ./entrypoint.sh /entrypoint.sh
2326

extras/library_generation/library_generation.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if [ $OPTIND -eq 1 ]; then
1313
PLATFORMS+=("opencr1")
1414
PLATFORMS+=("teensy4")
1515
PLATFORMS+=("teensy3")
16+
PLATFORMS+=("cortex_m3")
1617
fi
1718

1819
shift $((OPTIND-1))
@@ -94,6 +95,20 @@ if [[ " ${PLATFORMS[@]} " =~ " teensy4 " ]]; then
9495
cp -R firmware/build/libmicroros.a /arduino_project/src/imxrt1062/fpv5-d16-hard/libmicroros.a
9596
fi
9697

98+
######## Build for SAM (e.g. Arduino Due) ########
99+
if [[ " ${PLATFORMS[@]} " =~ " cortex_m3 " ]]; then
100+
rm -rf firmware/build
101+
102+
export TOOLCHAIN_PREFIX=/uros_ws/gcc-arm-none-eabi-4_8-2014q1/bin/arm-none-eabi-
103+
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
104+
105+
find firmware/build/include/ -name "*.c" -delete
106+
cp -R firmware/build/include/* /arduino_project/src/
107+
108+
mkdir -p /arduino_project/src/cortex-m3
109+
cp -R firmware/build/libmicroros.a /arduino_project/src/cortex-m3/libmicroros.a
110+
fi
111+
97112
######## Generate extra files ########
98113
find firmware/mcu_ws/ros2 \( -name "*.srv" -o -name "*.msg" -o -name "*.action" \) | awk -F"/" '{print $(NF-2)"/"$NF}' > /arduino_project/available_ros2_types
99114
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

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=micro-ROS Arduino library
77
url=https://github.com/micro-ROS
88
precompiled=true
99
category=Other
10-
architectures=OpenCR,Teensyduino
10+
architectures=OpenCR,Teensyduino,sam

src/arduino_transports.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#include <stdio.h>
22
#include <stdbool.h>
33

4+
/*
5+
TODO: We should do something about this
6+
47
#if defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY32)
58
#include "teensy_transports.c.in"
69
#elif defined(ARDUINO_ARCH_OPENCR)
710
#include "opencr_transports.c.in"
811
#else
912
#error micro-ROS Library not supported for this platform
1013
#endif
14+
*/
1115

1216

1317
// TODO: This should be fixed

0 commit comments

Comments
 (0)