Skip to content

Commit

Permalink
Merge pull request #151 from mcci-catena/issue150
Browse files Browse the repository at this point in the history
Fix #150: add CI testing for debug prints. Also fix #8, making debug prints work on gcc-based non-AVR.
  • Loading branch information
terrillmoore authored Oct 14, 2018
2 parents 8860484 + 76b7454 commit 04b5789
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
45 changes: 33 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ before_install:
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
- sleep 3
- export DISPLAY=:1.0
- wget http://downloads.arduino.cc/arduino-${IDE_VERSION}-linux64.tar.xz
- tar xf arduino-${IDE_VERSION}-linux64.tar.xz
- mv arduino-${IDE_VERSION} $HOME/arduino_ide
- ln -s $PWD $HOME/arduino_ide/libraries/Test_Library
- export PATH="$HOME/arduino_ide:$PATH"
- export ARDUINO_IDE=arduino_ide/${IDE_VERSION}
- if [ ! -d "$HOME/arduino_ide" ] ; then mkdir "$HOME/arduino_ide" ; fi
- if [ ! -d "$HOME/$ARDUINO_IDE" ] ; then { echo "fetch" && wget http://downloads.arduino.cc/arduino-${IDE_VERSION}-linux64.tar.xz && echo "untar" && tar xf arduino-${IDE_VERSION}-linux64.tar.xz && echo "move" && mv -f arduino-${IDE_VERSION} $HOME/${ARDUINO_IDE} ; } || { echo "IDE install failed"; exit 1; } ; else echo "IDE already installed" ; fi
- ln -sf $PWD $HOME/${ARDUINO_IDE}/libraries/Test_Library
- export PATH="$HOME/${ARDUINO_IDE}:$PATH"
#
# functions to generate the board settings for SAMD, STM32L0, ...
# keep args for these aligned for any common options. $1 is always board name, $2 is region.
Expand All @@ -24,15 +24,20 @@ before_install:
- "function _samdopts { echo mcci:samd:${1:-mcci_catena_4450}:lorawan_region=${2:-us915} ; }"
- "function _stm32l0opts { echo mcci:stm32:${1:-mcci_catena_4551}:lorawan_region=${2:-us915},opt=${3:-osstd},xserial=${4:-generic},usb=${5:-none},upload_method=${6:-STLink} ; }"
- "function _avropts { echo adafruit:avr:${1:-feather32u4} ; }"
- "function _esp32opts { echo esp32:esp32:${1:-heltec_wifi_lora_32}:FlashFreq=80 ; }"
#
# Put one or more arguments into lmic_project_config.h as `#define $i\n`
- function _projcfg { for i in "$@" ; do printf '#define %s 1\n' "$i" ; done > $PWD/project_config/lmic_project_config.h ; }
# Put one or more arguments into lmic_project_config.h as `#define $i 1\n` or `#define $i $arg`
- function _splitdef { if [ "$1" = "${1/=/}" ]; then echo "$1" 1 ; else echo "${1/=/ }" ; fi ; }
- function _projcfg { for i in "$@" ; do printf '#define %s %s\n' $(_splitdef "$i") ; done > $PWD/project_config/lmic_project_config.h ; }
#
# Handy macro to deal with expected failures.
- 'function _expect_failure { if [ $? -eq 0 ]; then echo "Suceeded, but should have failed!" ; echo project_config/lmic_project_config.h ; cat $PWD/project_config/lmic_project_config.h ; return 1 ; else echo "Failed, as expected"; return 0 ; fi ; }'
#
# modify the board manager preferences to point to our BSPs.
- arduino --pref "boardsmanager.additional.urls=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json,https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" --save-prefs
- BSPMCCI=https://github.com/mcci-catena/arduino-boards/raw/master/BoardManagerFiles/package_mcci_index.json
- BSPADAFRUIT=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
- BSPESP32=https://dl.espressif.com/dl/package_esp32_index.json
- arduino --pref "boardsmanager.additional.urls=$BSPMCCI,$BSPADAFRUIT,$BSPESP32" --save-prefs
#
# Centralize the STM32 config override. See the following:
# https://github.com/mcci-catena/Arduino_Core_STM32/issues/30
Expand All @@ -44,27 +49,38 @@ before_install:
- "echo $(_stm32l0opts) $(_stm32l0opts '' projcfg)"
- "echo $(_samdopts) $(_samdopts '' projcfg)"
- "echo $(_avropts) $(_avropts '' PROJCFG)"
- "echo $(_esp32opts) $(_esp32opts '' PROJCFG)"


install:
- git clone --depth=1 https://github.com/adafruit/Adafruit_Sensor.git $HOME/arduino_ide/libraries/Adafruit_Sensor
- git clone --depth=1 https://github.com/adafruit/DHT-sensor-library.git $HOME/arduino_ide/libraries/DHT-sensor-library
- git clone --depth=1 https://github.com/adafruit/Adafruit_Sensor.git $HOME/${ARDUINO_IDE}/libraries/Adafruit_Sensor
- git clone --depth=1 https://github.com/adafruit/DHT-sensor-library.git $HOME/${ARDUINO_IDE}/libraries/DHT-sensor-library
# be careful when installing; with caching, we usually won't update. Select most recent.
- arduino --install-boards adafruit:avr || echo "assume adafruit:avr already installed, continue"
- arduino --install-boards mcci:samd || echo "assume mcci:samd already installed, continue"
- arduino --install-boards mcci:stm32 || echo "assume mcci:samd already installed, continue"
- arduino --install-boards esp32:esp32 || echo "assume esp32:esp32 already installed, condtinue"
- 'if [ -d $HOME/.arduino15/packages/mcci/hardware/stm32/1.1.0 ]; then echo "Work around broken BSP version 1.1.0" ; export MCCI_STM32_OPTS="$MCCI_STM32_OPTS --pref build.board=CATENA_4551" ; fi'

cache:
directories:
- $HOME/.arduino15
- $HOME/arduino_ide

script:

# simple header file test
- arduino --verify --board $(_samdopts) $PWD/examples/header_test/header_test.ino
- arduino --verify --board $(_stm32l0opts) $MCCI_STM32_OPTS $PWD/examples/header_test/header_test.ino

#
# *** TESTS for ESP32
#
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board $(_esp32opts '' projcfg) $PWD/examples/ttn-otaa/ttn-otaa.ino
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board $(_esp32opts '' projcfg) $PWD/examples/ttn-abp/ttn-abp.ino
# make sure debug works
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio LMIC_DEBUG_LEVEL=2 LMIC_PRINTF_TO=Serial && arduino --verify --board $(_esp32opts '' projcfg) $PWD/examples/ttn-otaa/ttn-otaa.ino

#
# *** Tests for Feather 32u4
# The Adafruit BSP doesn't support the BSP selection options; so we have to use projcfg
Expand All @@ -83,6 +99,9 @@ script:
- _projcfg COMPILE_REGRESSION_TEST CFG_as923jp CFG_sx1276_radio && arduino --verify --board $(_avropts) $PWD/examples/raw-feather/raw-feather.ino
- _projcfg COMPILE_REGRESSION_TEST CFG_in866 CFG_sx1276_radio && arduino --verify --board $(_avropts) $PWD/examples/raw-feather/raw-feather.ino

# make sure debug prints work
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio LMIC_DEBUG_LEVEL=2 LMIC_PRINTF_TO=Serial && arduino --verify --board $(_avropts) $PWD/examples/raw-feather/raw-feather.ino

#
# *** Tests for SAMD
#
Expand All @@ -109,6 +128,9 @@ script:
#
# test ttn-otaa-feather-us915 with interrupts
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio LMIC_USE_INTERRUPTS && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino
# check that debug prints work
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio LMIC_DEBUG_LEVEL=1 LMIC_PRINTF_TO=Serial && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio LMIC_DEBUG_LEVEL=2 LMIC_PRINTF_TO=Serial && arduino --verify --board mcci:samd:mcci_catena_4450:lorawan_region=projcfg $PWD/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino

#
# test raw feather with au921
Expand Down Expand Up @@ -161,7 +183,6 @@ script:

#
# *** TESTS FOR STM32L0 / Catena 4551 ****
# make sure you install the BSP above.
#
- arduino --verify --board $(_stm32l0opts '' us915 ) $MCCI_STM32_OPTS $PWD/examples/raw-feather/raw-feather.ino
- arduino --verify --board $(_stm32l0opts '' eu868 ) $MCCI_STM32_OPTS $PWD/examples/raw-feather/raw-feather.ino
Expand All @@ -173,4 +194,4 @@ script:
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board $(_stm32l0opts '' projcfg) $MCCI_STM32_OPTS $PWD/examples/ttn-otaa/ttn-otaa.ino
- _projcfg COMPILE_REGRESSION_TEST CFG_us915 CFG_sx1276_radio && arduino --verify --board $(_stm32l0opts '' projcfg) $MCCI_STM32_OPTS $PWD/examples/ttn-abp/ttn-abp.ino

### end of file ###
### end of file ###
9 changes: 5 additions & 4 deletions src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ void hal_sleep () {
// -----------------------------------------------------------------------------

#if defined(LMIC_PRINTF_TO)
#if defined(ESP8266) || defined(ESP31B) || defined(ESP32)
//ESPXX specific PRINTF, only tested with ESP32 Haltec LoRA Wifi so far
#if !defined(__AVR)
static ssize_t uart_putchar (void *, const char *buf, size_t len) {
return LMIC_PRINTF_TO.write((const uint8_t *)buf, len);
}
Expand All @@ -292,9 +291,11 @@ static cookie_io_functions_t functions =

void hal_printf_init() {
stdout = fopencookie(NULL, "w", functions);
if (stdout != nullptr) {
setvbuf(stdout, NULL, _IONBF, 0);
}
}
#else // !defined(ESP8266) || defined(ESP31B) || defined(ESP32)
// all else, like AVR
#else // defined(__AVR)
static int uart_putchar (char c, FILE *)
{
LMIC_PRINTF_TO.write(c) ;
Expand Down
1 change: 1 addition & 0 deletions src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
# else // ndef LMIC_DEBUG_PRINTF_FN
// if there's no other info, just use printf. In a pure Arduino environment,
// that's what will happen.
# include <stdio.h>
# define LMIC_DEBUG_PRINTF(f, ...) printf(f, ## __VA_ARGS__)
# endif // ndef LMIC_DEBUG_PRINTF_FN
# endif // ndef LMIC_DEBUG_PRINTF
Expand Down

0 comments on commit 04b5789

Please sign in to comment.