diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b4947a..505aafd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,9 +10,9 @@ jobs: EXTRA_PACKAGES: TRIZEN_EXTRA_PACKAGES: - name: docker + name: build steps: - - name: checkout repo + - name: Checkout repo uses: actions/checkout@v3 with: submodules: 'recursive' @@ -23,7 +23,7 @@ jobs: - name: Run Docker run: docker run -v ./:/project kvasir_fw_build - - name: upload firmware + - name: Upload firmware uses: actions/upload-artifact@v3 with: name: firmware @@ -34,3 +34,30 @@ jobs: docker_build/*.uf2 docker_build/*.lst docker_build/*.map + + test-on-wokwi: + + runs-on: ubuntu-latest + + needs: build + + name: test + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Download firmware + uses: actions/download-artifact@v2 + with: + name: firmware + path: build + + - name: Test the binary on Wokwi + uses: wokwi/wokwi-ci-action@v1 + with: + token: ${{ secrets.WOKWI_CLI_TOKEN }} + path: / + timeout: 1000 # ms + scenario: 'blink.test.yaml' diff --git a/blink.test.yaml b/blink.test.yaml new file mode 100644 index 0000000..3f008df --- /dev/null +++ b/blink.test.yaml @@ -0,0 +1,15 @@ +name: Blinky test +version: 1 +author: Dominic Poeschko + +steps: + - wait-serial: 'LED on' + - expect-pin: + part-id: led1 + pin: A + value: 1 + - wait-serial: 'LED off' + - expect-pin: + part-id: led1 + pin: A + value: 0 diff --git a/diagram.json b/diagram.json new file mode 100644 index 0000000..d9f7db3 --- /dev/null +++ b/diagram.json @@ -0,0 +1,30 @@ +{ + "version": 1, + "author": "Dominic Poeschko", + "editor": "wokwi", + "parts": [ + { + "type": "wokwi-pi-pico", + "id": "pico", + "top": 73.9, + "left": 132.55, + "rotate": 90, + "attrs": { "env": "arduino-community" } + }, + { + "type": "wokwi-resistor", + "id": "r1", + "top": 86, + "left": 172.8, + "attrs": { "value": "1000" } + }, + { "type": "wokwi-led", "id": "led1", "top": 54, "left": 138.2, "attrs": { "color": "red" } } + ], + "connections": [ + [ "pico:GP0", "$serialMonitor:RX", "", [] ], + [ "pico:GP1", "$serialMonitor:TX", "", [] ], + [ "pico:GP2", "r1:2", "green", [ "v0" ] ], + [ "r1:1", "led1:A", "green", [ "v0" ] ], + [ "pico:GND.3", "led1:C", "black", [ "v-19.2", "h9.6" ] ] + ] +} diff --git a/src/ApplicationConfig.hpp b/src/ApplicationConfig.hpp index 7daf013..709aeda 100644 --- a/src/ApplicationConfig.hpp +++ b/src/ApplicationConfig.hpp @@ -10,5 +10,22 @@ using Clock = HW::SystickClock; using StackProtector = Kvasir::StackProtector<>; using FaultHandler = Kvasir::Fault::Handler; -using Startup = Kvasir::Startup:: - Startup; +struct DmaConfig { + static constexpr auto numberOfChannels = 1; + static constexpr auto callbackFunctionSize = 8; +}; + +using Dma = Kvasir::DMA::DmaBase; + +using Uart + = Kvasir::UART::UartBehavior; + +using Startup = Kvasir::Startup::Startup< + HW::ClockSettings, + Clock, + HW::ComBackend, + FaultHandler, + StackProtector, + HW::PinConfig, + Dma, + Uart>; diff --git a/src/HWConfig.hpp b/src/HWConfig.hpp index 95e26ad..73a03bd 100644 --- a/src/HWConfig.hpp +++ b/src/HWConfig.hpp @@ -2,13 +2,29 @@ #include "HWConfigCommon.hpp" namespace HW { namespace Pin { - using led = decltype(makePinLocation(Kvasir::Io::port0, Kvasir::Io::pin25)); + + using uart_tx = decltype(makePinLocation(Kvasir::Io::port0, Kvasir::Io::pin0)); + using uart_rx = decltype(makePinLocation(Kvasir::Io::port0, Kvasir::Io::pin1)); + using led = decltype(makePinLocation(Kvasir::Io::port0, Kvasir::Io::pin2)); } // namespace Pin struct Fault_CleanUpAction { void operator()() {} }; +struct UartConfig { + static constexpr auto clockSpeed = ClockSpeed; + + static constexpr auto instance = 0; + static constexpr auto rxPinLocation = Pin::uart_rx{}; + static constexpr auto txPinLocation = Pin::uart_tx{}; + static constexpr auto baudRate = 115200; + static constexpr auto dataBits = Kvasir::UART::DataBits::_8; + static constexpr auto parity = Kvasir::UART::Parity::none; + static constexpr auto stopBits = Kvasir::UART::StopBits::_1; + static constexpr auto isrPriority = 3; +}; + struct PinConfig { static constexpr auto powerClockEnable = list( clear(Kvasir::Peripheral::RESETS::Registers<>::RESET::io_bank0), diff --git a/src/main.cpp b/src/main.cpp index cd870aa..800b84c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,36 @@ // #include +#include + +template +static void print(Buffer& buffer, std::string_view s) { + buffer.resize(s.size()); + std::transform(s.begin(), s.end(), buffer.begin(), [](auto x) { + return static_cast(x); + }); + UC_LOG_D("{}",s); + Uart::send_nocopy(buffer); +} int main() { UC_LOG_D("{}", CMakeGitVersion::FullVersion); - auto next = Clock::now(); + Kvasir::StaticVector buffer; + auto next = Clock::now(); + bool on = false; while(true) { auto const now = Clock::now(); if(now > next) { - UC_LOG_D("foo"); - next += 1s; - apply(toggle(HW::Pin::led{})); + next += 250ms; + if(on) { + print(buffer, "LED off\n"); + apply(clear(HW::Pin::led{})); + } else { + print(buffer, "LED on\n"); + apply(set(HW::Pin::led{})); + + } + on = !on; } StackProtector::handler(); diff --git a/wokwi.toml b/wokwi.toml new file mode 100644 index 0000000..abb072a --- /dev/null +++ b/wokwi.toml @@ -0,0 +1,4 @@ +[wokwi] +version = 1 +firmware = "build/release_flash.uf2" +elf = "build/release.elf"