Skip to content

Commit

Permalink
added wokwi test
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicpoeschko committed Dec 18, 2023
1 parent 64e946e commit db06bde
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 10 deletions.
33 changes: 30 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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'
15 changes: 15 additions & 0 deletions blink.test.yaml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions diagram.json
Original file line number Diff line number Diff line change
@@ -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" ] ]
]
}
21 changes: 19 additions & 2 deletions src/ApplicationConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,22 @@ using Clock = HW::SystickClock;
using StackProtector = Kvasir::StackProtector<>;
using FaultHandler = Kvasir::Fault::Handler<HW::Fault_CleanUpAction>;

using Startup = Kvasir::Startup::
Startup<HW::ClockSettings, Clock, HW::ComBackend, FaultHandler, StackProtector, HW::PinConfig>;
struct DmaConfig {
static constexpr auto numberOfChannels = 1;
static constexpr auto callbackFunctionSize = 8;
};

using Dma = Kvasir::DMA::DmaBase<DmaConfig>;

using Uart
= Kvasir::UART::UartBehavior<HW::UartConfig, Dma, Dma::Channel::ch0, Dma::Priority::low, 512>;

using Startup = Kvasir::Startup::Startup<
HW::ClockSettings,
Clock,
HW::ComBackend,
FaultHandler,
StackProtector,
HW::PinConfig,
Dma,
Uart>;
18 changes: 17 additions & 1 deletion src/HWConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
28 changes: 24 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@
//

#include <cmake_git_version/version.hpp>
#include <kvasir/Util/StaticVector.hpp>

template<typename Buffer>
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<std::byte>(x);
});
UC_LOG_D("{}",s);
Uart::send_nocopy(buffer);
}

int main() {
UC_LOG_D("{}", CMakeGitVersion::FullVersion);
auto next = Clock::now();
Kvasir::StaticVector<std::byte, 128> 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();
Expand Down
4 changes: 4 additions & 0 deletions wokwi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wokwi]
version = 1
firmware = "build/release_flash.uf2"
elf = "build/release.elf"

0 comments on commit db06bde

Please sign in to comment.