Skip to content

Commit

Permalink
rp23: add missing binary info in linker script
Browse files Browse the repository at this point in the history
  • Loading branch information
romainreignier committed Sep 26, 2024
1 parent af6fbb0 commit af69d31
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 62 deletions.
19 changes: 10 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
// Uncomment the target of your chip.
//"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
//"rust-analyzer.cargo.target": "thumbv7m-none-eabi",
"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
//"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
//"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
//"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
"rust-analyzer.cargo.features": [
// Comment out these features when working on the examples. Most example crates do not have any cargo features.
"stm32f446re",
"time-driver-any",
"unstable-pac",
"exti",
"rt",
// "stm32f446re",
// "stm32h747xi-cm7",
// "time-driver-any",
// "unstable-pac",
// "exti",
// "rt",
],
"rust-analyzer.linkedProjects": [
"embassy-stm32/Cargo.toml",
// "embassy-stm32/Cargo.toml",
// To work on the examples, comment the line above and all of the cargo.features lines,
// then uncomment ONE line below to select the chip you want to work on.
// This makes rust-analyzer work on the example crate and all its dependencies.
Expand All @@ -50,7 +51,7 @@
// "examples/stm32l4/Cargo.toml",
// "examples/stm32l5/Cargo.toml",
// "examples/stm32u5/Cargo.toml",
// "examples/stm32wb/Cargo.toml",
"examples/stm32wb/Cargo.toml",
// "examples/stm32wl/Cargo.toml",
// "examples/wasm/Cargo.toml",
],
Expand Down
1 change: 1 addition & 0 deletions examples/rp23/memory.x
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SECTIONS {
{
__start_block_addr = .;
KEEP(*(.start_block));
KEEP(*(.boot_info));
} > FLASH

} INSERT AFTER .vector_table;
Expand Down
8 changes: 7 additions & 1 deletion examples/stm32f1/src/bin/input_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ async fn main(spawner: Spawner) {
unwrap!(spawner.spawn(blinky(p.PC13)));

let ch3 = CapturePin::new_ch3(p.PA2, Pull::None);
let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default());
let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(10), Default::default());

let mut last_capture = Option::None;
loop {
info!("wait for rising edge");
ic.wait_for_rising_edge(Channel::Ch3).await;

let capture_value = ic.get_capture_value(Channel::Ch3);
info!("new capture! {}", capture_value);
info!("new capture! {}", capture_value);
if let Some(c) = last_capture {
info!("period: {}", (capture_value - c));
}
last_capture = Some(capture_value);
}
}
4 changes: 2 additions & 2 deletions examples/stm32f4/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# replace STM32F429ZITx with your chip as listed in `probe-rs chip list`
runner = "probe-rs run --chip STM32F429ZITx"
runner = "probe-rs run --chip STM32F411CEUx"

[build]
target = "thumbv7em-none-eabi"

[env]
DEFMT_LOG = "trace"
DEFMT_LOG = "info"
9 changes: 8 additions & 1 deletion examples/stm32f4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
# Change stm32f429zi to your chip name, if necessary.
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f411ce", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] }
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
Expand Down Expand Up @@ -34,5 +34,12 @@ usbd-hid = "0.8.1"
static_cell = "2"
chrono = { version = "^0.4", default-features = false}

ssd1306 = "0.8.4"
#bme280 = "0.5.0"
bme280 = { git = "https://github.com/RobinThrift/bme280-rs.git", commit = "12d5e98253e0e8fadbd43895a608263f4a84884d", features = ["async"]}
ufmt = "0.2.0"
ufmt-macros = "0.3.0"
embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" }

[profile.release]
debug = 2
2 changes: 1 addition & 1 deletion examples/stm32f4/src/bin/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");

let mut led = Output::new(p.PB7, Level::High, Speed::Low);
let mut led = Output::new(p.PC13, Level::High, Speed::Low);

loop {
info!("high");
Expand Down
4 changes: 2 additions & 2 deletions examples/stm32f4/src/bin/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn main() -> ! {

let p = embassy_stm32::init(Default::default());

let button = Input::new(p.PC13, Pull::Down);
let mut led1 = Output::new(p.PB0, Level::High, Speed::Low);
let button = Input::new(p.PA0, Pull::Up);
let mut led1 = Output::new(p.PC13, Level::High, Speed::Low);
let _led2 = Output::new(p.PB7, Level::High, Speed::Low);
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);

Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f4/src/bin/button_exti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");

let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down);
let mut button = ExtiInput::new(p.PA0, p.EXTI0, Pull::Up);

info!("Press the USER button...");

Expand Down
6 changes: 3 additions & 3 deletions examples/stm32f4/src/bin/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use embassy_stm32::i2c::{Error, I2c};
use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};

