diff --git a/.travis.yml b/.travis.yml index d04407b8..6b6a39f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,9 +28,29 @@ env: - PLATFORMIO_PROJECT_DIR=examples/spl-blink - PLATFORMIO_PROJECT_DIR=examples/stm32cube-hal-blink - PLATFORMIO_PROJECT_DIR=examples/stm32cube-ll-blink + - PLATFORMIO_PROJECT_DIR=examples/zephyr-blink + - PLATFORMIO_PROJECT_DIR=examples/zephyr-cpp-synchronization + - PLATFORMIO_PROJECT_DIR=examples/zephyr-drivers-can + - PLATFORMIO_PROJECT_DIR=examples/zephyr-net-https-client + - PLATFORMIO_PROJECT_DIR=examples/zephyr-subsys-usb-hid-mouse - PLATFORMIO_PROJECT_DIR=tests/arduino-blink-different-cores - PLATFORMIO_PROJECT_DIR=tests/mbed-filesystem +# Zephyr framework doesn't support python 2 +jobs: + exclude: + - python: "2.7" + env: PLATFORMIO_PROJECT_DIR=examples/zephyr-blink + - python: "2.7" + env: PLATFORMIO_PROJECT_DIR=examples/zephyr-cpp-synchronization + - python: "2.7" + env: PLATFORMIO_PROJECT_DIR=examples/zephyr-drivers-can + - python: "2.7" + env: PLATFORMIO_PROJECT_DIR=examples/zephyr-net-https-client + - python: "2.7" + env: PLATFORMIO_PROJECT_DIR=examples/zephyr-subsys-usb-hid-mouse + + install: - pip install -U https://github.com/platformio/platformio/archive/develop.zip - platformio platform install file://. diff --git a/appveyor.yml b/appveyor.yml index 53d7beb6..63cc627c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,12 +26,17 @@ environment: - PLATFORMIO_PROJECT_DIR: "examples/spl-blink" - PLATFORMIO_PROJECT_DIR: "examples/stm32cube-hal-blink" - PLATFORMIO_PROJECT_DIR: "examples/stm32cube-ll-blink" + - PLATFORMIO_PROJECT_DIR: "examples/zephyr-blink" + - PLATFORMIO_PROJECT_DIR: "examples/zephyr-cpp-synchronization" + - PLATFORMIO_PROJECT_DIR: "examples/zephyr-drivers-can" + - PLATFORMIO_PROJECT_DIR: "examples/zephyr-modules" + - PLATFORMIO_PROJECT_DIR: "examples/zephyr-subsys-usb-hid-mouse" - PLATFORMIO_PROJECT_DIR: "tests/arduino-blink-different-cores" - PLATFORMIO_PROJECT_DIR: "tests/mbed-filesystem" install: - cmd: git submodule update --init --recursive - - cmd: SET PATH=%PATH%;C:\Python36\Scripts + - cmd: SET PATH=C:\Python36\Scripts;%PATH% - cmd: pip3 install -U https://github.com/platformio/platformio/archive/develop.zip - cmd: platformio platform install file://. diff --git a/boards/b96b_f446ve.json b/boards/b96b_f446ve.json index 1a1ffab3..537dd285 100644 --- a/boards/b96b_f446ve.json +++ b/boards/b96b_f446ve.json @@ -3,7 +3,10 @@ "cpu": "cortex-m4", "extra_flags": "-DSTM32F446xx", "f_cpu": "168000000L", - "mcu": "stm32f446vet6" + "mcu": "stm32f446vet6", + "zephyr": { + "variant": "96b_stm32_sensor_mez" + } }, "connectivity": [ "can" @@ -21,7 +24,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "96Boards B96B-F446VE", "upload": { diff --git a/boards/blackpill_f103c8.json b/boards/blackpill_f103c8.json index 979f28ae..eff54ad3 100644 --- a/boards/blackpill_f103c8.json +++ b/boards/blackpill_f103c8.json @@ -16,7 +16,10 @@ ], "ldscript": "stm32f103x8.ld", "mcu": "stm32f103c8t6", - "variant": "PILL_F103XX" + "variant": "PILL_F103XX", + "zephyr": { + "variant": "stm32_min_dev_black" + } }, "debug": { "default_tools": [ @@ -34,7 +37,8 @@ "arduino", "cmsis", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "BlackPill F103C8", "upload": { diff --git a/boards/blackpill_f103c8_128.json b/boards/blackpill_f103c8_128.json index 25c901cd..c5265b16 100644 --- a/boards/blackpill_f103c8_128.json +++ b/boards/blackpill_f103c8_128.json @@ -16,7 +16,10 @@ ], "ldscript": "ldscript_cb.ld", "mcu": "stm32f103c8t6", - "variant": "PILL_F103XX" + "variant": "PILL_F103XX", + "zephyr": { + "variant": "stm32_min_dev_black" + } }, "debug": { "default_tools": [ @@ -34,7 +37,8 @@ "arduino", "cmsis", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "BlackPill F103C8 (128k)", "upload": { diff --git a/boards/bluepill_f103c8.json b/boards/bluepill_f103c8.json index 4ac8643a..017e20f8 100644 --- a/boards/bluepill_f103c8.json +++ b/boards/bluepill_f103c8.json @@ -16,7 +16,10 @@ ], "ldscript": "stm32f103x8.ld", "mcu": "stm32f103c8t6", - "variant": "PILL_F103XX" + "variant": "PILL_F103XX", + "zephyr": { + "variant": "stm32_min_dev_blue" + } }, "debug": { "default_tools": [ @@ -35,7 +38,8 @@ "mbed", "cmsis", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "BluePill F103C8", "upload": { diff --git a/boards/bluepill_f103c8_128k.json b/boards/bluepill_f103c8_128k.json index e6c4ced7..06d3447a 100644 --- a/boards/bluepill_f103c8_128k.json +++ b/boards/bluepill_f103c8_128k.json @@ -16,7 +16,10 @@ ], "ldscript": "ldscript_cb.ld", "mcu": "stm32f103c8t6", - "variant": "PILL_F103XX" + "variant": "PILL_F103XX", + "zephyr": { + "variant": "stm32_min_dev_blue" + } }, "debug": { "default_tools": [ @@ -34,7 +37,8 @@ "arduino", "cmsis", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "BluePill F103C8 (128k)", "upload": { diff --git a/boards/disco_f051r8.json b/boards/disco_f051r8.json index 48f0e272..ddbcb413 100644 --- a/boards/disco_f051r8.json +++ b/boards/disco_f051r8.json @@ -3,7 +3,10 @@ "cpu": "cortex-m0", "extra_flags": "-DSTM32F051x8", "f_cpu": "48000000L", - "mcu": "stm32f051r8t6" + "mcu": "stm32f051r8t6", + "zephyr": { + "variant": "stm32f0_disco" + } }, "debug": { "default_tools": [ @@ -18,7 +21,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST STM32F0DISCOVERY", "upload": { diff --git a/boards/disco_f072rb.json b/boards/disco_f072rb.json index 92eb1508..3cbfe856 100644 --- a/boards/disco_f072rb.json +++ b/boards/disco_f072rb.json @@ -4,7 +4,10 @@ "extra_flags": "-DSTM32F072xB", "f_cpu": "48000000L", "mcu": "stm32f072rbt6", - "variant": "DISCO_F072RB" + "variant": "DISCO_F072RB", + "zephyr": { + "variant": "stm32f072b_disco" + } }, "connectivity": [ "can" @@ -24,7 +27,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Discovery F072RB", "upload": { diff --git a/boards/disco_f303vc.json b/boards/disco_f303vc.json index b03ca808..21b182bb 100644 --- a/boards/disco_f303vc.json +++ b/boards/disco_f303vc.json @@ -6,7 +6,10 @@ "f_cpu": "72000000L", "ldscript": "stm32f30xx.ld", "mcu": "stm32f303vct6", - "variant": "stm32f303xc" + "variant": "stm32f303xc", + "zephyr": { + "variant": "stm32f3_disco" + } }, "debug": { "default_tools": [ @@ -24,7 +27,8 @@ "cmsis", "spl", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST STM32F3DISCOVERY", "upload": { diff --git a/boards/disco_f407vg.json b/boards/disco_f407vg.json index 140b30ac..e22a4954 100644 --- a/boards/disco_f407vg.json +++ b/boards/disco_f407vg.json @@ -6,7 +6,10 @@ "f_cpu": "168000000L", "ldscript": "stm32f405x6.ld", "mcu": "stm32f407vgt6", - "variant": "DISCO_F407VG" + "variant": "DISCO_F407VG", + "zephyr": { + "variant": "stm32f4_disco" + } }, "debug": { "default_tools": [ @@ -25,7 +28,8 @@ "cmsis", "spl", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST STM32F4DISCOVERY", "upload": { diff --git a/boards/disco_f411ve.json b/boards/disco_f411ve.json index 44746b8b..ae836b82 100644 --- a/boards/disco_f411ve.json +++ b/boards/disco_f411ve.json @@ -1,9 +1,12 @@ { "build": { "cpu": "cortex-m4", - "extra_flags": "-DSTM32F411xE", + "extra_flags": "-DSTM32F4 -DSTM32F411xE", "f_cpu": "100000000L", - "mcu": "stm32f411vet6" + "mcu": "stm32f411vet6", + "zephyr": { + "variant": "stm32f411e_disco" + } }, "debug": { "default_tools": [ @@ -17,7 +20,9 @@ "svd_path": "STM32F411xx.svd" }, "frameworks": [ - "stm32cube" + "cmsis", + "stm32cube", + "zephyr" ], "name": "ST 32F411EDISCOVERY", "upload": { diff --git a/boards/disco_f412zg.json b/boards/disco_f412zg.json new file mode 100644 index 00000000..c8e9df91 --- /dev/null +++ b/boards/disco_f412zg.json @@ -0,0 +1,41 @@ +{ + "build": { + "cpu": "cortex-m4", + "extra_flags": "-DSTM32F412Zx", + "f_cpu": "100000000L", + "mcu": "stm32f412zgt6", + "zephyr": { + "variant": "stm32f412g_disco" + } + }, + "debug": { + "default_tools": [ + "stlink" + ], + "jlink_device": "STM32F412ZG", + "onboard_tools": [ + "stlink" + ], + "openocd_board": "st_nucleo_f4", + "svd_path": "STM32F41x.svd" + }, + "frameworks": [ + "mbed", + "stm32cube", + "zephyr" + ], + "name": "32F412GDISCOVERY", + "upload": { + "maximum_ram_size": 262144, + "maximum_size": 1048576, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic", + "mbed" + ] + }, + "url": "https://www.st.com/en/evaluation-tools/32f412gdiscovery.html", + "vendor": "ST" +} diff --git a/boards/disco_f429zi.json b/boards/disco_f429zi.json index fb765c9d..0527f49d 100644 --- a/boards/disco_f429zi.json +++ b/boards/disco_f429zi.json @@ -1,9 +1,12 @@ { "build": { "cpu": "cortex-m4", - "extra_flags": "-DSTM32F429xx", + "extra_flags": "-DSTM32F4 -DSTM32F429xx", "f_cpu": "180000000L", - "mcu": "stm32f429zit6" + "mcu": "stm32f429zit6", + "zephyr": { + "variant": "stm32f429i_disc1" + } }, "connectivity": [ "can" @@ -20,8 +23,10 @@ "svd_path": "STM32F429x.svd" }, "frameworks": [ + "cmsis", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST 32F429IDISCOVERY", "upload": { diff --git a/boards/disco_f469ni.json b/boards/disco_f469ni.json index 4d2e1ff2..bfe5da6a 100644 --- a/boards/disco_f469ni.json +++ b/boards/disco_f469ni.json @@ -1,9 +1,12 @@ { "build": { "cpu": "cortex-m4", - "extra_flags": "-DSTM32F469xx", + "extra_flags": "-DSTM32F4 -DSTM32F469xx", "f_cpu": "180000000L", - "mcu": "stm32f469nih6" + "mcu": "stm32f469nih6", + "zephyr": { + "variant": "stm32f469i_disco" + } }, "connectivity": [ "can" @@ -20,8 +23,10 @@ "svd_path": "STM32F46_79x.svd" }, "frameworks": [ + "cmsis", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST 32F469IDISCOVERY", "upload": { diff --git a/boards/disco_f723ie.json b/boards/disco_f723ie.json index 37b80983..98be67b9 100644 --- a/boards/disco_f723ie.json +++ b/boards/disco_f723ie.json @@ -3,7 +3,10 @@ "cpu": "cortex-m7", "extra_flags": "-DSTM32F723xx", "f_cpu": "216000000L", - "mcu": "stm32f723iek6" + "mcu": "stm32f723iek6", + "zephyr": { + "variant": "stm32f723e_disco" + } }, "connectivity": [ "can", @@ -21,7 +24,8 @@ "svd_path": "STM32F7x3.svd" }, "frameworks": [ - "stm32cube" + "stm32cube", + "zephyr" ], "name": "32F723EDISCOVERY", "upload": { diff --git a/boards/disco_f746ng.json b/boards/disco_f746ng.json index 2e2522c5..dce3b982 100644 --- a/boards/disco_f746ng.json +++ b/boards/disco_f746ng.json @@ -4,7 +4,10 @@ "extra_flags": "-DSTM32F746xx", "f_cpu": "216000000L", "mcu": "stm32f746ngh6", - "variant": "DISCO_F746NG" + "variant": "DISCO_F746NG", + "zephyr": { + "variant": "stm32f746g_disco" + } }, "connectivity": [ "can", @@ -24,7 +27,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST 32F746GDISCOVERY", "upload": { diff --git a/boards/disco_f769ni.json b/boards/disco_f769ni.json index ac3f6b79..50daa2b6 100644 --- a/boards/disco_f769ni.json +++ b/boards/disco_f769ni.json @@ -3,7 +3,10 @@ "cpu": "cortex-m7", "extra_flags": "-DSTM32F769xx", "f_cpu": "216000000L", - "mcu": "stm32f769nih6" + "mcu": "stm32f769nih6", + "zephyr": { + "variant": "stm32f769i_disco" + } }, "connectivity": [ "can", @@ -22,7 +25,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST 32F769IDISCOVERY", "upload": { diff --git a/boards/disco_h743xi.json b/boards/disco_h743xi.json new file mode 100644 index 00000000..9845ffec --- /dev/null +++ b/boards/disco_h743xi.json @@ -0,0 +1,44 @@ +{ + "build": { + "cpu": "cortex-m7", + "extra_flags": "-DSTM32H7xx -DSTM32H747xx", + "f_cpu": "400000000L", + "mcu": "stm32h747xih6", + "zephyr": { + "variant": "stm32h747i_disco_m7" + } + }, + "connectivity": [ + "can", + "ethernet" + ], + "debug": { + "default_tools": [ + "stlink" + ], + "jlink_device": "STM32H747XI", + "onboard_tools": [ + "stlink" + ], + "openocd_board": "st_nucleo_h743zi", + "svd_path": "STM32H7x7.svd" + }, + "frameworks": [ + "stm32cube", + "zephyr" + ], + "name": "STM32H747I-DISCO", + "upload": { + "maximum_ram_size": 524288, + "maximum_size": 2097152, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic", + "mbed" + ] + }, + "url": "https://www.st.com/en/evaluation-tools/stm32h747i-disco.html", + "vendor": "ST" +} diff --git a/boards/disco_l072cz_lrwan1.json b/boards/disco_l072cz_lrwan1.json index 83cbfdc4..041ee0b3 100644 --- a/boards/disco_l072cz_lrwan1.json +++ b/boards/disco_l072cz_lrwan1.json @@ -7,7 +7,10 @@ "arduino": "-D__CORTEX_SC=0" }, "mcu": "stm32l072cz", - "variant": "DISCO_L072CZ_LRWAN1" + "variant": "DISCO_L072CZ_LRWAN1", + "zephyr": { + "variant": "b_l072z_lrwan1" + } }, "debug": { "default_tools": [ @@ -23,7 +26,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST DISCO-L072CZ-LRWAN1", "upload": { diff --git a/boards/disco_l475vg_iot01a.json b/boards/disco_l475vg_iot01a.json index 76986933..ae283885 100644 --- a/boards/disco_l475vg_iot01a.json +++ b/boards/disco_l475vg_iot01a.json @@ -7,7 +7,10 @@ "arduino": "-DARDUINO_DISCO_L475VG_IOT" }, "mcu": "stm32l475vgt6", - "variant": "DISCO_L475VG_IOT" + "variant": "DISCO_L475VG_IOT", + "zephyr": { + "variant": "disco_l475_iot1" + } }, "connectivity": [ "bluetooth", @@ -28,7 +31,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST DISCO-L475VG-IOT01A", "upload": { diff --git a/boards/disco_l476vg.json b/boards/disco_l476vg.json index 9e6f9f51..301444f8 100644 --- a/boards/disco_l476vg.json +++ b/boards/disco_l476vg.json @@ -3,7 +3,10 @@ "cpu": "cortex-m4", "extra_flags": "-DSTM32L476xx", "f_cpu": "80000000L", - "mcu": "stm32l476vgt6" + "mcu": "stm32l476vgt6", + "zephyr": { + "variant": "stm32l476g_disco" + } }, "connectivity": [ "can" @@ -21,7 +24,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST 32L476GDISCOVERY", "upload": { diff --git a/boards/disco_l496ag.json b/boards/disco_l496ag.json index 217e92a2..aa5ff7d8 100644 --- a/boards/disco_l496ag.json +++ b/boards/disco_l496ag.json @@ -3,7 +3,10 @@ "cpu": "cortex-m4", "extra_flags": "-DSTM32L496xx", "f_cpu": "80000000L", - "mcu": "stm32l496agi6" + "mcu": "stm32l496agi6", + "zephyr": { + "variant": "stm32l496g_disco" + } }, "connectivity": [ "can" @@ -21,7 +24,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST 32L496GDISCOVERY", "upload": { diff --git a/boards/eval_f072vb.json b/boards/eval_f072vb.json new file mode 100644 index 00000000..d0fa95ab --- /dev/null +++ b/boards/eval_f072vb.json @@ -0,0 +1,36 @@ +{ + "build": { + "cpu": "cortex-m0", + "extra_flags": "-DSTM32F072xB", + "f_cpu": "48000000L", + "mcu": "stm32f072vbt6", + "zephyr": { + "variant": "stm32f072_eval" + } + }, + "connectivity": [ + "can" + ], + "debug": { + "jlink_device": "STM32F072VB", + "openocd_target": "stm32f0x", + "svd_path": "STM32F072x.svd" + }, + "frameworks": [ + "stm32cube", + "zephyr" + ], + "name": "STM32F072-EVAL", + "upload": { + "maximum_ram_size": 16384, + "maximum_size": 131072, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://www.st.com/en/evaluation-tools/stm32072b-eval.html", + "vendor": "ST" +} diff --git a/boards/eval_f107vc.json b/boards/eval_f107vc.json new file mode 100644 index 00000000..e9551b31 --- /dev/null +++ b/boards/eval_f107vc.json @@ -0,0 +1,35 @@ +{ + "build": { + "cpu": "cortex-m3", + "extra_flags": "-DSTM32F107xC -DSTM32F1", + "f_cpu": "72000000L", + "ldscript": "stm32f107xe.ld", + "mcu": "stm32f107vct6", + "zephyr": { + "variant": "stm3210c_eval" + } + }, + "debug": { + "jlink_device": "STM32F107VC", + "openocd_target": "stm32f1x", + "svd_path": "STM32F107xx.svd" + }, + "frameworks": [ + "cmsis", + "stm32cube", + "zephyr" + ], + "name": "STM3210C-EVAL", + "upload": { + "maximum_ram_size": 65536, + "maximum_size": 262144, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://www.st.com/en/evaluation-tools/stm3210c-eval.html", + "vendor": "ST" +} diff --git a/boards/eval_f373vc.json b/boards/eval_f373vc.json new file mode 100644 index 00000000..98232aae --- /dev/null +++ b/boards/eval_f373vc.json @@ -0,0 +1,37 @@ +{ + "build": { + "cpu": "cortex-m4", + "extra_flags": "-DSTM32F3 -DSTM32F373xC", + "f_cpu": "72000000L", + "ldscript": "stm32f30xx.ld", + "mcu": "stm32f373vct6", + "zephyr": { + "variant": "stm32373c_eval" + } + }, + "connectivity": [ + "can" + ], + "debug": { + "jlink_device": "STM32F373VC", + "openocd_target": "stm32f3x", + "svd_path": "STM32F30x.svd" + }, + "frameworks": [ + "stm32cube", + "zephyr" + ], + "name": "STM32373C-EVAL", + "upload": { + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://www.st.com/en/evaluation-tools/stm32373c-eval.html", + "vendor": "ST" +} diff --git a/boards/nucleo_f030r8.json b/boards/nucleo_f030r8.json index 846f12f0..956cb95e 100644 --- a/boards/nucleo_f030r8.json +++ b/boards/nucleo_f030r8.json @@ -20,7 +20,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F030R8", "upload": { diff --git a/boards/nucleo_f070rb.json b/boards/nucleo_f070rb.json index 65af24ae..9e3d09ef 100644 --- a/boards/nucleo_f070rb.json +++ b/boards/nucleo_f070rb.json @@ -18,7 +18,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F070RB", "upload": { diff --git a/boards/nucleo_f091rc.json b/boards/nucleo_f091rc.json index 2a6b98f2..9aa6c864 100644 --- a/boards/nucleo_f091rc.json +++ b/boards/nucleo_f091rc.json @@ -23,7 +23,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F091RC", "upload": { diff --git a/boards/nucleo_f103rb.json b/boards/nucleo_f103rb.json index 4037ea9c..16c38dd9 100644 --- a/boards/nucleo_f103rb.json +++ b/boards/nucleo_f103rb.json @@ -23,7 +23,8 @@ "arduino", "mbed", "libopencm3", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F103RB", "upload": { diff --git a/boards/nucleo_f207zg.json b/boards/nucleo_f207zg.json index ae5a7c1e..c09bc841 100644 --- a/boards/nucleo_f207zg.json +++ b/boards/nucleo_f207zg.json @@ -25,7 +25,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F207ZG", "upload": { diff --git a/boards/nucleo_f302r8.json b/boards/nucleo_f302r8.json index 5eaeb977..05deae1a 100644 --- a/boards/nucleo_f302r8.json +++ b/boards/nucleo_f302r8.json @@ -23,7 +23,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F302R8", "upload": { diff --git a/boards/nucleo_f334r8.json b/boards/nucleo_f334r8.json index b6998811..5f7347ce 100644 --- a/boards/nucleo_f334r8.json +++ b/boards/nucleo_f334r8.json @@ -21,7 +21,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F334R8", "upload": { diff --git a/boards/nucleo_f401re.json b/boards/nucleo_f401re.json index fdb98343..2a09dbce 100644 --- a/boards/nucleo_f401re.json +++ b/boards/nucleo_f401re.json @@ -24,7 +24,8 @@ "mbed", "cmsis", "spl", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F401RE", "upload": { diff --git a/boards/nucleo_f411re.json b/boards/nucleo_f411re.json index 21c3449b..77cedfa9 100644 --- a/boards/nucleo_f411re.json +++ b/boards/nucleo_f411re.json @@ -20,7 +20,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F411RE", "upload": { diff --git a/boards/nucleo_f412zg.json b/boards/nucleo_f412zg.json index c570f53e..38b60d10 100644 --- a/boards/nucleo_f412zg.json +++ b/boards/nucleo_f412zg.json @@ -18,7 +18,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F412ZG", "upload": { diff --git a/boards/nucleo_f413zh.json b/boards/nucleo_f413zh.json index 23b25cab..63985022 100644 --- a/boards/nucleo_f413zh.json +++ b/boards/nucleo_f413zh.json @@ -21,7 +21,8 @@ }, "frameworks": [ "stm32cube", - "mbed" + "mbed", + "zephyr" ], "name": "ST Nucleo F413ZH", "upload": { diff --git a/boards/nucleo_f429zi.json b/boards/nucleo_f429zi.json index 7edf7bed..2ade0422 100644 --- a/boards/nucleo_f429zi.json +++ b/boards/nucleo_f429zi.json @@ -24,7 +24,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F429ZI", "upload": { diff --git a/boards/nucleo_f746zg.json b/boards/nucleo_f746zg.json index 8d732d31..c9b9489a 100644 --- a/boards/nucleo_f746zg.json +++ b/boards/nucleo_f746zg.json @@ -22,7 +22,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F746ZG", "upload": { diff --git a/boards/nucleo_f756zg.json b/boards/nucleo_f756zg.json index e64a7b57..79aadb42 100644 --- a/boards/nucleo_f756zg.json +++ b/boards/nucleo_f756zg.json @@ -22,7 +22,8 @@ }, "frameworks": [ "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo F756ZG", "upload": { diff --git a/boards/nucleo_g071rb.json b/boards/nucleo_g071rb.json index c368c86a..25c5e416 100644 --- a/boards/nucleo_g071rb.json +++ b/boards/nucleo_g071rb.json @@ -3,7 +3,7 @@ "core": "stm32", "cpu": "cortex-m0plus", "extra_flags": "-DSTM32G0xx -DSTM32G071xx", - "f_cpu": "24000000L", + "f_cpu": "64000000L", "framework_extra_flags": { "arduino": "-D__CORTEX_SC=0" }, @@ -15,12 +15,13 @@ "svd_path": "STM32G071.svd" }, "frameworks": [ - "arduino" + "arduino", + "zephyr" ], "name": "Nucleo G071RB", "upload": { - "maximum_ram_size": 131072, - "maximum_size": 2097152, + "maximum_ram_size": 36864, + "maximum_size": 131072, "protocol": "mbed", "protocols": [ "jlink", diff --git a/boards/nucleo_g431kb.json b/boards/nucleo_g431kb.json index 3793a769..28626182 100644 --- a/boards/nucleo_g431kb.json +++ b/boards/nucleo_g431kb.json @@ -3,7 +3,7 @@ "core": "stm32", "cpu": "cortex-m4", "extra_flags": "-DSTM32G4xx -DSTM32G431xx", - "f_cpu": "24000000L", + "f_cpu": "170000000L", "mcu": "stm32g431kbt6", "variant": "NUCLEO_G431KB" }, diff --git a/boards/nucleo_g431rb.json b/boards/nucleo_g431rb.json index bec96982..adbbad20 100644 --- a/boards/nucleo_g431rb.json +++ b/boards/nucleo_g431rb.json @@ -3,7 +3,7 @@ "core": "stm32", "cpu": "cortex-m4", "extra_flags": "-DSTM32G4xx -DSTM32G431xx", - "f_cpu": "24000000L", + "f_cpu": "170000000L", "mcu": "stm32g431rbt6", "variant": "NUCLEO_G431RB" }, diff --git a/boards/nucleo_g474re.json b/boards/nucleo_g474re.json index 06e017cb..307a5b97 100644 --- a/boards/nucleo_g474re.json +++ b/boards/nucleo_g474re.json @@ -3,7 +3,7 @@ "core": "stm32", "cpu": "cortex-m4", "extra_flags": "-DSTM32G4xx -DSTM32G474xx", - "f_cpu": "17000000L", + "f_cpu": "170000000L", "mcu": "stm32g474ret6", "variant": "NUCLEO_G474RE" }, diff --git a/boards/nucleo_l053r8.json b/boards/nucleo_l053r8.json index 75c9da58..6ffa9d64 100644 --- a/boards/nucleo_l053r8.json +++ b/boards/nucleo_l053r8.json @@ -23,7 +23,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo L053R8", "upload": { diff --git a/boards/nucleo_l073rz.json b/boards/nucleo_l073rz.json index 55efbd63..a3d75410 100644 --- a/boards/nucleo_l073rz.json +++ b/boards/nucleo_l073rz.json @@ -23,7 +23,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo L073RZ", "upload": { diff --git a/boards/nucleo_l432kc.json b/boards/nucleo_l432kc.json index 2659e6e5..c1504b03 100644 --- a/boards/nucleo_l432kc.json +++ b/boards/nucleo_l432kc.json @@ -20,7 +20,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo L432KC", "upload": { diff --git a/boards/nucleo_l476rg.json b/boards/nucleo_l476rg.json index b11b3029..c4a6422a 100644 --- a/boards/nucleo_l476rg.json +++ b/boards/nucleo_l476rg.json @@ -23,7 +23,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo L476RG", "upload": { diff --git a/boards/nucleo_l4r5zi.json b/boards/nucleo_l4r5zi.json index 14815676..4248fa92 100644 --- a/boards/nucleo_l4r5zi.json +++ b/boards/nucleo_l4r5zi.json @@ -23,7 +23,8 @@ "frameworks": [ "arduino", "mbed", - "stm32cube" + "stm32cube", + "zephyr" ], "name": "ST Nucleo L4R5ZI", "upload": { diff --git a/boards/olimex_e407.json b/boards/olimex_e407.json new file mode 100644 index 00000000..648efb65 --- /dev/null +++ b/boards/olimex_e407.json @@ -0,0 +1,44 @@ +{ + "build": { + "core": "stm32", + "cpu": "cortex-m4", + "extra_flags": "-DSTM32F4 -DSTM32F407xx -DSTM32F40_41xxx", + "f_cpu": "168000000L", + "framework_extra_flags": { + "arduino": "-DARDUINO_BLACK_F407ZG" + }, + "ldscript": "stm32f405x6.ld", + "mcu": "stm32f407zgt6", + "variant": "BLACK_F407XX", + "zephyr": { + "variant": "olimex_stm32_e407" + } + }, + "connectivity": [ + "can" + ], + "debug": { + "jlink_device": "STM32F407ZE", + "openocd_target": "stm32f4x", + "svd_path": "STM32F40x.svd" + }, + "frameworks": [ + "arduino", + "cmsis", + "stm32cube", + "zephyr" + ], + "name": "STM32-E407", + "upload": { + "maximum_ram_size": 131072, + "maximum_size": 1048576, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://docs.zephyrproject.org/latest/boards/arm/olimex_stm32_e407/doc/index.html", + "vendor": "Olimex" +} diff --git a/boards/olimex_h407.json b/boards/olimex_h407.json new file mode 100644 index 00000000..a1b170a2 --- /dev/null +++ b/boards/olimex_h407.json @@ -0,0 +1,44 @@ +{ + "build": { + "core": "stm32", + "cpu": "cortex-m4", + "extra_flags": "-DSTM32F4 -DSTM32F407xx -DSTM32F40_41xxx", + "f_cpu": "168000000L", + "framework_extra_flags": { + "arduino": "-DARDUINO_BLACK_F407ZG" + }, + "ldscript": "stm32f405x6.ld", + "mcu": "stm32f407zgt6", + "variant": "BLACK_F407XX", + "zephyr": { + "variant": "olimex_stm32_h407" + } + }, + "connectivity": [ + "can" + ], + "debug": { + "jlink_device": "STM32F407ZE", + "openocd_target": "stm32f4x", + "svd_path": "STM32F40x.svd" + }, + "frameworks": [ + "arduino", + "cmsis", + "stm32cube", + "zephyr" + ], + "name": "STM32-H407", + "upload": { + "maximum_ram_size": 131072, + "maximum_size": 1048576, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://docs.zephyrproject.org/latest/boards/arm/olimex_stm32_h407/doc/index.html", + "vendor": "Olimex" +} diff --git a/boards/olimex_p405.json b/boards/olimex_p405.json new file mode 100644 index 00000000..8e8da695 --- /dev/null +++ b/boards/olimex_p405.json @@ -0,0 +1,35 @@ +{ + "build": { + "core": "maple", + "cpu": "cortex-m4", + "extra_flags": "-DSTM32F4 -DSTM32F405xx", + "f_cpu": "168000000L", + "ldscript": "stm32f405xg.ld", + "mcu": "stm32f405rgt6", + "zephyr": { + "variant": "olimex_stm32_p405" + } + }, + "debug": { + "jlink_device": "STM32F405RG", + "openocd_target": "stm32f4x", + "svd_path": "STM32F40x.svd" + }, + "frameworks": [ + "stm32cube", + "zephyr" + ], + "name": "Olimex STM32-P405", + "upload": { + "maximum_ram_size": 196608, + "maximum_size": 1048576, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://docs.zephyrproject.org/latest/boards/arm/olimex_stm32_p405/doc/index.html", + "vendor": "Olimex" +} diff --git a/boards/olimexino.json b/boards/olimexino.json new file mode 100644 index 00000000..cfb04d2a --- /dev/null +++ b/boards/olimexino.json @@ -0,0 +1,39 @@ +{ + "build": { + "core": "stm32", + "cpu": "cortex-m3", + "extra_flags": "-DSTM32F103xB", + "f_cpu": "72000000L", + "ldscript": "stm32f103xb.ld", + "mcu": "stm32f103rbt6", + "variant": "NUCLEO_F103RB", + "zephyr": { + "variant": "olimexino_stm32" + } + }, + "debug": { + "jlink_device": "STM32F103RB", + "openocd_target": "stm32f1x", + "svd_path": "STM32F103xx.svd" + }, + "frameworks": [ + "arduino", + "mbed", + "libopencm3", + "stm32cube", + "zephyr" + ], + "name": "OLIMEXINO-STM32", + "upload": { + "maximum_ram_size": 20480, + "maximum_size": 131072, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic" + ] + }, + "url": "https://docs.zephyrproject.org/latest/boards/arm/olimexino_stm32/doc/index.html", + "vendor": "Olimex" +} diff --git a/builder/frameworks/zephyr.py b/builder/frameworks/zephyr.py new file mode 100644 index 00000000..87141e58 --- /dev/null +++ b/builder/frameworks/zephyr.py @@ -0,0 +1,30 @@ +# Copyright 2019-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +The Zephyr Project is a scalable real-time operating system (RTOS) supporting multiple +hardware architectures, optimized for resource constrained devices, and built with +safety and security in mind. + +https://github.com/zephyrproject-rtos/zephyr +""" + +from os.path import join + +from SCons.Script import Import, SConscript + +Import("env") + +SConscript( + join(env.PioPlatform().get_package_dir("framework-zephyr"), "scripts", + "platformio", "platformio-build.py"), exports="env") diff --git a/builder/main.py b/builder/main.py index a5d2015a..d1f2aacc 100644 --- a/builder/main.py +++ b/builder/main.py @@ -83,6 +83,13 @@ # Target: Build executable and linkable firmware # +if "zephyr" in env.get("PIOFRAMEWORK", []): + env.SConscript( + join(platform.get_package_dir( + "framework-zephyr"), "scripts", "platformio", "platformio-build-pre.py"), + exports={"env": env} + ) + target_elf = None if "nobuild" in COMMAND_LINE_TARGETS: target_elf = join("$BUILD_DIR", "${PROGNAME}.elf") diff --git a/examples/zephyr-blink/.gitignore b/examples/zephyr-blink/.gitignore new file mode 100644 index 00000000..aeaebb2b --- /dev/null +++ b/examples/zephyr-blink/.gitignore @@ -0,0 +1 @@ +.pio \ No newline at end of file diff --git a/examples/zephyr-blink/.travis.yml b/examples/zephyr-blink/.travis.yml new file mode 100644 index 00000000..7c486f18 --- /dev/null +++ b/examples/zephyr-blink/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/zephyr-blink/README.rst b/examples/zephyr-blink/README.rst new file mode 100644 index 00000000..8ec6d5d2 --- /dev/null +++ b/examples/zephyr-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-ststm32/examples/zephyr-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e blackpill_f103c8 + + # Upload firmware for the specific environment + > platformio run -e blackpill_f103c8 --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/zephyr-blink/include/README b/examples/zephyr-blink/include/README new file mode 100644 index 00000000..194dcd43 --- /dev/null +++ b/examples/zephyr-blink/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/zephyr-blink/lib/README b/examples/zephyr-blink/lib/README new file mode 100644 index 00000000..6debab1e --- /dev/null +++ b/examples/zephyr-blink/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/zephyr-blink/platformio.ini b/examples/zephyr-blink/platformio.ini new file mode 100644 index 00000000..5d6b1646 --- /dev/null +++ b/examples/zephyr-blink/platformio.ini @@ -0,0 +1,23 @@ +; 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/page/projectconf.html + +[env:blackpill_f103c8] +platform = ststm32 +framework = zephyr +board = blackpill_f103c8 + +[env:nucleo_f030r8] +platform = ststm32 +framework = zephyr +board = nucleo_f030r8 + +[env:nucleo_l073rz] +platform = ststm32 +framework = zephyr +board = nucleo_l073rz diff --git a/examples/zephyr-blink/src/main.c b/examples/zephyr-blink/src/main.c new file mode 100644 index 00000000..d5e99bbd --- /dev/null +++ b/examples/zephyr-blink/src/main.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER +#define LED DT_ALIAS_LED0_GPIOS_PIN + +/* 1000 msec = 1 sec */ +#define SLEEP_TIME 1000 + +void main(void) +{ + u32_t cnt = 0; + struct device *dev; + + dev = device_get_binding(LED_PORT); + /* Set LED pin as output */ + gpio_pin_configure(dev, LED, GPIO_DIR_OUT); + + while (1) { + /* Set pin to HIGH/LOW every 1 second */ + gpio_pin_write(dev, LED, cnt % 2); + cnt++; + k_sleep(SLEEP_TIME); + } +} diff --git a/examples/zephyr-blink/test/README b/examples/zephyr-blink/test/README new file mode 100644 index 00000000..df5066e6 --- /dev/null +++ b/examples/zephyr-blink/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/zephyr-blink/zephyr/CMakeLists.txt b/examples/zephyr-blink/zephyr/CMakeLists.txt new file mode 100644 index 00000000..dce86233 --- /dev/null +++ b/examples/zephyr-blink/zephyr/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(blinky) + +target_sources(app PRIVATE ../src/main.c) diff --git a/examples/zephyr-blink/zephyr/prj.conf b/examples/zephyr-blink/zephyr/prj.conf new file mode 100644 index 00000000..7bbd5afc --- /dev/null +++ b/examples/zephyr-blink/zephyr/prj.conf @@ -0,0 +1,2 @@ +CONFIG_GPIO=y +CONFIG_SERIAL=n diff --git a/examples/zephyr-cpp-synchronization/.gitignore b/examples/zephyr-cpp-synchronization/.gitignore new file mode 100644 index 00000000..aeaebb2b --- /dev/null +++ b/examples/zephyr-cpp-synchronization/.gitignore @@ -0,0 +1 @@ +.pio \ No newline at end of file diff --git a/examples/zephyr-cpp-synchronization/.travis.yml b/examples/zephyr-cpp-synchronization/.travis.yml new file mode 100644 index 00000000..7c486f18 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/zephyr-cpp-synchronization/README.rst b/examples/zephyr-cpp-synchronization/README.rst new file mode 100644 index 00000000..d06c3e5b --- /dev/null +++ b/examples/zephyr-cpp-synchronization/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-ststm32/examples/zephyr-cpp-synchronization + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e nucleo_f756zg + + # Upload firmware for the specific environment + > platformio run -e nucleo_f756zg --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/zephyr-cpp-synchronization/include/README b/examples/zephyr-cpp-synchronization/include/README new file mode 100644 index 00000000..194dcd43 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/zephyr-cpp-synchronization/lib/README b/examples/zephyr-cpp-synchronization/lib/README new file mode 100644 index 00000000..6debab1e --- /dev/null +++ b/examples/zephyr-cpp-synchronization/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/zephyr-cpp-synchronization/platformio.ini b/examples/zephyr-cpp-synchronization/platformio.ini new file mode 100644 index 00000000..5dd89f53 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/platformio.ini @@ -0,0 +1,26 @@ +; 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/page/projectconf.html + +[env:disco_l475vg_iot01a] +platform = ststm32 +framework = zephyr +board = disco_l475vg_iot01a +monitor_speed = 115200 + +[env:nucleo_f756zg] +platform = ststm32 +framework = zephyr +board = nucleo_f756zg +monitor_speed = 115200 + +[env:nucleo_g071rb] +platform = ststm32 +framework = zephyr +board = nucleo_g071rb +monitor_speed = 115200 diff --git a/examples/zephyr-cpp-synchronization/src/main.cpp b/examples/zephyr-cpp-synchronization/src/main.cpp new file mode 100644 index 00000000..3a6338f6 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/src/main.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2015-2016 Wind River Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file C++ Synchronization demo. Uses basic C++ functionality. + */ + +#include +#include +#include +#include + +/** + * @class semaphore the basic pure virtual semaphore class + */ +class semaphore { +public: + virtual int wait(void) = 0; + virtual int wait(int timeout) = 0; + virtual void give(void) = 0; +}; + +/* specify delay between greetings (in ms); compute equivalent in ticks */ +#define SLEEPTIME 500 +#define STACKSIZE 2000 + +struct k_thread coop_thread; +K_THREAD_STACK_DEFINE(coop_stack, STACKSIZE); + +/* + * @class cpp_semaphore + * @brief Semaphore + * + * Class derives from the pure virtual semaphore class and + * implements it's methods for the semaphore + */ +class cpp_semaphore: public semaphore { +protected: + struct k_sem _sema_internal; +public: + cpp_semaphore(); + virtual ~cpp_semaphore() {} + virtual int wait(void); + virtual int wait(int timeout); + virtual void give(void); +}; + +/* + * @brief cpp_semaphore basic constructor + */ +cpp_semaphore::cpp_semaphore() +{ + printk("Create semaphore %p\n", this); + k_sem_init(&_sema_internal, 0, UINT_MAX); +} + +/* + * @brief wait for a semaphore + * + * Test a semaphore to see if it has been signaled. If the signal + * count is greater than zero, it is decremented. + * + * @return 1 when semaphore is available + */ +int cpp_semaphore::wait(void) +{ + k_sem_take(&_sema_internal, K_FOREVER); + return 1; +} + +/* + * @brief wait for a semaphore within a specified timeout + * + * Test a semaphore to see if it has been signaled. If the signal + * count is greater than zero, it is decremented. The function + * waits for timeout specified + * + * @param timeout the specified timeout in ticks + * + * @return 1 if semaphore is available, 0 if timed out + */ +int cpp_semaphore::wait(int timeout) +{ + return k_sem_take(&_sema_internal, timeout); +} + +/** + * + * @brief Signal a semaphore + * + * This routine signals the specified semaphore. + * + * @return N/A + */ +void cpp_semaphore::give(void) +{ + k_sem_give(&_sema_internal); +} + +cpp_semaphore sem_main; +cpp_semaphore sem_coop; + +void coop_thread_entry(void) +{ + struct k_timer timer; + + k_timer_init(&timer, NULL, NULL); + + while (1) { + /* wait for main thread to let us have a turn */ + sem_coop.wait(); + + /* say "hello" */ + printk("%s: Hello World!\n", __FUNCTION__); + + /* wait a while, then let main thread have a turn */ + k_timer_start(&timer, SLEEPTIME, 0); + k_timer_status_sync(&timer); + sem_main.give(); + } +} + +int main(void) +{ + struct k_timer timer; + + k_thread_create(&coop_thread, coop_stack, STACKSIZE, + (k_thread_entry_t) coop_thread_entry, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, 0); + k_timer_init(&timer, NULL, NULL); + + while (1) { + /* say "hello" */ + printk("%s: Hello World!\n", __FUNCTION__); + + /* wait a while, then let coop thread have a turn */ + k_timer_start(&timer, SLEEPTIME, 0); + k_timer_status_sync(&timer); + sem_coop.give(); + + /* Wait for coop thread to let us have a turn */ + sem_main.wait(); + } + + return 0; +} diff --git a/examples/zephyr-cpp-synchronization/test/README b/examples/zephyr-cpp-synchronization/test/README new file mode 100644 index 00000000..df5066e6 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/zephyr-cpp-synchronization/zephyr/CMakeLists.txt b/examples/zephyr-cpp-synchronization/zephyr/CMakeLists.txt new file mode 100644 index 00000000..0fa9ce86 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/zephyr/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(cpp_synchronization) + +target_sources(app PRIVATE ../src/main.cpp) diff --git a/examples/zephyr-cpp-synchronization/zephyr/prj.conf b/examples/zephyr-cpp-synchronization/zephyr/prj.conf new file mode 100644 index 00000000..50396291 --- /dev/null +++ b/examples/zephyr-cpp-synchronization/zephyr/prj.conf @@ -0,0 +1,2 @@ +CONFIG_CPLUSPLUS=y +CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=128 diff --git a/examples/zephyr-drivers-can/.gitignore b/examples/zephyr-drivers-can/.gitignore new file mode 100644 index 00000000..aeaebb2b --- /dev/null +++ b/examples/zephyr-drivers-can/.gitignore @@ -0,0 +1 @@ +.pio \ No newline at end of file diff --git a/examples/zephyr-drivers-can/.travis.yml b/examples/zephyr-drivers-can/.travis.yml new file mode 100644 index 00000000..7c486f18 --- /dev/null +++ b/examples/zephyr-drivers-can/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/zephyr-drivers-can/README.rst b/examples/zephyr-drivers-can/README.rst new file mode 100644 index 00000000..a39e52e3 --- /dev/null +++ b/examples/zephyr-drivers-can/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-ststm32/examples/zephyr-drivers-can + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e disco_f469ni + + # Upload firmware for the specific environment + > platformio run -e disco_f469ni --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/zephyr-drivers-can/include/README b/examples/zephyr-drivers-can/include/README new file mode 100644 index 00000000..194dcd43 --- /dev/null +++ b/examples/zephyr-drivers-can/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/zephyr-drivers-can/lib/README b/examples/zephyr-drivers-can/lib/README new file mode 100644 index 00000000..6debab1e --- /dev/null +++ b/examples/zephyr-drivers-can/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/zephyr-drivers-can/platformio.ini b/examples/zephyr-drivers-can/platformio.ini new file mode 100644 index 00000000..bd83f8c0 --- /dev/null +++ b/examples/zephyr-drivers-can/platformio.ini @@ -0,0 +1,26 @@ +; 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/page/projectconf.html + +[env:nucleo_f302r8] +platform = ststm32 +framework = zephyr +board = nucleo_f302r8 +monitor_speed = 115200 + +[env:disco_f469ni] +platform = ststm32 +framework = zephyr +board = disco_f469ni +monitor_speed = 115200 + +[env:nucleo_l476rg] +platform = ststm32 +framework = zephyr +board = nucleo_l476rg +monitor_speed = 115200 diff --git a/examples/zephyr-drivers-can/src/main.c b/examples/zephyr-drivers-can/src/main.c new file mode 100644 index 00000000..ab3efb15 --- /dev/null +++ b/examples/zephyr-drivers-can/src/main.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2018 Alexander Wachter + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +#define RX_THREAD_STACK_SIZE 512 +#define RX_THREAD_PRIORITY 2 +#define LED_MSG_ID 0x10 +#define COUNTER_MSG_ID 0x12345 +#define SET_LED 1 +#define RESET_LED 0 +#define SLEEP_TIME K_MSEC(250) + +K_THREAD_STACK_DEFINE(rx_thread_stack, RX_THREAD_STACK_SIZE); + +struct k_thread rx_thread_data; +struct zcan_work rx_work; + +CAN_DEFINE_MSGQ(counter_msgq, 2); + +void tx_irq_callback(u32_t error_flags, void *arg) +{ + char *sender = (char *)arg; + + if (error_flags) { + printk("Callback! error-code: %d\nSender: %s\n", + error_flags, sender); + } +} + +void rx_thread(void *can_dev_param, void *arg1, void *arg2) +{ + ARG_UNUSED(arg1); + ARG_UNUSED(arg2); + const struct zcan_filter filter = { + .id_type = CAN_EXTENDED_IDENTIFIER, + .rtr = CAN_DATAFRAME, + .ext_id = COUNTER_MSG_ID, + .rtr_mask = 1, + .ext_id_mask = CAN_EXT_ID_MASK + }; + struct device *can_dev = can_dev_param; + struct zcan_frame msg; + int filter_id; + + filter_id = can_attach_msgq(can_dev, &counter_msgq, &filter); + printk("Counter filter id: %d\n", filter_id); + + while (1) { + k_msgq_get(&counter_msgq, &msg, K_FOREVER); + + if (msg.dlc != 2U) { + printk("Wrong data length: %u\n", msg.dlc); + continue; + } + + printk("Counter received: %u\n", + sys_be16_to_cpu(UNALIGNED_GET((u16_t *)&msg.data))); + } +} + +void change_led(struct zcan_frame *msg, void *led_dev_param) +{ + struct device *led_dev = (struct device *)led_dev_param; + +#if defined(DT_ALIAS_LED0_GPIOS_PIN) && defined(DT_ALIAS_LED0_GPIOS_CONTROLLER) + + if (!led_dev_param) { + printk("No LED GPIO device\n"); + return; + } + + switch (msg->data[0]) { + case SET_LED: + gpio_pin_write(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 1); + break; + case RESET_LED: + gpio_pin_write(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 0); + break; + } +#else + printk("LED %s\n", msg->data[0] == SET_LED ? "ON" : "OFF"); +#endif +} + +void main(void) +{ + const struct zcan_filter change_led_filter = { + .id_type = CAN_STANDARD_IDENTIFIER, + .rtr = CAN_DATAFRAME, + .std_id = LED_MSG_ID, + .rtr_mask = 1, + .std_id_mask = CAN_STD_ID_MASK + }; + struct zcan_frame change_led_frame = { + .id_type = CAN_STANDARD_IDENTIFIER, + .rtr = CAN_DATAFRAME, + .std_id = LED_MSG_ID, + .dlc = 1 + }; + struct zcan_frame counter_frame = { + .id_type = CAN_EXTENDED_IDENTIFIER, + .rtr = CAN_DATAFRAME, + .ext_id = COUNTER_MSG_ID, + .dlc = 2 + }; + u8_t toggle = 1; + u16_t counter = 0; + struct device *led_gpio_dev = NULL; + struct device *can_dev; + k_tid_t rx_tid; + int ret; + + /* Usually the CAN device is either called CAN_0 or CAN_1, depending + * on the SOC. Let's check both and take the first valid one. + */ + can_dev = device_get_binding("CAN_0"); + if (!can_dev) { + can_dev = device_get_binding("CAN_1"); + } + + if (!can_dev) { + printk("CAN: Device driver not found.\n"); + return; + } + +#ifdef CONFIG_LOOPBACK_MODE + can_configure(can_dev, CAN_LOOPBACK_MODE, 250000); +#endif + +#if defined(DT_ALIAS_LED0_GPIOS_PIN) && defined(DT_ALIAS_LED0_GPIOS_CONTROLLER) + led_gpio_dev = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER); + if (!led_gpio_dev) { + printk("LED: Device driver not found.\n"); + return; + } + + ret = gpio_pin_configure(led_gpio_dev, DT_ALIAS_LED0_GPIOS_PIN, + GPIO_DIR_OUT); + if (ret < 0) { + printk("Error setting LED pin to output mode [%d]", ret); + } +#endif + + ret = can_attach_workq(can_dev, &k_sys_work_q, &rx_work, change_led, + led_gpio_dev, &change_led_filter); + if (ret == CAN_NO_FREE_FILTER) { + printk("Error, no filter available!\n"); + return; + } + + printk("Change LED filter ID: %d\n", ret); + + rx_tid = k_thread_create(&rx_thread_data, rx_thread_stack, + K_THREAD_STACK_SIZEOF(rx_thread_stack), + rx_thread, can_dev, NULL, NULL, + RX_THREAD_PRIORITY, 0, K_NO_WAIT); + if (!rx_tid) { + printk("ERROR spawning rx thread\n"); + } + + printk("Finished init.\n"); + + while (1) { + change_led_frame.data[0] = toggle++ & 0x01 ? SET_LED : RESET_LED; + /* This sending call is none blocking. */ + can_send(can_dev, &change_led_frame, K_FOREVER, tx_irq_callback, + "LED change"); + k_sleep(SLEEP_TIME); + + UNALIGNED_PUT(sys_cpu_to_be16(counter), + (u16_t *)&counter_frame.data[0]); + counter++; + /* This sending call is blocking until the message is sent. */ + can_send(can_dev, &counter_frame, K_MSEC(100), NULL, NULL); + k_sleep(SLEEP_TIME); + } +} diff --git a/examples/zephyr-drivers-can/test/README b/examples/zephyr-drivers-can/test/README new file mode 100644 index 00000000..df5066e6 --- /dev/null +++ b/examples/zephyr-drivers-can/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/zephyr-drivers-can/zephyr/CMakeLists.txt b/examples/zephyr-drivers-can/zephyr/CMakeLists.txt new file mode 100644 index 00000000..a026d7f9 --- /dev/null +++ b/examples/zephyr-drivers-can/zephyr/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(CAN) + +set (CONF_FILE "prj.mcp2515.conf") + +target_sources(app PRIVATE ../src/main.c) diff --git a/examples/zephyr-drivers-can/zephyr/prj.conf b/examples/zephyr-drivers-can/zephyr/prj.conf new file mode 100644 index 00000000..448dfc2c --- /dev/null +++ b/examples/zephyr-drivers-can/zephyr/prj.conf @@ -0,0 +1,7 @@ +CONFIG_CAN=y +CONFIG_CAN_INIT_PRIORITY=80 +CONFIG_CAN_MAX_FILTER=5 + +CONFIG_SHELL=y +CONFIG_CAN_SHELL=y +CONFIG_DEVICE_SHELL=y diff --git a/examples/zephyr-drivers-can/zephyr/prj.mcp2515.conf b/examples/zephyr-drivers-can/zephyr/prj.mcp2515.conf new file mode 100644 index 00000000..84a00237 --- /dev/null +++ b/examples/zephyr-drivers-can/zephyr/prj.mcp2515.conf @@ -0,0 +1,10 @@ +# Alternate conf file required for building the CAN sample for the +# MCP2515 stand alone CAN controller + +CONFIG_CAN=y +CONFIG_CAN_INIT_PRIORITY=80 +CONFIG_CAN_MCP2515_MAX_FILTER=5 + +CONFIG_SHELL=y +CONFIG_CAN_SHELL=y +CONFIG_DEVICE_SHELL=y diff --git a/examples/zephyr-net-https-client/.gitignore b/examples/zephyr-net-https-client/.gitignore new file mode 100644 index 00000000..aeaebb2b --- /dev/null +++ b/examples/zephyr-net-https-client/.gitignore @@ -0,0 +1 @@ +.pio \ No newline at end of file diff --git a/examples/zephyr-net-https-client/.travis.yml b/examples/zephyr-net-https-client/.travis.yml new file mode 100644 index 00000000..7c486f18 --- /dev/null +++ b/examples/zephyr-net-https-client/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/zephyr-net-https-client/README.rst b/examples/zephyr-net-https-client/README.rst new file mode 100644 index 00000000..fc0525c3 --- /dev/null +++ b/examples/zephyr-net-https-client/README.rst @@ -0,0 +1,32 @@ +.. Copyright 2019-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-ststm32/examples/zephyr-net-https-client + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/zephyr-net-https-client/include/README b/examples/zephyr-net-https-client/include/README new file mode 100644 index 00000000..194dcd43 --- /dev/null +++ b/examples/zephyr-net-https-client/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/zephyr-net-https-client/lib/README b/examples/zephyr-net-https-client/lib/README new file mode 100644 index 00000000..6debab1e --- /dev/null +++ b/examples/zephyr-net-https-client/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/zephyr-net-https-client/lib/user-lib/eeprom.c b/examples/zephyr-net-https-client/lib/user-lib/eeprom.c new file mode 100644 index 00000000..6d5c31f8 --- /dev/null +++ b/examples/zephyr-net-https-client/lib/user-lib/eeprom.c @@ -0,0 +1,10 @@ +#include "eeprom.h" + +#define EEPROM_MEMORY_START ((uint32_t)0x08080000U) + +void EEPROM_Write(uint32_t address, uint32_t value) { +} + + +uint32_t EEPROM_Read (uint32_t address) { +} \ No newline at end of file diff --git a/examples/zephyr-net-https-client/lib/user-lib/eeprom.h b/examples/zephyr-net-https-client/lib/user-lib/eeprom.h new file mode 100644 index 00000000..8c68481f --- /dev/null +++ b/examples/zephyr-net-https-client/lib/user-lib/eeprom.h @@ -0,0 +1,21 @@ +#ifndef __SIMPLE_EEPROM__ +#define __SIMPLE_EEPROM__ + +#ifdef __cplusplus + extern "C" { +#endif + +#include + +/*! + * \brief Write to EEPROM memory + */ +void EEPROM_Write(uint32_t address, uint32_t value); + + +/*! + * \brief Read from EEPROM memory + */ +uint32_t EEPROM_Read (uint32_t address); + +#endif diff --git a/examples/zephyr-net-https-client/platformio.ini b/examples/zephyr-net-https-client/platformio.ini new file mode 100644 index 00000000..de0dfed0 --- /dev/null +++ b/examples/zephyr-net-https-client/platformio.ini @@ -0,0 +1,16 @@ +; 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/page/projectconf.html + +[env:disco_f769ni] +platform = ststm32 +framework = zephyr +board = disco_f769ni + +board_build.embed_files = + src/https-cert.der diff --git a/examples/zephyr-net-https-client/src/ca_certificate.h b/examples/zephyr-net-https-client/src/ca_certificate.h new file mode 100644 index 00000000..4e55d419 --- /dev/null +++ b/examples/zephyr-net-https-client/src/ca_certificate.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2019 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define CA_CERTIFICATE_TAG 1 + +#define TLS_PEER_HOSTNAME "localhost" + +/* This is the same cert as what is found in net-tools/https-cert.pem file + */ +static const unsigned char ca_certificate[] = { +#include "https-cert.der.inc" +}; diff --git a/examples/zephyr-net-https-client/src/https-cert.der b/examples/zephyr-net-https-client/src/https-cert.der new file mode 100644 index 00000000..fac8c0cb Binary files /dev/null and b/examples/zephyr-net-https-client/src/https-cert.der differ diff --git a/examples/zephyr-net-https-client/src/main.c b/examples/zephyr-net-https-client/src/main.c new file mode 100644 index 00000000..d7bb086c --- /dev/null +++ b/examples/zephyr-net-https-client/src/main.c @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2019 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_REGISTER(net_http_client_sample, LOG_LEVEL_DBG); + +#include +#include +#include +#include + +#include "ca_certificate.h" + +#define HTTP_PORT 8000 +#define HTTPS_PORT 4443 + +#if defined(CONFIG_NET_CONFIG_PEER_IPV6_ADDR) +#define SERVER_ADDR6 CONFIG_NET_CONFIG_PEER_IPV6_ADDR +#else +#define SERVER_ADDR6 "" +#endif + +#if defined(CONFIG_NET_CONFIG_PEER_IPV4_ADDR) +#define SERVER_ADDR4 CONFIG_NET_CONFIG_PEER_IPV4_ADDR +#else +#define SERVER_ADDR4 "" +#endif + +#define MAX_RECV_BUF_LEN 512 + +static u8_t recv_buf_ipv4[MAX_RECV_BUF_LEN]; +static u8_t recv_buf_ipv6[MAX_RECV_BUF_LEN]; + +static int setup_socket(sa_family_t family, const char *server, int port, + int *sock, struct sockaddr *addr, socklen_t addr_len) +{ + const char *family_str = family == AF_INET ? "IPv4" : "IPv6"; + int ret = 0; + + memset(addr, 0, addr_len); + + if (family == AF_INET) { + net_sin(addr)->sin_family = AF_INET; + net_sin(addr)->sin_port = htons(port); + inet_pton(family, server, &net_sin(addr)->sin_addr); + } else { + net_sin6(addr)->sin6_family = AF_INET6; + net_sin6(addr)->sin6_port = htons(port); + inet_pton(family, server, &net_sin6(addr)->sin6_addr); + } + + if (IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS)) { + sec_tag_t sec_tag_list[] = { + CA_CERTIFICATE_TAG, + }; + + *sock = socket(family, SOCK_STREAM, IPPROTO_TLS_1_2); + if (*sock >= 0) { + ret = setsockopt(*sock, SOL_TLS, TLS_SEC_TAG_LIST, + sec_tag_list, sizeof(sec_tag_list)); + if (ret < 0) { + LOG_ERR("Failed to set %s secure option (%d)", + family_str, -errno); + ret = -errno; + } + + ret = setsockopt(*sock, SOL_TLS, TLS_HOSTNAME, + TLS_PEER_HOSTNAME, + sizeof(TLS_PEER_HOSTNAME)); + if (ret < 0) { + LOG_ERR("Failed to set %s TLS_HOSTNAME " + "option (%d)", family_str, -errno); + ret = -errno; + } + } + } else { + *sock = socket(family, SOCK_STREAM, IPPROTO_TCP); + } + + if (*sock < 0) { + LOG_ERR("Failed to create %s HTTP socket (%d)", family_str, + -errno); + } + + return ret; +} + +static int payload_cb(int sock, struct http_request *req, void *user_data) +{ + const char *content[] = { + "foobar", + "chunked", + "last" + }; + char tmp[64]; + int i, pos = 0; + + for (i = 0; i < ARRAY_SIZE(content); i++) { + pos += snprintk(tmp + pos, sizeof(tmp) - pos, + "%x\r\n%s\r\n", + (unsigned int)strlen(content[i]), + content[i]); + } + + pos += snprintk(tmp + pos, sizeof(tmp) - pos, "0\r\n\r\n"); + + (void)send(sock, tmp, pos, 0); + + return pos; +} + +static void response_cb(struct http_response *rsp, + enum http_final_call final_data, + void *user_data) +{ + if (final_data == HTTP_DATA_MORE) { + LOG_INF("Partial data received (%zd bytes)", rsp->data_len); + } else if (final_data == HTTP_DATA_FINAL) { + LOG_INF("All the data received (%zd bytes)", rsp->data_len); + } + + LOG_INF("Response to %s", (const char *)user_data); + LOG_INF("Response status %s", rsp->http_status); +} + +static int connect_socket(sa_family_t family, const char *server, int port, + int *sock, struct sockaddr *addr, socklen_t addr_len) +{ + int ret; + + ret = setup_socket(family, server, port, sock, addr, addr_len); + if (ret < 0 || *sock < 0) { + return -1; + } + + ret = connect(*sock, addr, addr_len); + if (ret < 0) { + LOG_ERR("Cannot connect to %s remote (%d)", + family == AF_INET ? "IPv4" : "IPv6", + -errno); + ret = -errno; + } + + return ret; +} + +void main(void) +{ + struct sockaddr_in6 addr6; + struct sockaddr_in addr4; + int sock4 = -1, sock6 = -1; + s32_t timeout = K_SECONDS(3); + int ret; + int port = HTTP_PORT; + + printk("Program started!\n"); + + if (IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS)) { + ret = tls_credential_add(CA_CERTIFICATE_TAG, + TLS_CREDENTIAL_CA_CERTIFICATE, + ca_certificate, + sizeof(ca_certificate)); + if (ret < 0) { + LOG_ERR("Failed to register public certificate: %d", + ret); + exit(1); + } + + port = HTTPS_PORT; + } + + printk("CONFIG_NET_SOCKETS_SOCKOPT_TLS!\n"); + + if (IS_ENABLED(CONFIG_NET_IPV4)) { + (void)connect_socket(AF_INET, SERVER_ADDR4, port, + &sock4, (struct sockaddr *)&addr4, + sizeof(addr4)); + } + + printk("CONFIG_NET_IPV4s!\n"); + + if (IS_ENABLED(CONFIG_NET_IPV6)) { + (void)connect_socket(AF_INET6, SERVER_ADDR6, port, + &sock6, (struct sockaddr *)&addr6, + sizeof(addr6)); + } + + printk("CONFIG_NET_IPV6!\n"); + + if (sock4 < 0 && sock6 < 0) { + LOG_ERR("Cannot create HTTP connection."); + exit(1); + } + + if (sock4 >= 0 && IS_ENABLED(CONFIG_NET_IPV4)) { + struct http_request req; + + memset(&req, 0, sizeof(req)); + + req.method = HTTP_GET; + req.url = "/"; + req.host = SERVER_ADDR4; + req.protocol = "HTTP/1.1"; + req.response = response_cb; + req.recv_buf = recv_buf_ipv4; + req.recv_buf_len = sizeof(recv_buf_ipv4); + + printk("IPv4 GET!\n"); + + ret = http_client_req(sock4, &req, timeout, "IPv4 GET"); + + close(sock4); + } + + if (sock6 >= 0 && IS_ENABLED(CONFIG_NET_IPV6)) { + struct http_request req; + + memset(&req, 0, sizeof(req)); + + req.method = HTTP_GET; + req.url = "/"; + req.host = SERVER_ADDR6; + req.protocol = "HTTP/1.1"; + req.response = response_cb; + req.recv_buf = recv_buf_ipv6; + req.recv_buf_len = sizeof(recv_buf_ipv6); + + printk("IPv6 GET!\n"); + + ret = http_client_req(sock6, &req, timeout, "IPv6 GET"); + + close(sock6); + } + + sock4 = -1; + sock6 = -1; + + if (IS_ENABLED(CONFIG_NET_IPV4)) { + (void)connect_socket(AF_INET, SERVER_ADDR4, port, + &sock4, (struct sockaddr *)&addr4, + sizeof(addr4)); + } + + if (IS_ENABLED(CONFIG_NET_IPV6)) { + (void)connect_socket(AF_INET6, SERVER_ADDR6, port, + &sock6, (struct sockaddr *)&addr6, + sizeof(addr6)); + } + + if (sock4 < 0 && sock6 < 0) { + LOG_ERR("Cannot create HTTP connection."); + exit(1); + } + + if (sock4 >= 0 && IS_ENABLED(CONFIG_NET_IPV4)) { + struct http_request req; + + memset(&req, 0, sizeof(req)); + + req.method = HTTP_POST; + req.url = "/foobar"; + req.host = SERVER_ADDR4; + req.protocol = "HTTP/1.1"; + req.payload = "foobar"; + req.payload_len = strlen(req.payload); + req.response = response_cb; + req.recv_buf = recv_buf_ipv4; + req.recv_buf_len = sizeof(recv_buf_ipv4); + + ret = http_client_req(sock4, &req, timeout, "IPv4 POST"); + + close(sock4); + } + + if (sock6 >= 0 && IS_ENABLED(CONFIG_NET_IPV6)) { + struct http_request req; + + memset(&req, 0, sizeof(req)); + + req.method = HTTP_POST; + req.url = "/"; + req.host = SERVER_ADDR6; + req.protocol = "HTTP/1.1"; + req.payload = "foobar"; + req.payload_len = strlen(req.payload); + req.response = response_cb; + req.recv_buf = recv_buf_ipv6; + req.recv_buf_len = sizeof(recv_buf_ipv6); + + ret = http_client_req(sock6, &req, timeout, "IPv6 POST"); + + close(sock6); + } + + /* Do a chunked POST request */ + + sock4 = -1; + sock6 = -1; + + if (IS_ENABLED(CONFIG_NET_IPV4)) { + (void)connect_socket(AF_INET, SERVER_ADDR4, port, + &sock4, (struct sockaddr *)&addr4, + sizeof(addr4)); + } + + if (IS_ENABLED(CONFIG_NET_IPV6)) { + (void)connect_socket(AF_INET6, SERVER_ADDR6, port, + &sock6, (struct sockaddr *)&addr6, + sizeof(addr6)); + } + + if (sock4 < 0 && sock6 < 0) { + LOG_ERR("Cannot create HTTP connection."); + exit(1); + } + + if (sock4 >= 0 && IS_ENABLED(CONFIG_NET_IPV4)) { + struct http_request req; + const char *headers[] = { + "Transfer-Encoding: chunked\r\n", + NULL + }; + + memset(&req, 0, sizeof(req)); + + req.method = HTTP_POST; + req.url = "/chunked-test"; + req.host = SERVER_ADDR4; + req.protocol = "HTTP/1.1"; + req.payload_cb = payload_cb; + req.header_fields = headers; + req.response = response_cb; + req.recv_buf = recv_buf_ipv4; + req.recv_buf_len = sizeof(recv_buf_ipv4); + + printk("IPv4 POST!\n"); + + ret = http_client_req(sock4, &req, timeout, "IPv4 POST"); + + close(sock4); + } + + if (sock6 >= 0 && IS_ENABLED(CONFIG_NET_IPV6)) { + struct http_request req; + const char *headers[] = { + "Transfer-Encoding: chunked\r\n", + NULL + }; + + memset(&req, 0, sizeof(req)); + + req.method = HTTP_POST; + req.url = "/chunked-test"; + req.host = SERVER_ADDR6; + req.protocol = "HTTP/1.1"; + req.payload_cb = payload_cb; + req.header_fields = headers; + req.response = response_cb; + req.recv_buf = recv_buf_ipv6; + req.recv_buf_len = sizeof(recv_buf_ipv6); + + ret = http_client_req(sock6, &req, timeout, "IPv6 POST"); + + close(sock6); + } + + printk("FINAL!!!\n"); + + k_sleep(K_FOREVER); +} diff --git a/examples/zephyr-net-https-client/test/README b/examples/zephyr-net-https-client/test/README new file mode 100644 index 00000000..df5066e6 --- /dev/null +++ b/examples/zephyr-net-https-client/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/zephyr-net-https-client/zephyr/CMakeLists.txt b/examples/zephyr-net-https-client/zephyr/CMakeLists.txt new file mode 100644 index 00000000..e4afe9e0 --- /dev/null +++ b/examples/zephyr-net-https-client/zephyr/CMakeLists.txt @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +set (CONF_FILE "prj.conf overlay-tls.conf") + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(http_client) + +FILE(GLOB app_sources ../src/*.c) +target_sources(app PRIVATE ${app_sources}) + +set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) + +generate_inc_file_for_target( + app + ../src/https-cert.der + ${gen_dir}/https-cert.der.inc +) diff --git a/examples/zephyr-net-https-client/zephyr/overlay-tls.conf b/examples/zephyr-net-https-client/zephyr/overlay-tls.conf new file mode 100644 index 00000000..1a91e13e --- /dev/null +++ b/examples/zephyr-net-https-client/zephyr/overlay-tls.conf @@ -0,0 +1,13 @@ +CONFIG_MAIN_STACK_SIZE=3072 +CONFIG_NET_BUF_RX_COUNT=80 +CONFIG_NET_BUF_TX_COUNT=80 + +# TLS configuration +CONFIG_MBEDTLS=y +CONFIG_MBEDTLS_BUILTIN=y +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=60000 +CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048 + +CONFIG_NET_SOCKETS_SOCKOPT_TLS=y +CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=6 diff --git a/examples/zephyr-net-https-client/zephyr/prj.conf b/examples/zephyr-net-https-client/zephyr/prj.conf new file mode 100644 index 00000000..968b5bbb --- /dev/null +++ b/examples/zephyr-net-https-client/zephyr/prj.conf @@ -0,0 +1,38 @@ +# Networking config +CONFIG_NETWORKING=y +CONFIG_NET_IPV4=y +CONFIG_NET_IPV6=y +CONFIG_NET_TCP=y +CONFIG_NET_SHELL=y + +# Sockets +CONFIG_NET_SOCKETS=y +CONFIG_NET_SOCKETS_POSIX_NAMES=y +CONFIG_NET_SOCKETS_POLL_MAX=4 + +# Network driver config +CONFIG_TEST_RANDOM_GENERATOR=y + +# Network address config +CONFIG_NET_CONFIG_SETTINGS=y +CONFIG_NET_CONFIG_NEED_IPV4=y +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" +# Address of HTTP IPv4 server +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" +# Address of HTTP IPv6 server +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" + +# HTTP +CONFIG_HTTP_CLIENT=y + +# Network debug config +CONFIG_LOG=y +CONFIG_LOG_IMMEDIATE=y +CONFIG_NET_LOG=y +CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=n +CONFIG_NET_HTTP_LOG_LEVEL_DBG=y + +CONFIG_MAIN_STACK_SIZE=2048 diff --git a/examples/zephyr-subsys-usb-hid-mouse/.gitignore b/examples/zephyr-subsys-usb-hid-mouse/.gitignore new file mode 100644 index 00000000..aeaebb2b --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/.gitignore @@ -0,0 +1 @@ +.pio \ No newline at end of file diff --git a/examples/zephyr-subsys-usb-hid-mouse/.travis.yml b/examples/zephyr-subsys-usb-hid-mouse/.travis.yml new file mode 100644 index 00000000..7c486f18 --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose 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 +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be 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 +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/zephyr-subsys-usb-hid-mouse/README.rst b/examples/zephyr-subsys-usb-hid-mouse/README.rst new file mode 100644 index 00000000..f12a983d --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2019-present PlatformIO + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-ststm32/examples/zephyr-subsys-usb-hid-mouse + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e disco_f407vg + + # Upload firmware for the specific environment + > platformio run -e disco_f407vg --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/zephyr-subsys-usb-hid-mouse/include/README b/examples/zephyr-subsys-usb-hid-mouse/include/README new file mode 100644 index 00000000..194dcd43 --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/zephyr-subsys-usb-hid-mouse/lib/README b/examples/zephyr-subsys-usb-hid-mouse/lib/README new file mode 100644 index 00000000..6debab1e --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/zephyr-subsys-usb-hid-mouse/platformio.ini b/examples/zephyr-subsys-usb-hid-mouse/platformio.ini new file mode 100644 index 00000000..d66e671a --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/platformio.ini @@ -0,0 +1,26 @@ +; 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/page/projectconf.html + +[env:disco_f746ng] +platform = ststm32 +framework = zephyr +board = disco_f746ng +monitor_speed = 115200 + +[env:disco_f407vg] +platform = ststm32 +framework = zephyr +board = disco_f407vg +monitor_speed = 115200 + +[env:nucleo_f207zg] +platform = ststm32 +framework = zephyr +board = nucleo_f207zg +monitor_speed = 115200 diff --git a/examples/zephyr-subsys-usb-hid-mouse/src/main.c b/examples/zephyr-subsys-usb-hid-mouse/src/main.c new file mode 100644 index 00000000..0a53d631 --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/src/main.c @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2018 qianfan Zhao + * Copyright (c) 2018 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +#include +#include + +#define LOG_LEVEL LOG_LEVEL_DBG +LOG_MODULE_REGISTER(main); + +/* change this to use another GPIO port */ +#ifdef DT_ALIAS_SW0_GPIOS_CONTROLLER +#define PORT0 DT_ALIAS_SW0_GPIOS_CONTROLLER +#else +#error DT_ALIAS_SW0_GPIOS_CONTROLLER needs to be set +#endif + +/* change this to use another GPIO pin */ +#ifdef DT_ALIAS_SW0_GPIOS_PIN +#define PIN0 DT_ALIAS_SW0_GPIOS_PIN +#else +#error DT_ALIAS_SW0_GPIOS_PIN needs to be set +#endif + +/* The switch pin pull-up/down flags */ +#ifdef DT_ALIAS_SW0_GPIOS_FLAGS +#define PIN0_FLAGS DT_ALIAS_SW0_GPIOS_FLAGS +#else +#error DT_ALIAS_SW0_GPIOS_FLAGS needs to be set +#endif + +/* If second button exists, use it as right-click. */ +#ifdef DT_ALIAS_SW1_GPIOS_PIN +#define PIN1 DT_ALIAS_SW1_GPIOS_PIN +#endif + +#ifdef DT_ALIAS_SW1_GPIOS_CONTROLLER +#define PORT1 DT_ALIAS_SW1_GPIOS_CONTROLLER +#endif + +#ifdef DT_ALIAS_SW1_GPIOS_FLAGS +#define PIN1_FLAGS DT_ALIAS_SW1_GPIOS_FLAGS +#endif + +/* If third button exists, use it as X axis movement. */ +#ifdef DT_ALIAS_SW2_GPIOS_PIN +#define PIN2 DT_ALIAS_SW2_GPIOS_PIN +#endif + +#ifdef DT_ALIAS_SW2_GPIOS_CONTROLLER +#define PORT2 DT_ALIAS_SW2_GPIOS_CONTROLLER +#endif + +#ifdef DT_ALIAS_SW2_GPIOS_FLAGS +#define PIN2_FLAGS DT_ALIAS_SW2_GPIOS_FLAGS +#endif + +/* If fourth button exists, use it as Y axis movement. */ +#ifdef DT_ALIAS_SW3_GPIOS_PIN +#define PIN3 DT_ALIAS_SW3_GPIOS_PIN +#endif + +#ifdef DT_ALIAS_SW3_GPIOS_CONTROLLER +#define PORT3 DT_ALIAS_SW3_GPIOS_CONTROLLER +#endif + +#ifdef DT_ALIAS_SW3_GPIOS_FLAGS +#define PIN3_FLAGS DT_ALIAS_SW3_GPIOS_FLAGS +#endif + +#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER +#define LED DT_ALIAS_LED0_GPIOS_PIN + +static const u8_t hid_report_desc[] = HID_MOUSE_REPORT_DESC(2); + +static u32_t def_val[4]; +static volatile u8_t status[4]; +static K_SEM_DEFINE(sem, 0, 1); /* starts off "not available" */ +static struct gpio_callback callback[4]; +static enum usb_dc_status_code usb_status; + +#define MOUSE_BTN_REPORT_POS 0 +#define MOUSE_X_REPORT_POS 1 +#define MOUSE_Y_REPORT_POS 2 + +#define MOUSE_BTN_LEFT BIT(0) +#define MOUSE_BTN_RIGHT BIT(1) +#define MOUSE_BTN_MIDDLE BIT(2) + + + +static void status_cb(enum usb_dc_status_code status, const u8_t *param) +{ + usb_status = status; +} + +static void left_button(struct device *gpio, struct gpio_callback *cb, + u32_t pins) +{ + u32_t cur_val; + u8_t state = status[MOUSE_BTN_REPORT_POS]; + + if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { + if (usb_status == USB_DC_SUSPEND) { + usb_wakeup_request(); + return; + } + } + + gpio_pin_read(gpio, PIN0, &cur_val); + if (def_val[0] != cur_val) { + state |= MOUSE_BTN_LEFT; + } else { + state &= ~MOUSE_BTN_LEFT; + } + + if (status[MOUSE_BTN_REPORT_POS] != state) { + status[MOUSE_BTN_REPORT_POS] = state; + k_sem_give(&sem); + } +} + +#ifdef DT_ALIAS_SW1_GPIOS_PIN +static void right_button(struct device *gpio, struct gpio_callback *cb, + u32_t pins) +{ + u32_t cur_val; + u8_t state = status[MOUSE_BTN_REPORT_POS]; + + if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { + if (usb_status == USB_DC_SUSPEND) { + usb_wakeup_request(); + return; + } + } + + gpio_pin_read(gpio, PIN1, &cur_val); + if (def_val[0] != cur_val) { + state |= MOUSE_BTN_RIGHT; + } else { + state &= ~MOUSE_BTN_RIGHT; + } + + if (status[MOUSE_BTN_REPORT_POS] != state) { + status[MOUSE_BTN_REPORT_POS] = state; + k_sem_give(&sem); + } +} +#endif + +#ifdef DT_ALIAS_SW2_GPIOS_PIN +static void x_move(struct device *gpio, struct gpio_callback *cb, u32_t pins) +{ + u32_t cur_val; + u8_t state = status[MOUSE_X_REPORT_POS]; + + gpio_pin_read(gpio, PIN2, &cur_val); + + if (def_val[2] != cur_val) { + state += 10U; + } + + if (status[MOUSE_X_REPORT_POS] != state) { + status[MOUSE_X_REPORT_POS] = state; + k_sem_give(&sem); + } +} +#endif + +#ifdef DT_ALIAS_SW3_GPIOS_PIN +static void y_move(struct device *gpio, struct gpio_callback *cb, u32_t pins) +{ + u32_t cur_val; + u8_t state = status[MOUSE_Y_REPORT_POS]; + + gpio_pin_read(gpio, PIN3, &cur_val); + + if (def_val[3] != cur_val) { + state += 10U; + } + + if (status[MOUSE_Y_REPORT_POS] != state) { + status[MOUSE_Y_REPORT_POS] = state; + k_sem_give(&sem); + } +} +#endif + +int callbacks_configure(struct device *gpio, u32_t pin, int flags, + void (*handler)(struct device*, struct gpio_callback*, + u32_t), struct gpio_callback *callback, u32_t *val) +{ + if (!gpio) { + LOG_ERR("Could not find PORT"); + return -ENXIO; + } + gpio_pin_configure(gpio, pin, + GPIO_DIR_IN | GPIO_INT | + GPIO_INT_EDGE | GPIO_INT_DOUBLE_EDGE | + flags); + gpio_pin_read(gpio, pin, val); + gpio_init_callback(callback, handler, BIT(pin)); + gpio_add_callback(gpio, callback); + gpio_pin_enable_callback(gpio, pin); + return 0; +} + +void main(void) +{ + u8_t report[4] = { 0x00 }; + u8_t toggle = 0U; + struct device *led_dev, *hid_dev; + + led_dev = device_get_binding(LED_PORT); + if (led_dev == NULL) { + LOG_ERR("Cannot get LED"); + return; + } + + hid_dev = device_get_binding("HID_0"); + if (hid_dev == NULL) { + LOG_ERR("Cannot get USB HID Device"); + return; + } + + gpio_pin_configure(led_dev, LED, GPIO_DIR_OUT); + + if (callbacks_configure(device_get_binding(PORT0), PIN0, PIN0_FLAGS, + &left_button, &callback[0], &def_val[0])) { + LOG_ERR("Failed configuring left button callback."); + return; + } + +#ifdef DT_ALIAS_SW1_GPIOS_PIN + if (callbacks_configure(device_get_binding(PORT1), PIN1, PIN1_FLAGS, + &right_button, &callback[1], &def_val[1])) { + LOG_ERR("Failed configuring right button callback."); + return; + } +#endif + +#ifdef DT_ALIAS_SW2_GPIOS_PIN + if (callbacks_configure(device_get_binding(PORT2), PIN2, PIN2_FLAGS, + &x_move, &callback[2], &def_val[2])) { + LOG_ERR("Failed configuring X axis movement callback."); + return; + } +#endif + +#ifdef DT_ALIAS_SW3_GPIOS_PIN + if (callbacks_configure(device_get_binding(PORT3), PIN3, PIN3_FLAGS, + &y_move, &callback[3], &def_val[3])) { + LOG_ERR("Failed configuring Y axis movement callback."); + return; + } +#endif + + static const struct hid_ops ops = { + .status_cb = status_cb + }; + usb_hid_register_device(hid_dev, + hid_report_desc, sizeof(hid_report_desc), + &ops); + usb_hid_init(hid_dev); + + while (true) { + k_sem_take(&sem, K_FOREVER); + + report[MOUSE_BTN_REPORT_POS] = status[MOUSE_BTN_REPORT_POS]; + report[MOUSE_X_REPORT_POS] = status[MOUSE_X_REPORT_POS]; + status[MOUSE_X_REPORT_POS] = 0U; + report[MOUSE_Y_REPORT_POS] = status[MOUSE_Y_REPORT_POS]; + status[MOUSE_Y_REPORT_POS] = 0U; + hid_int_ep_write(hid_dev, report, sizeof(report), NULL); + + /* Toggle LED on sent report */ + gpio_pin_write(led_dev, LED, toggle); + toggle = !toggle; + } +} diff --git a/examples/zephyr-subsys-usb-hid-mouse/test/README b/examples/zephyr-subsys-usb-hid-mouse/test/README new file mode 100644 index 00000000..df5066e6 --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/examples/zephyr-subsys-usb-hid-mouse/zephyr/CMakeLists.txt b/examples/zephyr-subsys-usb-hid-mouse/zephyr/CMakeLists.txt new file mode 100644 index 00000000..3008afc4 --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/zephyr/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(hid-mouse) + +FILE(GLOB app_sources ../src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/examples/zephyr-subsys-usb-hid-mouse/zephyr/prj.conf b/examples/zephyr-subsys-usb-hid-mouse/zephyr/prj.conf new file mode 100644 index 00000000..071214c2 --- /dev/null +++ b/examples/zephyr-subsys-usb-hid-mouse/zephyr/prj.conf @@ -0,0 +1,10 @@ +CONFIG_USB=y +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_HID=y +CONFIG_USB_DEVICE_PRODUCT="Zephyr HID mouse sample" + +CONFIG_LOG=y +CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y + +CONFIG_GPIO=y diff --git a/platform.json b/platform.json index 6a43dcef..79175cea 100644 --- a/platform.json +++ b/platform.json @@ -12,7 +12,7 @@ "type": "git", "url": "https://github.com/platformio/platform-ststm32.git" }, - "version": "5.7.0", + "version": "6.0.0", "packageRepositories": [ "https://dl.bintray.com/platformio/dl-packages/manifest.json", "http://dl.platformio.org/packages/manifest.json" @@ -41,6 +41,10 @@ "stm32cube": { "package": "framework-stm32cube", "script": "builder/frameworks/stm32cube.py" + }, + "zephyr": { + "package": "framework-zephyr", + "script": "builder/frameworks/zephyr.py" } }, "packages": { @@ -88,6 +92,71 @@ "optional": true, "version": "~2.0.181130" }, + "framework-zephyr": { + "type": "framework", + "optional": true, + "version": "~1.20100.0" + }, + "framework-zephyr-hal-stm32": { + "optional": true, + "version": "~0.20100.190619" + }, + "framework-zephyr-hal-st": { + "optional": true, + "version": "~0.20100.190924" + }, + "framework-zephyr-civetweb": { + "optional": true, + "version": "~0.20100.190807" + }, + "framework-zephyr-fatfs": { + "optional": true, + "version": "~0.20100.190522" + }, + "framework-zephyr-libmetal": { + "optional": true, + "version": "~0.20100.190530" + }, + "framework-zephyr-lvgl": { + "optional": true, + "version": "~0.20100.190812" + }, + "framework-zephyr-mbedtls": { + "optional": true, + "version": "~0.20100.191006" + }, + "framework-zephyr-mcumgr": { + "optional": true, + "version": "~0.20100.190528" + }, + "framework-zephyr-nffs": { + "optional": true, + "version": "~0.20100.190523" + }, + "framework-zephyr-open-amp": { + "optional": true, + "version": "~0.20100.190612" + }, + "framework-zephyr-openthread": { + "optional": true, + "version": "~0.20100.191024" + }, + "framework-zephyr-segger": { + "optional": true, + "version": "~0.20100.190421" + }, + "framework-zephyr-tinycbor": { + "optional": true, + "version": "~0.20100.191016" + }, + "framework-zephyr-littlefs": { + "optional": true, + "version": "~0.20100.190811" + }, + "framework-zephyr-mipi-sys-t": { + "optional": true, + "version": "~0.20100.191024" + }, "tool-stm32duino": { "type": "uploader", "optional": true, @@ -107,6 +176,22 @@ "type": "uploader", "optional": true, "version": "~1.9.190708" + }, + "tool-cmake": { + "optional": true, + "version": "~3.15.0" + }, + "tool-dtc": { + "optional": true, + "version": "~1.4.7" + }, + "tool-ninja": { + "optional": true, + "version": "^1.7.0" + }, + "tool-gperf": { + "optional": true, + "version": "^3.0.0" } } } diff --git a/platform.py b/platform.py index 2ab969d7..17942254 100644 --- a/platform.py +++ b/platform.py @@ -15,7 +15,7 @@ from platform import system from platformio.managers.platform import PlatformBase - +from platformio.util import get_systype class Ststm32Platform(PlatformBase): @@ -42,6 +42,15 @@ def configure_default_packages(self, variables, targets): 'script'] = "builder/frameworks/arduino/mxchip.py" self.packages['toolchain-gccarmnoneeabi']['version'] = "~1.60301.0" + if "zephyr" in variables.get("pioframework", []): + for p in self.packages: + if p.startswith("framework-zephyr-") or p in ( + "tool-cmake", "tool-dtc", "tool-ninja"): + self.packages[p]["optional"] = False + self.packages['toolchain-gccarmnoneeabi']['version'] = "~1.80201.0" + if "windows" not in get_systype(): + self.packages['tool-gperf']['optional'] = False + # configure J-LINK tool jlink_conds = [ "jlink" in variables.get(option, "")