From bbb508721ffcfe88aadc5d7b60fc15537e5865a1 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Sun, 25 Feb 2018 23:35:29 -0800 Subject: [PATCH 1/8] Add build config options to build script An example of what options can be used can be seen in tup.config.default. --- Firmware/Board/v3.3/Inc/main.h | 4 -- Firmware/MotorControl/commands.cpp | 7 ++++ Firmware/MotorControl/commands.h | 21 ----------- Firmware/Tupfile.lua | 60 +++++++++++++++++++++++++++++- tup.config.default | 6 +++ 5 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 tup.config.default diff --git a/Firmware/Board/v3.3/Inc/main.h b/Firmware/Board/v3.3/Inc/main.h index a9650093..c6276ad8 100644 --- a/Firmware/Board/v3.3/Inc/main.h +++ b/Firmware/Board/v3.3/Inc/main.h @@ -52,10 +52,6 @@ /* USER CODE BEGIN Includes */ -#define HW_VERSION_MAJOR 3 -#define HW_VERSION_MINOR 4 -// #define HW_VERSION_HIGH_VOLTAGE true - #if HW_VERSION_MAJOR == 3 && HW_VERSION_MINOR == 1 \ || HW_VERSION_MAJOR == 3 && HW_VERSION_MINOR == 2 #include "prev_board_ver/main_V3_2.h" diff --git a/Firmware/MotorControl/commands.cpp b/Firmware/MotorControl/commands.cpp index 1e9d0117..91178b54 100644 --- a/Firmware/MotorControl/commands.cpp +++ b/Firmware/MotorControl/commands.cpp @@ -36,6 +36,13 @@ extern USBD_HandleTypeDef hUsbDeviceFS; /* Private constant data -----------------------------------------------------*/ // TODO: make command to switch gpio_mode during run-time + +typedef enum { + GPIO_MODE_NONE, + GPIO_MODE_UART, + GPIO_MODE_STEP_DIR, +} GpioMode_t; + #if defined(USE_GPIO_MODE_STEP_DIR) static const GpioMode_t gpio_mode = GPIO_MODE_STEP_DIR; //GPIO 1,2 is M0 Step,Dir #elif !defined(UART_PROTOCOL_NONE) diff --git a/Firmware/MotorControl/commands.h b/Firmware/MotorControl/commands.h index 0d9d7c87..8ce16821 100644 --- a/Firmware/MotorControl/commands.h +++ b/Firmware/MotorControl/commands.h @@ -10,27 +10,6 @@ #include #include "crc.hpp" -// Select which protocol to run on USB (see README for more details) -#define USB_PROTOCOL_NATIVE -// #define USB_PROTOCOL_NATIVE_STREAM_BASED -// #define USB_PROTOCOL_LEGACY -// #define USB_PROTOCOL_NONE - -// Select which protocol to run on UART (see README for more details) -// #define UART_PROTOCOL_NATIVE -// #define UART_PROTOCOL_LEGACY -#define UART_PROTOCOL_NONE - -// Use GPIO 1/2 for step/dir input instead of UART -// #define USE_GPIO_MODE_STEP_DIR - - -typedef enum { - GPIO_MODE_NONE, - GPIO_MODE_UART, - GPIO_MODE_STEP_DIR, -} GpioMode_t; - extern "C" { #endif diff --git a/Firmware/Tupfile.lua b/Firmware/Tupfile.lua index 3885d8bd..9411cdb6 100644 --- a/Firmware/Tupfile.lua +++ b/Firmware/Tupfile.lua @@ -1,7 +1,65 @@ tup.include('build.lua') -boarddir = 'Board/v3.3' +-- Switch between board versions +boardversion = tup.getconfig("BOARD_VERSION") +if boardversion == "" then boardversion = "v3.4" end +if boardversion == "v3.1" then + boarddir = 'Board/v3.3' -- currently all platform code is in the same v3.3 directory + FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=1" +elseif boardversion == "v3.2" then + boarddir = 'Board/v3.3' + FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=2" +elseif boardversion == "v3.3" then + boarddir = 'Board/v3.3' + FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=3" +elseif boardversion == "v3.4" then + boarddir = 'Board/v3.3' + FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=4" +else + error("unknown board version "..boardversion) +end +buildsuffix = boardversion + +-- 48V voltage version +if tup.getconfig("48V") == "y" then + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=true" +else + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=false" +end + +-- USB I/O settings +if tup.getconfig("USB_PROTOCOL") == "native" or tup.getconfig("USB_PROTOCOL") == "" then + FLAGS += "-DUSB_PROTOCOL_NATIVE" +elseif tup.getconfig("USB_PROTOCOL") == "native-stream" then + FLAGS += "-DUSB_PROTOCOL_NATIVE_STREAM_BASED" +elseif tup.getconfig("USB_PROTOCOL") == "ascii" then + FLAGS += "-DUSB_PROTOCOL_LEGACY" +elseif tup.getconfig("USB_PROTOCOL") == "none" then + FLAGS += "-DUSB_PROTOCOL_NONE" +else + error("unknown USB protocol") +end + +-- UART I/O settings +if tup.getconfig("UART_PROTOCOL") == "native" then + FLAGS += "-DUART_PROTOCOL_NATIVE" +elseif tup.getconfig("UART_PROTOCOL") == "ascii" or tup.getconfig("UART_PROTOCOL") == "" then + FLAGS += "-DUART_PROTOCOL_LEGACY" +elseif tup.getconfig("UART_PROTOCOL") == "none" then + FLAGS += "-DUART_PROTOCOL_NONE" +else + error("unknown UART protocol "..tup.getconfig("UART_PROTOCOL")) +end + +-- GPIO settings +if tup.getconfig("STEP_DIR") == "y" then + if tup.getconfig("UART_PROTOCOL") != "none" then + FLAGS += "-DUSE_GPIO_MODE_STEP_DIR" + else + error("Step/dir mode conflicts with UART. Set CONFIG_UART_PROTOCOL to none.") + end +end -- C-specific flags diff --git a/tup.config.default b/tup.config.default new file mode 100644 index 00000000..5795105e --- /dev/null +++ b/tup.config.default @@ -0,0 +1,6 @@ +CONFIG_DEBUG=y +CONFIG_BOARD_VERSION=v3.3 +CONFIG_BOARD_48V=n +CONFIG_USB_PROTOCOL=native +CONFIG_UART_PROTOCOL=ascii +CONFIG_STEP_DIR=n From 7e7ea04dc7d556ba75a56135187807cfd403e7ce Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Sun, 4 Mar 2018 18:53:54 -0800 Subject: [PATCH 2/8] update readme --- Firmware/README.md | 46 +++++++++++++++----------------------------- Firmware/Tupfile.lua | 1 + 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/Firmware/README.md b/Firmware/README.md index ee389e8c..1a3d1a92 100644 --- a/Firmware/README.md +++ b/Firmware/README.md @@ -27,41 +27,25 @@ The project is under active development, so make sure to check the [Changelog](C To correctly operate the ODrive, you need to supply some parameters. Some are mandatory, and if supplied incorrectly will cause the drive to malfunction. In this section we will set the compile-time parameters, later we will also set the [run time parameters](#configuring-parameters). -The first thing to set is your board hardware version, located at the top of [Inc/main.h](Inc/main.h). If, for example, you are using the hardware: ODrive v3.2, then you should set it like this: -```C -#define HW_VERSION_MAJOR 3 -#define HW_VERSION_MINOR 2 -``` -If you are using the 48V version of ODrive, you should also uncomment this line -```C -#define HW_VERSION_HIGH_VOLTAGE true -``` +To customize the compile time parameters, copy or rename the file `tup.config.default` to `tup.config` and edit the parameters in that file: -### Communication configuration -If want to use the example python scripts and connect the ODrive via USB, the defaults are fine for you and you can skip this step. +__CONFIG_BOARD_VERSION__: The board version you're using. Can be `v3.1`, `v3.2`, `v3.3` or `v3.4`. -You can select what interface you want to run on USB and GPIO pins. See [Communicating over USB or UART](#communicating-over-usb-or-uart) for more information. -The following options are available in [MotorControl/commands.h](MotorControl/commands.h): +__CONFIG_48V__: Set to `y` if you're using a 48V version of the ODrive. Otherwise set to `n`. All ODrives v3.3 or older are 24V. All ODrives v3.4 or newer have a label that says 24V or 48V. -__USB__: - - `USB_PROTOCOL_NATIVE`: Use the native protocol (recommended for new applications). - The python library only understands the native protocol, so this is the way to go - if you use that. - - `USB_PROTOCOL_NATIVE_STREAM_BASED`: Use the native stream based protocol. - On most platforms the device shows up as a serial port when connected over USB. - So instead of using the python tool's direct USB access, you can use this option and then pretend you connected the device over serial. - __On some platforms (specifically macOS), this is required__ because the kernel doesn't allow direct USB access. - - `USB_PROTOCOL_LEGACY`: Use the human-readable legacy protocol - Select this option if you already have an existing application. This option will be removed in the future. - - `USB_PROTOCOL_NONE`: Ignore USB communication +__CONFIG_USB_PROTOCOL__: Defines which protocol the ODrive should use on the USB interface. + * `native`: The native ODrive protocol. Use this if you want to use the python tools in this repo. + * `native-stream`: Like the native ODrive protocol, but the ODrive will treat the USB connection exactly as if it was a UART connection. __Use this if you're on macOS__. This is necessary because macOS doesn't grant our python tools sufficient low-level access to treat the device as the USB device that it is. + * `ascii`: The ASCII protocol. This allows sending simple commands like position setpoints directly from the terminal to the ODrive without the use of intermediate utilities. + * `none`: Disable USB. The device will still show up when plugged in but it will ignore any commands. + +__CONFIG_UART_PROTOCOL__: Defines which protocol the ODrive should use on the UART interface (GPIO1 and GPIO2). Note that UART is only supported on ODrive v3.3 and higher. + * `native`: The native ODrive protocol. Use this if you're connecting the ODrive to a PC using UART and want to use the python tools to control and setup the ODrive. + * `ascii`: The ASCII protocol. Use this option if you control the ODrive with an Arduino. The ODrive Arduino library is not yet updated to the native protocol. + * `none`: Disable UART. + +__CONFIG_STEP_DIR__: Set to `y` to use the GPIO1 and GPIO2 for step/direction input. Set to `n` otherwise. To use this, `CONFIG_UART_PROTOCOL` must be `none` because UART uses the same pins. -__GPIO 1,2 pins__: -Note that UART is only supported on ODrive v3.3 and higher. - - `UART_PROTOCOL_NATIVE`: Use the native protocol (see notes above). - - `UART_PROTOCOL_LEGACY`: Use the human-readable legacy protocol - Use this option if you control the ODrive with an Arduino. The ODrive Arduino library is not yet updated to the native protocol. - - `UART_PROTOCOL_NONE`: Ignore UART communication - - `USE_GPIO_MODE_STEP_DIR`: Step/direction control mode (use in conjunction with `UART_PROTOCOL_NONE`)

