Skip to content

Commit 0b2bc59

Browse files
authored
Merge pull request #105 from Neotron-Compute/add-elf2uf2
Add UF2 file to output and force clippy to run
2 parents bbf73fe + d7f07d8 commit 0b2bc59

File tree

7 files changed

+132
-92
lines changed

7 files changed

+132
-92
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,36 @@ jobs:
1515
submodules: true
1616
fetch-depth: 0
1717

18+
- name: Install tools
19+
uses: taiki-e/install-action@v2
20+
with:
21+
22+
1823
- name: Add targets
1924
run: |
2025
rustup target add thumbv6m-none-eabi
2126
2227
- name: Build neotron-pico-bios
2328
run: |
2429
cargo build --release --verbose
30+
elf2uf2-rs ./target/thumbv6m-none-eabi/release/neotron-pico-bios
31+
32+
- name: Upload Artifacts
33+
uses: actions/upload-artifact@v4
34+
if: ${{success()}}
35+
with:
36+
name: Artifacts
37+
if-no-files-found: error
38+
path: |
39+
./target/thumbv6m-none-eabi/release/neotron-pico-bios
40+
./target/thumbv6m-none-eabi/release/neotron-pico-bios.uf2
2541
2642
- name: Upload files to Release
2743
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/')
2844
uses: softprops/action-gh-release@v1
2945
with:
3046
files: |
3147
./target/thumbv6m-none-eabi/release/neotron-pico-bios
48+
./target/thumbv6m-none-eabi/release/neotron-pico-bios.uf2
3249
env:
3350
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/clippy.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: [push, pull_request]
44

55
env:
66
CARGO_TERM_COLOR: always
7+
RUSTFLAGS: "-Dwarnings"
78

89
jobs:
910
clippy-check:
@@ -15,15 +16,11 @@ jobs:
1516
submodules: true
1617
fetch-depth: 0
1718

18-
- name: Install Rust
19-
uses: actions-rs/toolchain@v1
20-
with:
21-
toolchain: stable
22-
components: clippy
23-
target: thumbv6m-none-eabi
19+
- name: Add targets/components
20+
run: |
21+
rustup component add clippy
22+
rustup target add thumbv6m-none-eabi
2423
2524
- name: Run Clippy
26-
uses: actions-rs/clippy-check@v1
27-
with:
28-
token: ${{ secrets.GITHUB_TOKEN }}
29-
args: --all-features --target=thumbv6m-none-eabi
25+
run: |
26+
cargo clippy --target=thumbv6m-none-eabi --all-features

.github/workflows/format.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ jobs:
1212
submodules: true
1313
fetch-depth: 0
1414

15-
- name: Install Rust
16-
uses: actions-rs/toolchain@v1
17-
with:
18-
toolchain: stable
19-
components: rustfmt
15+
- name: Add components
16+
run: |
17+
rustup component add rustfmt
2018
2119
- name: Check Format
2220
run: cargo fmt -- --check

src/console.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ impl TextConsole {
304304
}
305305
}
306306

307+
impl Default for TextConsole {
308+
fn default() -> Self {
309+
Self::new()
310+
}
311+
}
312+
307313
unsafe impl Sync for TextConsole {}
308314

