Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
459 changes: 455 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ heapless = "0.9.2"
log = "0.4.29"
cortex-m-rt = "0.7.5"
static_cell = "2.1.1"
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"
defmt = "1"
defmt-rtt = "1"
panic-probe = "1"
rp235x-hal = "0.3"

[profile.dev]
debug = 1
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];

forAllSystems = nixpkgs.lib.genAttrs systems;
Expand All @@ -23,6 +24,7 @@
pkgs.probe-rs
pkgs.flip-link
pkgs.gcc-arm-embedded-14
pkgs.picotool
];

};
Expand Down
32 changes: 32 additions & 0 deletions platforms/cmforth-picocalc/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[target.thumbv8m.main-none-eabihf]
# Choose a default "cargo run" tool (see README for more info)
# - `probe-rs` provides flashing and defmt via a hardware debugger, and stack unwind on panic
# - `picotool` loads an elf, skipping unchanged flash sectors, verify it, and execute it
#runner = "probe-rs run --chip RP235x --protocol swd"
# runner = "picotool load -f -u -v -x -t elf"
runner = "probe-rs run --chip RP235x --protocol swd"

linker = "flip-link"

# Pass some extra options to rustc, some of which get passed on to the linker.
#
# * linker argument --nmagic turns off page alignment of sections (which saves
# flash space)
# * linker argument -Tlink.x tells the linker to use link.x as a linker script.
# This is usually provided by the cortex-m-rt crate, and by default the
# version in that crate will include a file called `memory.x` which describes
# the particular memory layout for your specific chip.
# * linker argument -Tdefmt.x also tells the linker to use `defmt.x` as a
# secondary linker script. This is required to make defmt_rtt work.
rustflags = [
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
"-C", "target-cpu=cortex-m33",
]

[build]
target = "thumbv8m.main-none-eabihf"

[env]
DEFMT_LOG = "debug"
22 changes: 22 additions & 0 deletions platforms/cmforth-picocalc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "cmforth-picocalc"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
cmforth.workspace = true
cortex-m-rt.workspace = true
cortex-m.workspace = true
defmt-rtt.workspace = true
defmt.workspace = true
embedded-graphics.workspace = true
embedded-hal.workspace = true
heapless.workspace = true
panic-probe = { workspace = true, features = ["print-defmt"] }
rp235x-hal = { workspace = true, features = [
"rt",
"critical-section-impl",
"binary-info",
] }
static_cell.workspace = true
16 changes: 16 additions & 0 deletions platforms/cmforth-picocalc/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::{env, fs::File, io::Write, path::Path};

fn main() {
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rerun-if-changed=build.rs");
copy_linker_script()
}

fn copy_linker_script() {
let out_dir = env::var("OUT_DIR").expect("No OUT_DIR");
let dest_path = Path::new(&out_dir);
let mut f = File::create(dest_path.join("memory.x")).unwrap();
f.write_all(include_bytes!("memory.x")).unwrap();

println!("cargo:rustc-link-search={}", dest_path.display());
}
75 changes: 75 additions & 0 deletions platforms/cmforth-picocalc/memory.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
MEMORY {
/*
* The RP2350 has either external or internal flash.
*
* 2 MiB is a safe default here, although a Pico 2 has 4 MiB.
*/
FLASH : ORIGIN = 0x10000000, LENGTH = 2048K
/*
* RAM consists of 8 banks, SRAM0-SRAM7, with a striped mapping.
* This is usually good for performance, as it distributes load on
* those banks evenly.
*/
RAM : ORIGIN = 0x20000000, LENGTH = 512K
/*
* RAM banks 8 and 9 use a direct mapping. They can be used to have
* memory areas dedicated for some specific job, improving predictability
* of access times.
* Example: Separate stacks for core0 and core1.
*/
SRAM4 : ORIGIN = 0x20080000, LENGTH = 4K
SRAM5 : ORIGIN = 0x20081000, LENGTH = 4K
}

SECTIONS {
/* ### Boot ROM info
*
* Goes after .vector_table, to keep it in the first 4K of flash
* where the Boot ROM (and picotool) can find it
*/
.start_block : ALIGN(4)
{
__start_block_addr = .;
KEEP(*(.start_block));
KEEP(*(.boot_info));
} > FLASH

} INSERT AFTER .vector_table;

/* move .text to start /after/ the boot info */
_stext = ADDR(.start_block) + SIZEOF(.start_block);

SECTIONS {
/* ### Picotool 'Binary Info' Entries
*
* Picotool looks through this block (as we have pointers to it in our
* header) to find interesting information.
*/
.bi_entries : ALIGN(4)
{
/* We put this in the header */
__bi_entries_start = .;
/* Here are the entries */
KEEP(*(.bi_entries));
/* Keep this block a nice round size */
. = ALIGN(4);
/* We put this in the header */
__bi_entries_end = .;
} > FLASH
} INSERT AFTER .text;

SECTIONS {
/* ### Boot ROM extra info
*
* Goes after everything in our program, so it can contain a signature.
*/
.end_block : ALIGN(4)
{
__end_block_addr = .;
KEEP(*(.end_block));
} > FLASH

} INSERT AFTER .uninit;

PROVIDE(start_to_end = __end_block_addr - __start_block_addr);
PROVIDE(end_to_start = __start_block_addr - __end_block_addr);
Loading