## Compiling and downloading firmware diff --git a/Firmware/Tupfile.lua b/Firmware/Tupfile.lua index 23eefc57..c6423482 100644 --- a/Firmware/Tupfile.lua +++ b/Firmware/Tupfile.lua @@ -74,6 +74,7 @@ FLAGS += '-mfpu=fpv4-sp-d16' FLAGS += '-mfloat-abi=hard' FLAGS += { '-Wall', '-fdata-sections', '-ffunction-sections'} +-- debug build FLAGS += '-g -gdwarf-2' From fe34e7789a1e2aef863a30e8c8a7e4173dcbe8f4 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Fri, 9 Mar 2018 21:24:30 -0800 Subject: [PATCH 3/8] amend changelog --- Firmware/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Firmware/CHANGELOG.md b/Firmware/CHANGELOG.md index 304a193b..cfdd01a8 100644 --- a/Firmware/CHANGELOG.md +++ b/Firmware/CHANGELOG.md @@ -3,6 +3,9 @@ Please add a note of your changes below this heading if you make a Pull Request. * **Storing of configuration parameters to Non Volatile Memory** +### Changed +* The build is now configured using the `tup.config` file instead of editing source files. Make sure you set your board version correctly. See [here](README.md#configuring-the-build) for details. + # Releases ## [0.3.5] - 2018-03-04 From 5ba0aa099af9256a2751e694fd69a08acfdab668 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Sat, 10 Mar 2018 01:55:27 -0800 Subject: [PATCH 4/8] Update CHANGELOG.md --- Firmware/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/CHANGELOG.md b/Firmware/CHANGELOG.md index cfdd01a8..2b4fe92d 100644 --- a/Firmware/CHANGELOG.md +++ b/Firmware/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased Features Please add a note of your changes below this heading if you make a Pull Request. +### Added * **Storing of configuration parameters to Non Volatile Memory** ### Changed From 9a9826b8ce36883f9c3ee240475bc94c749a2bbc Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Sun, 11 Mar 2018 21:00:04 -0700 Subject: [PATCH 5/8] change board names in build config, remove default --- Firmware/README.md | 4 +--- Firmware/Tupfile.lua | 20 +++++++++++--------- tup.config.default | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Firmware/README.md b/Firmware/README.md index 1a3d1a92..18feb9cd 100644 --- a/Firmware/README.md +++ b/Firmware/README.md @@ -29,9 +29,7 @@ In this section we will set the compile-time parameters, later we will also set To customize the compile time parameters, copy or rename the file `tup.config.default` to `tup.config` and edit the parameters in that file: -__CONFIG_BOARD_VERSION__: The board version you're using. Can be `v3.1`, `v3.2`, `v3.3` or `v3.4`. - -__CONFIG_48V__: Set to `y` if you're using a 48V version of the ODrive. Otherwise set to `n`. All ODrives v3.3 or older are 24V. All ODrives v3.4 or newer have a label that says 24V or 48V. +__CONFIG_BOARD_VERSION__: The board version you're using. Can be `v3.1`, `v3.2`, `v3.3`, `v3.4-24V` or `v3.4-48V`. Check for a label on the upper side of the ODrive to find out which version you have. __CONFIG_USB_PROTOCOL__: Defines which protocol the ODrive should use on the USB interface. * `native`: The native ODrive protocol. Use this if you want to use the python tools in this repo. diff --git a/Firmware/Tupfile.lua b/Firmware/Tupfile.lua index c6423482..e9500aba 100644 --- a/Firmware/Tupfile.lua +++ b/Firmware/Tupfile.lua @@ -3,31 +3,33 @@ tup.include('build.lua') -- Switch between board versions boardversion = tup.getconfig("BOARD_VERSION") -if boardversion == "" then boardversion = "v3.4" end if boardversion == "v3.1" then boarddir = 'Board/v3.3' -- currently all platform code is in the same v3.3 directory FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=1" + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=false" elseif boardversion == "v3.2" then boarddir = 'Board/v3.3' FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=2" + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=false" elseif boardversion == "v3.3" then boarddir = 'Board/v3.3' FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=3" -elseif boardversion == "v3.4" then + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=false" +elseif boardversion == "v3.4-24V" then boarddir = 'Board/v3.3' FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=4" + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=false" +elseif boardversion == "v3.4-48V" then + boarddir = 'Board/v3.3' + FLAGS += "-DHW_VERSION_MAJOR=3 -DHW_VERSION_MINOR=4" + FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=true" +elseif boardversion == "" then + error("board version not specified - take a look at tup.config.default") else error("unknown board version "..boardversion) end buildsuffix = boardversion --- 48V voltage version -if tup.getconfig("48V") == "y" then - FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=true" -else - FLAGS += "-DHW_VERSION_HIGH_VOLTAGE=false" -end - -- USB I/O settings if tup.getconfig("USB_PROTOCOL") == "native" or tup.getconfig("USB_PROTOCOL") == "" then FLAGS += "-DUSB_PROTOCOL_NATIVE" diff --git a/tup.config.default b/tup.config.default index 5795105e..831e3b67 100644 --- a/tup.config.default +++ b/tup.config.default @@ -1,6 +1,6 @@ +# Copy this file to tup.config and adapt it to your needs CONFIG_DEBUG=y -CONFIG_BOARD_VERSION=v3.3 -CONFIG_BOARD_48V=n +#CONFIG_BOARD_VERSION=v3.3 # make sure this fits your board CONFIG_USB_PROTOCOL=native CONFIG_UART_PROTOCOL=ascii CONFIG_STEP_DIR=n From 7a6f925e9650b64b980fad26d5fe3b6fb75d680f Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Sun, 11 Mar 2018 21:36:06 -0700 Subject: [PATCH 6/8] fix CONFIG_UART_PROTOCOL check --- Firmware/Tupfile.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Tupfile.lua b/Firmware/Tupfile.lua index e9500aba..0a12027a 100644 --- a/Firmware/Tupfile.lua +++ b/Firmware/Tupfile.lua @@ -56,7 +56,7 @@ end -- GPIO settings if tup.getconfig("STEP_DIR") == "y" then - if tup.getconfig("UART_PROTOCOL") != "none" then + if tup.getconfig("UART_PROTOCOL") == "none" then FLAGS += "-DUSE_GPIO_MODE_STEP_DIR" else error("Step/dir mode conflicts with UART. Set CONFIG_UART_PROTOCOL to none.") From b29c82a5fdffa6cd038cab0f1487ab682671ef19 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Sun, 11 Mar 2018 21:57:38 -0700 Subject: [PATCH 7/8] make Travis build v3.4-48V by default --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2fdc962e..2c4232e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,5 +32,6 @@ install: script: - cd Firmware - mkdir -p build + - echo "CONFIG_BOARD_VERSION=v3.4-24V" > ../tup.config # TODO: build more configuration combinations - tup generate ./build.sh - bash -xe ./build.sh From 2a593a8cace5f0fc068cbb9a3fd64dc87b9f817a Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Sun, 11 Mar 2018 22:34:59 -0700 Subject: [PATCH 8/8] make travis use tup 0.7.5 --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c4232e6..acc62f3d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,15 +23,14 @@ install: - export GCC_URL=https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 - if [ ! -e $GCC_DIR/bin/arm-none-eabi-gcc ]; then wget $GCC_URL -O $GCC_ARCHIVE; tar xfj $GCC_ARCHIVE -C $HOME/dl; fi - export PATH=$PATH:$GCC_DIR/bin - - export TUP_DIR=$HOME/dl/tup_0.7.2.12+ga582fee_amd64 - - export TUP_ARCHIVE=$HOME/dl/tup_0.7.2.12+ga582fee_amd64.deb - - export TUP_URL=http://ppa.launchpad.net/anatol/tup/ubuntu/pool/main/t/tup/tup_0.7.2.12+ga582fee_amd64.deb + - export TUP_DIR=$HOME/dl/tup_0.7.5-0~16.04.york0_amd64 + - export TUP_ARCHIVE=$HOME/dl/tup_0.7.5-0~16.04.york0_amd64.deb + - export TUP_URL=http://ppa.launchpad.net/jonathonf/tup/ubuntu/pool/main/t/tup/tup_0.7.5-0~16.04.york0_amd64.deb - if [ ! -e $TUP_DIR/bin/tup ]; then wget $TUP_URL -O $TUP_ARCHIVE; dpkg-deb -R $TUP_ARCHIVE $TUP_DIR; fi - export PATH=$PATH:$TUP_DIR/usr/bin script: - - cd Firmware - - mkdir -p build - - echo "CONFIG_BOARD_VERSION=v3.4-24V" > ../tup.config # TODO: build more configuration combinations + - mkdir -p Firmware/build + - echo "CONFIG_BOARD_VERSION=v3.4-24V" > tup.config # TODO: build more configuration combinations - tup generate ./build.sh - bash -xe ./build.sh