Skip to content

Commit 03f94df

Browse files
authored
Run build and rp2040js simulation on CI (#19)
* Make build easier * Add CI * tag * install gcc * Add rp2040js * Patch * Fix wildcard * Fix * sleep * fix * Remove unnecessary patch * Patch picoruby instead of pico-sdk * Remove unnecessary file * Remove patch * Use tee
1 parent 726df39 commit 03f94df

File tree

8 files changed

+122
-3
lines changed

8 files changed

+122
-3
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: 'recursive'
18+
fetch-tags: true
19+
- run: |
20+
sudo apt remove man-db
21+
sudo apt install -y cmake ruby gcc-arm-none-eabi npm
22+
pushd lib/pico-sdk
23+
git fetch origin --tags --recurse-submodules=no
24+
popd
25+
pushd lib/pico-extras
26+
git fetch origin --tags --recurse-submodules=no
27+
popd
28+
pushd lib/rp2040js
29+
git apply < ../../.github/workflows/rp2040js.patch
30+
npm install
31+
popd
32+
- run: rake mrubyc:pico:debug
33+
- run: |
34+
set -eux
35+
npm --prefix ./lib/rp2040js run start:micropython -- --image $PWD/build_pico/R2P2_PICO-FLASH*.uf2 | tee log.txt &
36+
sleep 10
37+
kill -9 %1
38+
# cat log.txt
39+
grep "/etc/init.d/r2p2" log.txt
40+
# grep "No app.(mrb|rb) found" log.txt
41+
42+

.github/workflows/rp2040js.patch

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
diff --git a/demo/micropython-run.ts b/demo/micropython-run.ts
2+
index 2eed868..4c24513 100644
3+
--- a/demo/micropython-run.ts
4+
+++ b/demo/micropython-run.ts
5+
@@ -6,6 +6,7 @@ import { USBCDC } from '../src/usb/cdc.js';
6+
import { ConsoleLogger, LogLevel } from '../src/utils/logging.js';
7+
import { bootromB1 } from './bootrom.js';
8+
import { loadCircuitpythonFlashImage, loadMicropythonFlashImage, loadUF2 } from './load-flash.js';
9+
+import { RP2040SysInfo } from '../src/peripherals/sysinfo.js';
10+
11+
const args = minimist(process.argv.slice(2), {
12+
string: [
13+
@@ -90,5 +91,42 @@ process.stdin.on('data', (chunk) => {
14+
}
15+
});
16+
17+
+export class CustomRP2040SysInfo extends RP2040SysInfo {
18+
+ readUint32(offset: number) {
19+
+ const PLATFORM = 0x4;
20+
+ switch (offset) {
21+
+ case PLATFORM:
22+
+ return 0x01000002;
23+
+ }
24+
+ return super.readUint32(offset);
25+
+ }
26+
+}
27+
+
28+
+mcu.peripherals[0x40000] = new CustomRP2040SysInfo(mcu, 'SYSINFO_BASE');
29+
+
30+
+mcu.onBreak = (code) => {
31+
+ // TODO: raise HardFault exception
32+
+ // console.error('Breakpoint!', code);
33+
+ // console.log(code);
34+
+
35+
+ if(code == 27){
36+
+ const this_ = mcu.core;
37+
+ const RAM_START_ADDRESS = 0x20000000;
38+
+ const flashAddr = this_.registers[0];
39+
+ const ramAddr = this_.registers[1] - RAM_START_ADDRESS;
40+
+ const count = this_.registers[2];
41+
+
42+
+ // console.log("flash write:", flashAddr, ramAddr, count)
43+
+
44+
+ mcu.flash.set(mcu.sram.slice(ramAddr, ramAddr+count), flashAddr);
45+
+
46+
+ // Copy LR to PC register
47+
+ // this.registers[15] = this.registers[14];
48+
+ // this_.PC = this_.LR;
49+
+ } else {
50+
+ simulator.stop();
51+
+ }
52+
+};
53+
+
54+
simulator.rp2040.core.PC = 0x10000000;
55+
simulator.execute();

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
[submodule "lib/picoruby"]
22
path = lib/picoruby
33
url = [email protected]:picoruby/picoruby.git
4+
[submodule "lib/pico-sdk"]
5+
path = lib/pico-sdk
6+
url = https://github.com/raspberrypi/pico-sdk.git
7+
[submodule "lib/pico-extras"]
8+
path = lib/pico-extras
9+
url = https://github.com/raspberrypi/pico-extras.git
10+
[submodule "lib/rp2040js"]
11+
path = lib/rp2040js
12+
url = https://github.com/wokwi/rp2040js.git

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ add_dependencies(${PROJECT_NAME}
9393
)
9494
foreach(rb ${RUBY_FILES})
9595
add_custom_target(${rb}
96-
COMMAND ${PICORBC} -B${rb} -o${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb/${rb}.c ${CMAKE_SOURCE_DIR}/mrblib/${rb}.rb
96+
COMMAND
97+
mkdir -p ${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb &&
98+
${PICORBC} -B${rb} -o${CMAKE_SOURCE_DIR}/${BUILD_DIR}/mrb/${rb}.c ${CMAKE_SOURCE_DIR}/mrblib/${rb}.rb
99+
DEPENDS ${CMAKE_SOURCE_DIR}/mrblib/${rb}.rb
97100
)
98101
endforeach(rb)
99102

Rakefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
require "fileutils"
22

3+
unless ENV.include? "PICO_SDK_PATH"
4+
ENV["PICO_SDK_PATH"] = "#{File.dirname(__FILE__)}/lib/pico-sdk"
5+
end
6+
unless ENV.include? "PICO_EXTRAS_PATH"
7+
ENV["PICO_EXTRAS_PATH"] = "#{File.dirname(__FILE__)}/lib/pico-extras"
8+
end
9+
310
PICO_SDK_TAG = "2.1.1"
411
if PICO_SDK_TAG == "2.1.1"
512
PICO_EXTRAS_TAG = "sdk-2.1.0" # workaround. 2.1.1 and 2.1.0 are the same
@@ -128,7 +135,7 @@ task :check_pico_sdk => :check_pico_sdk_path do
128135
raise <<~MSG
129136
pico-sdk #{PICO_SDK_TAG} is not checked out!\n
130137
Tips for dealing with:\n
131-
cd $PICO_SDK_PATH && git pull && git checkout #{PICO_SDK_TAG} && git submodule update --recursive\n
138+
cd $PICO_SDK_PATH && git fetch origin --tags && git checkout #{PICO_SDK_TAG} && git submodule update --recursive\n
132139
MSG
133140
end
134141
end
@@ -137,7 +144,7 @@ task :check_pico_sdk => :check_pico_sdk_path do
137144
raise <<~MSG
138145
pico-extras #{PICO_EXTRAS_TAG} is not checked out!\n
139146
Tips for dealing with:\n
140-
cd $PICO_EXTRAS_PATH && git pull && git checkout #{PICO_EXTRAS_TAG} && git submodule update --recursive\n
147+
cd $PICO_EXTRAS_PATH && git fetch origin --tags && git checkout #{PICO_EXTRAS_TAG} && git submodule update --recursive\n
141148
MSG
142149
end
143150
end

lib/pico-extras

Submodule pico-extras added at f05d4f7

lib/pico-sdk

Submodule pico-sdk added at bddd20f

lib/rp2040js

Submodule rp2040js added at 9c0c110

0 commit comments

Comments
 (0)