diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc0fb2b5..8d4ed693 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,33 +12,30 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - path: Arduino-Zephyr-API + path: ArduinoCore-zephyr - name: Initialize - working-directory: Arduino-Zephyr-API + working-directory: ArduinoCore-zephyr run: | - west init -m https://github.com/zephyrproject-rtos/gsoc-2022-arduino-core.git + mkdir build && cd build + west init -m https://github.com/arduino/ArduinoCore-zephyr.git west update - git clone https://github.com/arduino/ArduinoCore-API.git ArduinoCore-API - cp -r ArduinoCore-API/api modules/lib/Arduino-Zephyr-API/cores/arduino/. + rm -rf modules/lib/ArduinoCore-zephyr/* + cp -r ../* modules/lib/ArduinoCore-zephyr || true + rm modules/lib/ArduinoCore-zephyr/cores/arduino/api + cp -r modules/lib/ArduinoCore-API/api modules/lib/ArduinoCore-zephyr/cores/arduino/api - name: Build fade - working-directory: Arduino-Zephyr-API + working-directory: ArduinoCore-zephyr/build run: | - west build -p -b arduino_nano_33_ble_sense samples/fade + west build -p -b arduino_nano_33_ble//sense ../samples/fade - name: Build i2cdemo - working-directory: Arduino-Zephyr-API + working-directory: ArduinoCore-zephyr/build run: | - west build -p -b arduino_nano_33_ble_sense samples/i2cdemo + west build -p -b ek_ra8d1 ../samples/i2cdemo - name: Build adc - working-directory: Arduino-Zephyr-API + working-directory: ArduinoCore-zephyr/build run: | - west build -p -b beagleconnect_freedom samples/analog_input - - - name: Archive firmware - uses: actions/upload-artifact@v3 - with: - name: firmware - path: Arduino-Zephyr-API/build/zephyr/zephyr.* + west build -p -b arduino_nano_33_ble//sense ../samples/analog_input \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index cfc60ce2..8ea476a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,15 @@ # SPDX-License-Identifier: Apache-2.0 +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") + if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}) set(variant_dir variants/${BOARD}) -elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) - set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}) +elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${NORMALIZED_BOARD_TARGET}) + set(variant_dir variants/${NORMALIZED_BOARD_TARGET}) else() - message(INFO "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}") +if (CONFIG_ARDUINO_API) + message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${NORMALIZED_BOARD_TARGET}") +endif() endif() if (CONFIG_ARDUINO_API) diff --git a/cores/arduino/CMakeLists.txt b/cores/arduino/CMakeLists.txt index ca21a2c3..db1412f3 100644 --- a/cores/arduino/CMakeLists.txt +++ b/cores/arduino/CMakeLists.txt @@ -6,6 +6,8 @@ if(NOT DEFINED ARDUINO_BUILD_PATH) zephyr_sources(zephyrSerial.cpp) zephyr_sources(zephyrCommon.cpp) +zephyr_sources(USB.cpp) +zephyr_sources(itoa.cpp) if(DEFINED CONFIG_ARDUINO_ENTRY) zephyr_sources(main.cpp) diff --git a/cores/arduino/SerialUSB.h b/cores/arduino/SerialUSB.h index 0e67dc71..f26de64a 100644 --- a/cores/arduino/SerialUSB.h +++ b/cores/arduino/SerialUSB.h @@ -31,6 +31,6 @@ class SerialUSB_ : public ZephyrSerial { }; } // namespace arduino -#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) +#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) extern arduino::SerialUSB_ Serial; #endif \ No newline at end of file diff --git a/cores/arduino/USB.cpp b/cores/arduino/USB.cpp index 3847d96d..735f2350 100644 --- a/cores/arduino/USB.cpp +++ b/cores/arduino/USB.cpp @@ -4,23 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -// Make PluggableUSB link happy -#include "api/PluggableUSB.h" - -static uint8_t _epBuffer[1]; -void* epBuffer(unsigned int n) { - return &_epBuffer[n]; -}; - -arduino::PluggableUSB_::PluggableUSB_() {} - #include #include #include #include #include -#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) +#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) const struct device *const usb_dev = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), cdc_acm, 0)); void usb_status_cb(enum usb_dc_status_code cb_status, const uint8_t *param) { diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 88874624..dff4d605 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -10,14 +10,16 @@ #endif int main(void) { -#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) || DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials) +#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) Serial.begin(115200); #endif setup(); for (;;) { loop(); + #if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) || DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials) if (arduino::serialEventRun) arduino::serialEventRun(); + #endif } return 0; diff --git a/cores/arduino/zephyrSerial.cpp b/cores/arduino/zephyrSerial.cpp index 8d838c6b..2c93f4ff 100644 --- a/cores/arduino/zephyrSerial.cpp +++ b/cores/arduino/zephyrSerial.cpp @@ -198,11 +198,16 @@ void arduino::ZephyrSerial::flush() { } } +#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm)) +#define FIRST_UART_INDEX 1 +#else +#define FIRST_UART_INDEX 0 +#endif #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials) -#if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) +#if !(DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) // If CDC USB, use that object as Serial (and SerialUSB) -arduino::ZephyrSerial Serial(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), serials, 0))); +arduino::ZephyrSerial Serial(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), serials, FIRST_UART_INDEX))); #endif #if (DT_PROP_LEN(DT_PATH(zephyr_user), serials) > 1) #define ARDUINO_SERIAL_DEFINED_0 1 diff --git a/cores/arduino/zephyrSerial.h b/cores/arduino/zephyrSerial.h index 7e7a160a..047262e8 100644 --- a/cores/arduino/zephyrSerial.h +++ b/cores/arduino/zephyrSerial.h @@ -81,7 +81,7 @@ class ZephyrSerial : public HardwareSerial } // namespace arduino #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials) -#if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) +#if !(DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM) // If CDC USB, use that object as Serial (and SerialUSB) extern arduino::ZephyrSerial Serial; #endif diff --git a/extra/bootstrap.sh b/extra/bootstrap.sh index 796be9e4..512c0aad 100755 --- a/extra/bootstrap.sh +++ b/extra/bootstrap.sh @@ -12,3 +12,6 @@ west init -l . west update pip install -r ../zephyr/scripts/requirements-base.txt # download slim toolchain from https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8 + +# add here the required blobs based on supported platforms +west blobs fetch hal_nxp \ No newline at end of file diff --git a/samples/analog_input/CMakeLists.txt b/samples/analog_input/CMakeLists.txt index 83ac0d6b..87169d5c 100644 --- a/samples/analog_input/CMakeLists.txt +++ b/samples/analog_input/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(analog_input) diff --git a/samples/attach_interrupt/CMakeLists.txt b/samples/attach_interrupt/CMakeLists.txt index 711b9673..991732b5 100644 --- a/samples/attach_interrupt/CMakeLists.txt +++ b/samples/attach_interrupt/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(attach_interrupt) diff --git a/samples/blinky_arduino/CMakeLists.txt b/samples/blinky_arduino/CMakeLists.txt index e5c58ee3..3d78417b 100644 --- a/samples/blinky_arduino/CMakeLists.txt +++ b/samples/blinky_arduino/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) diff --git a/samples/button_press_led/CMakeLists.txt b/samples/button_press_led/CMakeLists.txt index e5c58ee3..3d78417b 100644 --- a/samples/button_press_led/CMakeLists.txt +++ b/samples/button_press_led/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) diff --git a/samples/fade/CMakeLists.txt b/samples/fade/CMakeLists.txt index 6f3c4cff..84053036 100644 --- a/samples/fade/CMakeLists.txt +++ b/samples/fade/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(fade) diff --git a/samples/hello_arduino/CMakeLists.txt b/samples/hello_arduino/CMakeLists.txt index 0675b10d..b18bdf5c 100644 --- a/samples/hello_arduino/CMakeLists.txt +++ b/samples/hello_arduino/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(hello_world) diff --git a/samples/i2cdemo/CMakeLists.txt b/samples/i2cdemo/CMakeLists.txt index e79ab241..e9e9c0b6 100644 --- a/samples/i2cdemo/CMakeLists.txt +++ b/samples/i2cdemo/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) diff --git a/samples/serial_event/CMakeLists.txt b/samples/serial_event/CMakeLists.txt index a275e3cc..b06eb6f1 100644 --- a/samples/serial_event/CMakeLists.txt +++ b/samples/serial_event/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(serial_event) diff --git a/samples/spi_controller/CMakeLists.txt b/samples/spi_controller/CMakeLists.txt index 824634e5..f296c294 100644 --- a/samples/spi_controller/CMakeLists.txt +++ b/samples/spi_controller/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(spi_controller) diff --git a/samples/threads_arduino/CMakeLists.txt b/samples/threads_arduino/CMakeLists.txt index f9aea636..3976c817 100644 --- a/samples/threads_arduino/CMakeLists.txt +++ b/samples/threads_arduino/CMakeLists.txt @@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.20.0) cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) -set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) +set(NORMALIZED_BOARD_TARGET "${BOARD}${BOARD_QUALIFIERS}") +string(REPLACE "/" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}") +set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/ArduinoCore-zephyr/loader/boards/${NORMALIZED_BOARD_TARGET}.overlay) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(threads)