diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..80874dd4 Binary files /dev/null and b/.DS_Store differ diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 00000000..b1b9d7cb Binary files /dev/null and b/examples/.DS_Store differ diff --git a/examples/unit-test/.DS_Store b/examples/unit-test/.DS_Store new file mode 100644 index 00000000..75baee7d Binary files /dev/null and b/examples/unit-test/.DS_Store differ diff --git a/examples/unit-test/mbed-blink/.gitignore b/examples/unit-test/mbed-blink/.gitignore new file mode 100644 index 00000000..aebf6786 --- /dev/null +++ b/examples/unit-test/mbed-blink/.gitignore @@ -0,0 +1,5 @@ +.pioenvs +.clang_complete +.gcc-flags.json +.piolibdeps +.DS_Store \ No newline at end of file diff --git a/examples/unit-test/mbed-blink/.travis.yml b/examples/unit-test/mbed-blink/.travis.yml new file mode 100644 index 00000000..72c6e43f --- /dev/null +++ b/examples/unit-test/mbed-blink/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/stable/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/stable/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/stable/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/unit-test/mbed-blink/lib/readme.txt b/examples/unit-test/mbed-blink/lib/readme.txt new file mode 100644 index 00000000..3f9e008a --- /dev/null +++ b/examples/unit-test/mbed-blink/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/en/stable/librarymanager/ldf.html diff --git a/examples/unit-test/mbed-blink/platformio.ini b/examples/unit-test/mbed-blink/platformio.ini new file mode 100644 index 00000000..4b289e12 --- /dev/null +++ b/examples/unit-test/mbed-blink/platformio.ini @@ -0,0 +1,40 @@ +# ; PlatformIO Project Configuration File +# ; +# ; Build options: build flags, source filter, extra scripting +# ; Upload options: custom port, speed and extra flags +# ; Library options: dependencies, extra library storages +# ; +# ; Please visit documentation for the other options and examples +# ; http://docs.platformio.org/en/stable/projectconf.html + +[env:bluepill_f103c8] +platform = ststm32 +board = bluepill_f103c8 +framework = mbed +upload_protocol = gdb +#This is the built in Serial passthrough for the Blackmagic Probe +test_port = /dev/cu.usbmodemBFDEA5F3 +build_flags = -DSTM32F1 + +[env:nucleo_f030r8] +platform = ststm32 +board = nucleo_f030r8 +framework = mbed +upload_protocol = stlink +build_flags = -DSTM32F0 +#This is a FT232 USB Serial Converter +test_port = /dev/cu.usbserial-A900ZD1K + +#Run "pio device list" to get a list of available serial ports +#in the system. Connect the TX,RX to the RX,TX of USART1 in the target + +#The build flags are specified to allow for conditional compilation +#of the program to allow for differences between different dev boards + +#The STM32F030R8 discovery uses the Nucleo F030R8 template and +#specifies "stlink" as the upload protocol, removing the need for +#any external programmer + +#Also need to correct the correct clock source and frequency +#in the STM32F030R8 discovery board. The program functions +#but blinks much faster than the specified 1 second delay diff --git a/examples/unit-test/mbed-blink/src/main.cpp b/examples/unit-test/mbed-blink/src/main.cpp new file mode 100644 index 00000000..f4154e1d --- /dev/null +++ b/examples/unit-test/mbed-blink/src/main.cpp @@ -0,0 +1,25 @@ +#include "mbed.h" + +#ifndef UNIT_TEST + +/*The leds are connected to different port pins on the +bluepill F103C8 and Disco F030R8 boards +*/ + +#ifdef STM32F1 +DigitalOut myled(PC_13); +#endif +#ifdef STM32F0 +DigitalOut myled(PC_9); +#endif + +int main(void) +{ + while (1) { + myled = 1; + wait(1); + myled = 0; + wait(1); + } +} +#endif diff --git a/examples/unit-test/mbed-blink/test/test_main.cpp b/examples/unit-test/mbed-blink/test/test_main.cpp new file mode 100644 index 00000000..20e9932a --- /dev/null +++ b/examples/unit-test/mbed-blink/test/test_main.cpp @@ -0,0 +1,41 @@ +#include "mbed.h" +#include "unity.h" + +#ifdef UNIT_TEST + +#ifdef STM32F1 +DigitalOut myled(PC_13); +#endif +#ifdef STM32F0 +DigitalOut myled(PC_9); +#endif + + +void test_led_write_high(void) +{ + myled.write(1); + TEST_ASSERT_EQUAL(myled.read(), 1); +} + +void test_led_write_low(void) +{ + myled.write(0); + TEST_ASSERT_EQUAL(myled.read(), 0); +} + +int main(void) +{ + UNITY_BEGIN(); + + wait(1); +// Without the above delay, the console does not print the PASS/FAIL message +// for the first couple of unit tests + RUN_TEST(test_led_write_high); + wait(0.5); + RUN_TEST(test_led_write_low); + wait(0.5); + UNITY_END(); +} + + +#endif diff --git a/examples/unit-test/mbed-blink/upload.gdb b/examples/unit-test/mbed-blink/upload.gdb new file mode 100644 index 00000000..65b59a5d --- /dev/null +++ b/examples/unit-test/mbed-blink/upload.gdb @@ -0,0 +1,6 @@ +target extended-remote /dev/cu.usbmodemBFDEA5F1 +monitor swdp_scan +attach 1 +load +quit +yes