const ADDRESS: u8 = 0x5F;
const WHOAMI: u8 = 0x0F;
const ADDRESS: u8 = 0x76;
const WHOAMI: u8 = 0xD0;

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
Expand All @@ -20,7 +20,7 @@ async fn main(_spawner: Spawner) {
let mut data = [0u8; 1];

match i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) {
Ok(()) => info!("Whoami: {}", data[0]),
Ok(()) => info!("Chip ID: {:x}", data[0]),
Err(Error::Timeout) => error!("Operation timed out"),
Err(e) => error!("I2c Error: {:?}", e),
}
Expand Down
7 changes: 6 additions & 1 deletion examples/stm32f4/src/bin/input_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ async fn main(spawner: Spawner) {
unwrap!(spawner.spawn(blinky(p.PB2)));

let ch3 = CapturePin::new_ch3(p.PB10, Pull::None);
let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default());
let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(10), Default::default());

let mut last_capture = Option::None;
loop {
info!("wait for risign edge");
ic.wait_for_rising_edge(Channel::Ch3).await;

let capture_value = ic.get_capture_value(Channel::Ch3);
info!("new capture! {}", capture_value);
if let Some(c) = last_capture {
info!("period: {}", (capture_value - c));
}
last_capture = Some(capture_value);
}
}
40 changes: 22 additions & 18 deletions examples/stm32f4/src/bin/usb_ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_net::tcp::TcpSocket;
use embassy_net::StackResources;
use embassy_net::{Stack, StackResources};
use embassy_stm32::rng::{self, Rng};
use embassy_stm32::time::Hertz;
use embassy_stm32::usb::Driver;
use embassy_stm32::{bind_interrupts, peripherals, usb, Config};
use embassy_time::Timer;
use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState};
use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
use embassy_usb::{Builder, UsbDevice};
use embedded_io_async::Write;
use heapless::Vec;
use static_cell::StaticCell;
use {defmt_rtt as _, panic_probe as _};

Expand All @@ -37,7 +39,7 @@ async fn net_task(mut runner: embassy_net::Runner<'static, Device<'static, MTU>>

bind_interrupts!(struct Irqs {
OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
HASH_RNG => rng::InterruptHandler<peripherals::RNG>;
//HASH_RNG => rng::InterruptHandler<peripherals::RNG>;
});

// If you are trying this and your USB device doesn't connect, the most
Expand All @@ -53,20 +55,20 @@ async fn main(spawner: Spawner) {
{
use embassy_stm32::rcc::*;
config.rcc.hse = Some(Hse {
freq: Hertz(8_000_000),
mode: HseMode::Bypass,
freq: Hertz(25_000_000),
mode: HseMode::Oscillator,
});
config.rcc.pll_src = PllSource::HSE;
config.rcc.pll = Some(Pll {
prediv: PllPreDiv::DIV4,
mul: PllMul::MUL168,
divp: Some(PllPDiv::DIV2), // 8mhz / 4 * 168 / 2 = 168Mhz.
divq: Some(PllQDiv::DIV7), // 8mhz / 4 * 168 / 7 = 48Mhz.
prediv: PllPreDiv::DIV25,
mul: PllMul::MUL192,
divp: Some(PllPDiv::DIV2), // 25mhz / 25 * 192 / 2 = 96Mhz.
divq: Some(PllQDiv::DIV4), // 25mhz / 25 * 192 / 4 = 48Mhz.
divr: None,
});
config.rcc.ahb_pre = AHBPrescaler::DIV1;
config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.apb1_pre = APBPrescaler::DIV2;
config.rcc.apb2_pre = APBPrescaler::DIV1;
config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
}
Expand Down Expand Up @@ -126,21 +128,23 @@ async fn main(spawner: Spawner) {

unwrap!(spawner.spawn(usb_task(usb)));

Timer::after_millis(1000).await;

static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new();
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr);
unwrap!(spawner.spawn(usb_ncm_task(runner)));

let config = embassy_net::Config::dhcpv4(Default::default());
//let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
// dns_servers: Vec::new(),
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
//});
//let config = embassy_net::Config::dhcpv4(Default::default());
let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
dns_servers: Vec::new(),
gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
});

// Generate random seed
let mut rng = Rng::new(p.RNG, Irqs);
//let mut rng = Rng::new(p.RNG, Irqs);
let mut seed = [0; 8];
unwrap!(rng.async_fill_bytes(&mut seed).await);
//unwrap!(rng.async_fill_bytes(&mut seed).await);
let seed = u64::from_le_bytes(seed);

