Commit ccabe4062c9ab13a6879e4514c109a8b7d2cbedd

Authored by Antonio Carlos Domínguez Brito
1 parent 516a7ade

CMake compiling support added and a small bug fixed

CMakeLists.txt 0 → 100644
... ... @@ -0,0 +1,186 @@
  1 +cmake_minimum_required(VERSION 2.8)
  2 +
  3 +set(PORT /dev/ttyACM0 CACHE STRING "uploading serial port")
  4 +set(IS_NATIVE_PORT true CACHE STRING "is it the native port? (true), or not? (false)")
  5 +
  6 +set(CMAKE_TOOLCHAIN_FILE arduino_due_toolchain.cmake)
  7 +
  8 +project(soft_uart C CXX)
  9 +
  10 +#####################################################################
  11 +# generating a static library for the standard Arduino library: begin
  12 +#####################################################################
  13 +
  14 +file(
  15 + GLOB ARDUINO_DUE_STD_LIB_SOURCE_FILES
  16 + LIST_DIRECTORIES false
  17 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino/*.c
  18 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino/*.cpp
  19 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino/USB/*.c
  20 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino/USB/*.cpp
  21 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/variants/arduino_due_x/*.c
  22 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/variants/arduino_due_x/*.cpp
  23 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/libraries/SPI/*.c
  24 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/libraries/SPI/*.cpp
  25 +)
  26 +
  27 +#mess(STATUS "ARDUINO_DUE_STD_LIB_SOURCE_FILES: ${ARDUINO_DUE_STD_LIB_SOURCE_FILES}")
  28 +
  29 +add_library(arduino_due_std_lib STATIC ${ARDUINO_DUE_STD_LIB_SOURCE_FILES})
  30 +set_property(
  31 + TARGET arduino_due_std_lib PROPERTY
  32 + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  33 +)
  34 +target_compile_options(
  35 + arduino_due_std_lib PUBLIC
  36 + -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -std=gnu++11 -mthumb
  37 +)
  38 +
  39 +target_compile_definitions(
  40 + arduino_due_std_lib PUBLIC
  41 + -Dprintf=iprintf -DF_CPU=84000000L -DARDUINO=10605 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due"
  42 +)
  43 +#####################################################################
  44 +# generating a static library for the standard Arduino library: end
  45 +#####################################################################
  46 +
  47 +# checking environment variable ARDUINO_IDE_LIBRARY_PATH
  48 +if(
  49 + NOT (DEFINED ENV{ARDUINO_IDE_LIBRARY_PATH})
  50 + OR
  51 + ($ENV{ARDUINO_IDE_LIBRARY_PATH} EQUAL "")
  52 +)
  53 +
  54 + message(FATAL_ERROR "[ERROR] Environment variable ARDUINO_IDE_LIBRARY_PATH not set!")
  55 +
  56 +else()
  57 +
  58 + message(STATUS "Environment variable ARDUINO_IDE_LIBRARY_PATH: $ENV{ARDUINO_IDE_LIBRARY_PATH}")
  59 +
  60 +endif()
  61 +
  62 +#####################################################################
  63 +# generating a static library for soft_uart: begin
  64 +#####################################################################
  65 +
  66 +file(
  67 + GLOB SOFT_UART_LIB_SOURCE_FILES
  68 + LIST_DIRECTORIES false
  69 + $ENV{ARDUINO_IDE_LIBRARY_PATH}/libraries/soft_uart/*.c
  70 + $ENV{ARDUINO_IDE_LIBRARY_PATH}/libraries/soft_uart/*.cpp
  71 +)
  72 +
  73 +#mess(STATUS "SOFT_UART_LIB_SOURCE_FILES: ${SOFT_UART_LIB_SOURCE_FILES}")
  74 +
  75 +add_library(soft_uart_lib STATIC ${SOFT_UART_LIB_SOURCE_FILES})
  76 +set_property(
  77 + TARGET soft_uart_lib PROPERTY
  78 + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  79 +)
  80 +target_compile_options(
  81 + soft_uart_lib PUBLIC
  82 + -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -std=gnu++11 -mthumb
  83 +)
  84 +
  85 +target_compile_definitions(
  86 + soft_uart_lib PUBLIC
  87 + -Dprintf=iprintf -DF_CPU=84000000L -DARDUINO=10605 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due"
  88 +)
  89 +
  90 +target_include_directories(
  91 + soft_uart_lib PUBLIC
  92 + $ENV{ARDUINO_IDE_LIBRARY_PATH}/libraries/soft_uart/
  93 +)
  94 +#####################################################################
  95 +# generating a static library for soft_uart: end
  96 +#####################################################################
  97 +
  98 +#####################################################################
  99 +# soft_uart examples: begin
  100 +#####################################################################
  101 +
  102 +set(
  103 + SOFT_UART_EXAMPLES
  104 + soft_uart_serial_test
  105 + soft_uart_serial_test_auto
  106 + soft_uart_serial_test_half_duplex
  107 + soft_uart_serial_test_half_duplex_9O2
  108 +)
  109 +
  110 +foreach(src_example ${SOFT_UART_EXAMPLES})
  111 + configure_file(
  112 + ${PROJECT_SOURCE_DIR}/examples/${src_example}/${src_example}.ino
  113 + ${src_example}.cpp
  114 + COPYONLY
  115 + )
  116 + add_executable(
  117 + ${src_example}.cpp.elf
  118 + ${src_example}.cpp
  119 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino/syscalls_sam3.c
  120 + )
  121 + target_compile_options(
  122 + ${src_example}.cpp.elf PUBLIC
  123 + -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -std=gnu++11 -mthumb
  124 + )
  125 +
  126 + target_compile_definitions(
  127 + ${src_example}.cpp.elf PUBLIC
  128 + -Dprintf=iprintf -DF_CPU=84000000L -DARDUINO=10605 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due"
  129 + )
  130 +
  131 + target_include_directories(
  132 + ${src_example}.cpp.elf PUBLIC
  133 + $ENV{ARDUINO_IDE_LIBRARY_PATH}/libraries/soft_uart
  134 + )
  135 + target_link_libraries(
  136 + ${src_example}.cpp.elf
  137 + -Os -Wl,--gc-sections -mcpu=cortex-m3 -T$ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/variants/arduino_due_x/linker_scripts/gcc/flash.ld -Wl,-Map,${src_example}.cpp.map -mthumb -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,--warn-unresolved-symbols -Wl,--start-group arduino_due_std_lib soft_uart_lib $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a -Wl,--end-group -lm
  138 + )
  139 +
  140 + # bin
  141 + add_custom_command(
  142 + OUTPUT
  143 + ${src_example}.cpp.bin
  144 + COMMAND
  145 + ${DUE_OBJCOPY} -O binary ${src_example}.cpp.elf ${src_example}.cpp.bin
  146 + DEPENDS
  147 + ${src_example}.cpp.elf
  148 + )
  149 +
  150 + # size
  151 + add_custom_command(
  152 + OUTPUT
  153 + ${src_example}.cpp.size
  154 + COMMAND
  155 + ${DUE_SIZE_TOOL} -A ${src_example}.cpp.elf > ${src_example}.cpp.size
  156 + DEPENDS
  157 + ${src_example}.cpp.elf
  158 + )
  159 +
  160 + # target for the custom commands
  161 + add_custom_target(
  162 + ${src_example}
  163 + ALL
  164 + DEPENDS
  165 + ${src_example}.cpp.size ${src_example}.cpp.bin
  166 + )
  167 +
  168 + # upload - with avrdude
  169 + get_filename_component(PORT_NAME ${PORT} NAME)
  170 + add_custom_target(
  171 + upload_${src_example}
  172 + COMMAND
  173 + stty -F ${PORT} 1200\; cat ${CMAKE_CURRENT_LIST_DIR}/dummy > ${PORT}\; sleep 3
  174 + COMMAND
  175 + ${DUE_BOSSAC} -i -d --port=${PORT_NAME} -U ${IS_NATIVE_PORT} -e -w -v -b ${src_example}.cpp.bin -R
  176 + DEPENDS ${src_example}.cpp.bin
  177 + COMMENT
  178 + "Uploading ${src_example}.cpp.bin to uC ATSAM3X8E through ${PORT}"
  179 + )
  180 +
  181 +endforeach(src_example)
  182 +
  183 +
  184 +
  185 +
  186 +
... ...
README.md
... ... @@ -107,5 +107,24 @@ The list of users/projects goes now:
107 107  
108 108 1. **Project:** Autonomous sailboat A-Tirma (<http://velerorobot.blogspot.com.es>). **User**: División de Robótica y Oceanografía Computacional (<http://www.roc.siani.es>). **Description**: The library was a specific development for this project. The sailboat onboard system is based on an Arduino DUE, and we ran out of hardware serial ports for all the hardware we use on the boat.
109 109  
  110 +### 7. Compiling with CMake
  111 +
  112 +For compiling on command line using CMake, just proceed in the following manner:
  113 +
  114 +1. Go to `soft_uart` directory (the one you have cloned with the progject).
  115 +2. Create directory `build` (if not already created).
  116 +3. Execute `cmake ..`.
  117 +4. Set the following flags and variables (if not done before), you should execute `ccmake ..`:
  118 + * Set `PORT` to the serial port where the DUE's port you will use for uploading.
  119 + * Set `IS_NATIVE_PORT` to `true` (native port) or `false` (programming port) accordingly.
  120 +5. Be sure the changes were applyed, usually running `cmake ..`.
  121 +6. Compile executing `make`.
  122 +7. The previous step has generated the examples available with the library. You can upload the code executing:
  123 + * `make upload_soft_uart_serial_test`,
  124 + * `make upload_soft_uart_serial_test_auto`,
  125 + * `make upload_soft_uart_serial_test_half_duplex`
  126 + * and `make upload_soft_uart_serial_test_half_duplex_9O1`.
  127 +
  128 +
110 129  
111 130  
... ...
arduino_due_toolchain.cmake 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +# arduino_due_toolchain.cmake: toolchain file for arduino due
  2 +
  3 +include (CMakeForceCompiler)
  4 +
  5 +set(CMAKE_SYSTEM_NAME Generic)
  6 +set(CMAKE_SYSTEM_PROCESSOR arm)
  7 +
  8 +# checking environment variable ARDUINO_DUE_SOURCE_PATH
  9 +if(
  10 + NOT (DEFINED ENV{ARDUINO_DUE_ROOT_PATH})
  11 + OR
  12 + ($ENV{ARDUINO_DUE_ROOT_PATH} EQUAL "")
  13 +)
  14 +
  15 + message(FATAL_ERROR "[ERROR] Environment variable ARDUINO_DUE_ROOT_PATH not set!")
  16 +
  17 +else()
  18 +
  19 + message(STATUS "Environment variable ARDUINO_DUE_ROOT_PATH: $ENV{ARDUINO_DUE_ROOT_PATH}")
  20 +
  21 +endif()
  22 +
  23 +function(find_due_program DUE_PROGRAM_PATH DUE_PROGRAM WHERE)
  24 +
  25 + find_program(
  26 + ${DUE_PROGRAM_PATH}
  27 + ${DUE_PROGRAM}
  28 + PATH ${WHERE}
  29 + NO_SYSTEM_ENVIRONMENT_PATH
  30 + )
  31 + if(NOT ${DUE_PROGRAM_PATH})
  32 + message(FATAL_ERROR "[ERROR] \"${DUE_PROGRAM}\" not found!")
  33 + else()
  34 + message(STATUS "\"${DUE_PROGRAM}\" found: ${${DUE_PROGRAM_PATH}}")
  35 + endif()
  36 +
  37 +endfunction(find_due_program)
  38 +
  39 +find_due_program(
  40 + DUE_CC
  41 + arm-none-eabi-gcc
  42 + $ENV{ARDUINO_DUE_ROOT_PATH}/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin
  43 +)
  44 +find_due_program(
  45 + DUE_CXX
  46 + arm-none-eabi-g++
  47 + $ENV{ARDUINO_DUE_ROOT_PATH}/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin
  48 +)
  49 +find_due_program(
  50 + DUE_OBJCOPY
  51 + arm-none-eabi-objcopy
  52 + $ENV{ARDUINO_DUE_ROOT_PATH}/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin
  53 +)
  54 +find_due_program(
  55 + DUE_SIZE_TOOL
  56 + arm-none-eabi-size
  57 + $ENV{ARDUINO_DUE_ROOT_PATH}/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin
  58 +)
  59 +find_due_program(
  60 + DUE_OBJDUMP
  61 + arm-none-eabi-objdump
  62 + $ENV{ARDUINO_DUE_ROOT_PATH}/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin
  63 +)
  64 +find_due_program(
  65 + DUE_BOSSAC
  66 + bossac
  67 + $ENV{ARDUINO_DUE_ROOT_PATH}/tools/bossac/1.3a-arduino
  68 +)
  69 +
  70 +CMAKE_FORCE_C_COMPILER(${DUE_CC} arduino_due_arm)
  71 +CMAKE_FORCE_CXX_COMPILER(${DUE_CXX} arduino_due_arm)
  72 +
  73 +include_directories(
  74 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/system/libsam
  75 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/system/CMSIS/CMSIS/Include
  76 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/system/CMSIS/Device/ATMEL $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino
  77 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/cores/arduino/USB
  78 + $ENV{ARDUINO_DUE_ROOT_PATH}/hardware/sam/1.6.4/variants/arduino_due_x
  79 +)
  80 +
  81 +
... ...
dummy 0 → 100644
... ... @@ -0,0 +1 @@
  1 +dummy
... ...
soft_uart.h
... ... @@ -321,7 +321,8 @@ namespace arduino_due
321 321 pinMode(_ctx_.rx_pin,INPUT);
322 322 attachInterrupt(_ctx_.rx_pin,uart::rx_interrupt,CHANGE);
323 323  
324   - _mode_=mode_codes::RX_MODE; _ctx_.enable_rx_interrupts();
  324 + _mode_=mode_codes::RX_MODE;
  325 + _ctx_.enable_rx_interrupts();
325 326 return true;
326 327 }
327 328  
... ... @@ -334,10 +335,10 @@ namespace arduino_due
334 335  
335 336 if(_mode_==mode_codes::TX_MODE) return true;
336 337  
  338 + while(_ctx_.rx_status!=rx_status_codes::LISTENING)
  339 + { /* nothing */ }
  340 +
337 341 _ctx_.disable_rx_interrupts();
338   - while(
339   - _ctx_.rx_status!=rx_status_codes::LISTENING
340   - ) _ctx_.enable_rx_interrupts();
341 342  
342 343 detachInterrupt(_ctx_.rx_pin);
343 344 pinMode(_ctx_.tx_pin,OUTPUT);
... ...