Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

[RFC] #[ramfunc] #100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/*.rs.bk
.#*
Cargo.lock
bin/*.after
bin/*.before
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ version = "0.5.3"

[dependencies]
r0 = "0.2.1"
cortex-m-rt-macros = { path = "macros", version = "0.1.0" }

[dev-dependencies]
panic-semihosting = "0.3.0"
Expand Down
2 changes: 2 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ main() {

cargo check --target $TARGET --features device

( cd macros && cargo check && cargo test )

local examples=(
alignment
minimal
Expand Down
4 changes: 2 additions & 2 deletions examples/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_abort;

use core::ptr;

entry!(main);
use rt::entry;

static mut BSS1: u16 = 0;
static mut BSS2: u8 = 0;
Expand All @@ -19,6 +18,7 @@ static mut DATA2: u16 = 1;
static RODATA1: &[u8; 3] = b"012";
static RODATA2: &[u8; 2] = b"34";

#[entry]
fn main() -> ! {
unsafe {
let _bss1 = ptr::read_volatile(&BSS1);
Expand Down
4 changes: 2 additions & 2 deletions examples/data_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_abort;

use core::ptr;

entry!(main);
use rt::entry;

// This large static array uses most of .rodata
static RODATA: [u8; 48*1024] = [1u8; 48*1024];
Expand All @@ -20,6 +19,7 @@ static RODATA: [u8; 48*1024] = [1u8; 48*1024];
// without also overflowing RAM.
static mut DATA: [u8; 16*1024] = [1u8; 16*1024];

#[entry]
fn main() -> ! {
unsafe {
let _bigdata = ptr::read_volatile(&RODATA as *const u8);
Expand Down
5 changes: 2 additions & 3 deletions examples/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

// the program entry point
entry!(main);
use rt::entry;

#[entry]
fn main() -> ! {
loop {}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

// the program entry point
entry!(main);
use rt::entry;

// the program entry point
#[entry]
fn main() -> ! {
loop {}
}
13 changes: 4 additions & 9 deletions examples/override-exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
#![no_std]

extern crate cortex_m;
#[macro_use(entry, exception)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

use cortex_m::asm;
use rt::ExceptionFrame;

// the program entry point
entry!(main);
use rt::{entry, exception, ExceptionFrame};

#[entry]
fn main() -> ! {
loop {}
}

exception!(*, default_handler);

#[exception(DefaultHandler)]
fn default_handler(_irqn: i16) {
asm::bkpt();
}

exception!(HardFault, hard_fault);

#[exception(HardFault)]
fn hard_fault(_ef: &ExceptionFrame) -> ! {
asm::bkpt();

Expand Down
8 changes: 3 additions & 5 deletions examples/pre_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
#![no_main]
#![no_std]

#[macro_use(entry, pre_init)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

pre_init!(disable_watchdog);
use rt::{entry, pre_init};

#[pre_init]
unsafe fn disable_watchdog() {
// Do what you need to disable the watchdog.
}

// the program entry point
entry!(main);

#[entry]
fn main() -> ! {
loop {}
}
12 changes: 5 additions & 7 deletions examples/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
#![no_main]
#![no_std]

#[macro_use(entry, exception)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

// the program entry point
entry!(main);
use rt::{entry, exception};

#[entry]
fn main() -> ! {
loop {}
}

// exception handler with state
exception!(SysTick, sys_tick, state: u32 = 0);

fn sys_tick(state: &mut u32) {
*state += 1;
#[exception(SysTick, static STATE: u32 = 0)]
fn sys_tick() {
*STATE += 1;
}
14 changes: 14 additions & 0 deletions link.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ SECTIONS
/* LMA of .data */
__sidata = LOADADDR(.data);

.ramfunc : ALIGN(4)
{
*(.ramfunc.*);

. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
} > RAM AT > FLASH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want it at RAM? It is common to put the ramfunc in CCM (core coupled memory) RAM to not contend with the data RAM or vice versa.
Can we have make this user specifiable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have make this user specifiable?

In general, we don't have good support for multiple memory regions -- we hardcode most things to Flash and RAM (e.g. we don't have a way to say put this static mut in CCRAM and that one in RAM).

By user specifiable do you mean that (a) the user should be able to (a) say pull all #[ramfunc] functions into CCRAM or put all of them in RAM; or (b) that the user should be specify that this one function goes in CCRAM and that one goes in RAM?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferable for each one, but if we can make all settable that would be a good improvement.


/* VMA of .ramfunc */
__sramfunc = ADDR(.ramfunc);
__eramfunc = ADDR(.ramfunc) + SIZEOF(.ramfunc);

/* LMA of .ramfunc */
__siramfunc = LOADADDR(.ramfunc);

/* ### .bss */
.bss : ALIGN(4)
{
Expand Down
18 changes: 18 additions & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "cortex-m-rt-macros"
version = "0.1.0"
authors = ["Jorge Aparicio <[email protected]>"]

[lib]
proc-macro = true

[dependencies]
quote = "0.6.6"
rand = "0.5.5"

[dependencies.syn]
features = ["extra-traits", "full"]
version = "0.14.8"

[dev-dependencies]
cortex-m-rt = { path = ".." }
Loading