// Init network stack
Expand Down
18 changes: 10 additions & 8 deletions examples/stm32f4/src/bin/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ async fn main(_spawner: Spawner) {
{
use embassy_stm32::rcc::*;
config.rcc.hse = Some(Hse {
freq: Hertz(8_000_000),
mode: HseMode::Bypass,
freq: Hertz(25_000_000),
mode: HseMode::Oscillator,
});
config.rcc.pll_src = PllSource::HSE;
config.rcc.pll = Some(Pll {
prediv: PllPreDiv::DIV4,
mul: PllMul::MUL168,
divp: Some(PllPDiv::DIV2), // 8mhz / 4 * 168 / 2 = 168Mhz.
divq: Some(PllQDiv::DIV7), // 8mhz / 4 * 168 / 7 = 48Mhz.
prediv: PllPreDiv::DIV25,
mul: PllMul::MUL192,
divp: Some(PllPDiv::DIV2), // 25mhz / 25 * 192 / 2 = 96Mhz.
divq: Some(PllQDiv::DIV4), // 25mhz / 25 * 192 / 4 = 48Mhz.
divr: None,
});
config.rcc.ahb_pre = AHBPrescaler::DIV1;
config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.apb1_pre = APBPrescaler::DIV2;
config.rcc.apb2_pre = APBPrescaler::DIV1;
config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
}
Expand Down Expand Up @@ -99,6 +99,8 @@ async fn main(_spawner: Spawner) {
// Run the USB device.
let usb_fut = usb.run();

info!("USB config finished");

// Do stuff with the class!
let echo_fut = async {
loop {
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32g4/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# replace STM32G071C8Rx with your chip as listed in `probe-rs chip list`
runner = "probe-rs run --chip STM32G484VETx"
runner = "probe-rs run --chip STM32G431CBUx --connect-under-reset"

[build]
target = "thumbv7em-none-eabi"
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32g4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
# Change stm32g491re to your chip name, if necessary.
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "time-driver-any", "stm32g431cb", "memory-x", "unstable-pac", "exti"] }
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-time = { version = "0.3.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
Expand Down
34 changes: 30 additions & 4 deletions examples/stm32g4/src/bin/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,48 @@ use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::Timer;
use embassy_stm32::time::Hertz;
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
//let p = embassy_stm32::init(Default::default());
let mut config = embassy_stm32::Config::default();
{
use embassy_stm32::rcc::*;
// Sets up the Clock Recovery System (CRS) to use the USB SOF to trim the HSI48 oscillator.
config.rcc.hsi48 = Some(Hsi48Config {
sync_from_usb: true,
});
config.rcc.hse = Some(Hse {
freq: Hertz(8_000_000),
mode: HseMode::Oscillator,
});
config.rcc.pll = Some(Pll {
source: PllSource::HSE,
prediv: PllPreDiv::DIV2,
mul: PllMul::MUL72,
divp: None,
divq: Some(PllQDiv::DIV6), // 48mhz
divr: Some(PllRDiv::DIV2), // Main system clock at 144 MHz
});
config.rcc.sys = Sysclk::PLL1_R;
config.rcc.boost = true; // BOOST!
config.rcc.mux.clk48sel = mux::Clk48sel::HSI48;
//config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q; // uncomment to use PLL1_Q instead.
}
let p = embassy_stm32::init(config);
info!("Hello World!");

let mut led = Output::new(p.PA5, Level::High, Speed::Low);
let mut led = Output::new(p.PC6, Level::High, Speed::Low);

loop {
info!("high");
led.set_high();
Timer::after_millis(300).await;
Timer::after_millis(1000).await;

info!("low");
led.set_low();
Timer::after_millis(300).await;
Timer::after_millis(1000).await;
}
}
2 changes: 2 additions & 0 deletions examples/stm32h7/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[target.thumbv7em-none-eabihf]
runner = 'probe-rs run --chip STM32H743ZITx'

# dfu-util -a 0 -d 2341:035b -s 0x08040000 -D *.bin

[build]
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)

Expand Down
2 changes: 1 addition & 1 deletion examples/stm32h7/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
# Change stm32h743bi to your chip name, if necessary.
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h743bi", "time-driver-tim2", "exti", "memory-x", "unstable-pac", "chrono"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h747xi-cm7", "time-driver-tim2", "exti", "memory-x", "unstable-pac", "chrono"] }
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
embassy-embedded-hal = { version = "0.2.0", path = "../../embassy-embedded-hal" }
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32h7/memory.x
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 2048K /* BANK_1 + BANK_2 */
FLASH : ORIGIN = 0x08040000, LENGTH = 2048K /* BANK_1 + BANK_2 */
RAM : ORIGIN = 0x24000000, LENGTH = 512K /* SRAM */
RAM_D3 : ORIGIN = 0x38000000, LENGTH = 64K /* SRAM4 */
}
Expand Down
Loading

0 comments on commit af69d31

Please sign in to comment.