309315
impl core::fmt::Write for &TextConsole {

src/main.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod vga;
6262
use core::{
6363
convert::{TryFrom, TryInto},
6464
fmt::Write,
65+
ptr::{addr_of, addr_of_mut},
6566
sync::atomic::{AtomicBool, AtomicU32, Ordering},
6667
};
6768

@@ -333,10 +334,10 @@ static API_CALLS: common::Api = common::Api {
333334
const SECONDS_BETWEEN_UNIX_AND_NEOTRON_EPOCH: i64 = 946684800;
334335

335336
extern "C" {
336-
static mut _flash_os_start: u32;
337-
static mut _flash_os_len: u32;
338-
static mut _ram_os_start: u32;
339-
static mut _ram_os_len: u32;
337+
static _flash_os_start: u32;
338+
static _flash_os_len: u32;
339+
static _ram_os_start: u32;
340+
static _ram_os_len: u32;
340341
}
341342

342343
/// What we paint Core 0's stack with
@@ -710,11 +711,10 @@ fn paint_stacks() {
710711
static mut _stack_start: usize;
711712
}
712713
unsafe {
713-
let stack_len =
714-
(&_stack_start as *const usize as usize) - (&__sheap as *const usize as usize);
714+
let stack_len = (addr_of!(_stack_start) as usize) - (addr_of!(__sheap) as usize);
715715
// But not the top 64 words, because we're using the stack right now!
716716
let stack = core::slice::from_raw_parts_mut(
717-
&mut __sheap as *mut usize,
717+
addr_of_mut!(__sheap),
718718
(stack_len / core::mem::size_of::<usize>()) - 256,
719719
);
720720
info!("Painting Core 1 stack: {:?}", stack.as_ptr_range());
@@ -744,10 +744,9 @@ fn check_stacks() {
744744
static mut __sheap: usize;
745745
static mut _stack_start: usize;
746746
}
747-
let stack_len =
748-
unsafe { (&_stack_start as *const usize as usize) - (&__sheap as *const usize as usize) };
747+
let stack_len = unsafe { (addr_of!(_stack_start) as usize) - (addr_of!(__sheap) as usize) };
749748
check_stack(
750-
unsafe { &__sheap as *const usize },
749+
unsafe { addr_of!(__sheap) },
751750
stack_len,
752751
CORE0_STACK_PAINT_WORD,
753752
);
@@ -1896,8 +1895,8 @@ pub extern "C" fn memory_get_region(region: u8) -> FfiOption<common::MemoryRegio
18961895
0 => {
18971896
// Application Region
18981897
FfiOption::Some(MemoryRegion {
1899-
start: unsafe { &mut _ram_os_start as *mut u32 } as *mut u8,
1900-
length: unsafe { &mut _ram_os_len as *const u32 } as usize,
1898+
start: unsafe { addr_of!(_ram_os_start) } as *mut u8,
1899+
length: unsafe { addr_of!(_ram_os_len) } as usize,
19011900
kind: common::MemoryKind::Ram.into(),
19021901
})
19031902
}

src/multicore.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ static CORE1_ENTRY_FUNCTION: [u16; 2] = [
6565
/// Starts core 1 running the given function, with the given stack.
6666
pub fn launch_core1_with_stack(
6767
main_func: unsafe extern "C" fn() -> u32,
68-
stack: &mut [usize],
68+
stack: *mut usize,
69+
stack_len: usize,
6970
ppb: &mut crate::pac::PPB,
7071
fifo: &mut rp_pico::hal::sio::SioFifo,
7172
psm: &mut crate::pac::PSM,
@@ -80,25 +81,30 @@ pub fn launch_core1_with_stack(
8081

8182
defmt::debug!("Setting up stack...");
8283

83-
// Gets popped into `r0` by CORE1_ENTRY_FUNCTION. This is the `main`
84-
// function we want to run. It appears in the call to `core1_wrapper` as
85-
// the first argument.
86-
stack[stack.len() - 3] = main_func as *const () as usize;
87-
// Gets popped into `r1` by CORE1_ENTRY_FUNCTION. This is the top of stack
88-
// for Core 1. It appears in the call to `core1_wrapper` as the second
89-
// argument.
90-
stack[stack.len() - 2] = stack.as_ptr() as *const _ as usize;
91-
// Gets popped into `pc` by CORE1_ENTRY_FUNCTION. This is the function
92-
// `CORE1_ENTRY_FUNCTION` will jump to, passing the above two values as
93-
// arguments.
94-
stack[stack.len() - 1] = core1_wrapper as *const () as usize;
95-
// Point into the top of the stack (so there are three values pushed onto
96-
// it, i.e. at/above it)
97-
let stack_ptr = unsafe { stack.as_mut_ptr().add(stack.len() - 3) };
84+
let stack_ptr = unsafe {
85+
// Gets popped into `r0` by CORE1_ENTRY_FUNCTION. This is the `main`
86+
// function we want to run. It appears in the call to `core1_wrapper` as
87+
// the first argument.
88+
stack
89+
.add(stack_len - 3)
90+
.write_volatile(main_func as *const () as usize);
91+
// Gets popped into `r1` by CORE1_ENTRY_FUNCTION. This is the top of stack
92+
// for Core 1. It appears in the call to `core1_wrapper` as the second
93+
// argument.
94+
stack.add(stack_len - 2).write_volatile(stack as usize);
95+
// Gets popped into `pc` by CORE1_ENTRY_FUNCTION. This is the function
96+
// `CORE1_ENTRY_FUNCTION` will jump to, passing the above two values as
97+
// arguments.
98+
stack
99+
.add(stack_len - 1)
100+
.write_volatile(core1_wrapper as *const () as usize);
101+
// Point into the top of the stack (so there are three values pushed onto
102+
// it, i.e. at/above it)
103+
stack.add(stack_len - 3)
104+
};
98105

99106
defmt::debug!("Stack ptr is 0x{:x}", stack_ptr);
100-
defmt::debug!("Stack bottom is 0x{:x}", stack.as_ptr());
101-
defmt::debug!("Stack top is 0x{:x}", &stack[stack.len() - 4..stack.len()]);
107+
defmt::debug!("Stack bottom is 0x{:x}", stack);
102108

103109
// This is the launch sequence we send to core1, to get it to leave the
104110
// boot ROM and run our code.

0 commit comments

Comments
 (0)