Skip to content

Commit

Permalink
boards: rpi: remove naked_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Jan 18, 2024
1 parent 0628a5e commit 0a0e830
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 61 deletions.
45 changes: 24 additions & 21 deletions boards/nano_rp2040_connect/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
// https://github.com/rust-lang/rust/issues/62184.
#![cfg_attr(not(doc), no_main)]
#![deny(missing_docs)]
#![feature(naked_functions)]

use core::arch::asm;
use core::arch::global_asm;

use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
use components::gpio::GpioComponent;
Expand Down Expand Up @@ -152,31 +151,35 @@ impl KernelResources<Rp2040<'static, Rp2040DefaultPeripherals<'static>>> for Nan
}
}

/// Entry point used for debuger
///
/// When loaded using gdb, the Arduino Nano RP2040 Connect is not reset
/// by default. Without this function, gdb sets the PC to the
/// beginning of the flash. This is not correct, as the RP2040
/// has a more complex boot process.
///
/// This function is set to be the entry point for gdb and is used
/// to send the RP2040 back in the bootloader so that all the boot
/// sqeuence is performed.
#[no_mangle]
#[naked]
pub unsafe extern "C" fn jump_to_bootloader() {
asm!(
"
#[allow(dead_code)]
extern "C" {
/// Entry point used for debugger
///
/// When loaded using gdb, the Arduino Nano RP2040 Connect is not reset
/// by default. Without this function, gdb sets the PC to the
/// beginning of the flash. This is not correct, as the RP2040
/// has a more complex boot process.
///
/// This function is set to be the entry point for gdb and is used
/// to send the RP2040 back in the bootloader so that all the boot
/// sequence is performed.
fn jump_to_bootloader();
}

global_asm!(
"
.section .jump_to_bootloader, \"ax\"
.global jump_to_bootloader
.thumb_func
jump_to_bootloader:
movs r0, #0
ldr r1, =(0xe0000000 + 0x0000ed08)
str r0, [r1]
ldmia r0!, {{r1, r2}}
msr msp, r1
bx r2
",
options(noreturn)
);
}
"
);

fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
// Start tick in watchdog
Expand Down
44 changes: 24 additions & 20 deletions boards/pico_explorer_base/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![deny(missing_docs)]
#![feature(naked_functions)]

use core::arch::asm;
use core::arch::global_asm;

use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
use components::gpio::GpioComponent;
Expand Down Expand Up @@ -162,31 +162,35 @@ impl KernelResources<Rp2040<'static, Rp2040DefaultPeripherals<'static>>> for Pic
}
}

/// Entry point used for debuger
///
/// When loaded using gdb, the Raspberry Pi Pico is not reset
/// by default. Without this function, gdb sets the PC to the
/// beginning of the flash. This is not correct, as the RP2040
/// has a more complex boot process.
///
/// This function is set to be the entry point for gdb and is used
/// to send the RP2040 back in the bootloader so that all the boot
/// sqeuence is performed.
#[no_mangle]
#[naked]
pub unsafe extern "C" fn jump_to_bootloader() {
asm!(
"
#[allow(dead_code)]
extern "C" {
/// Entry point used for debugger
///
/// When loaded using gdb, the Raspberry Pi Pico is not reset
/// by default. Without this function, gdb sets the PC to the
/// beginning of the flash. This is not correct, as the RP2040
/// has a more complex boot process.
///
/// This function is set to be the entry point for gdb and is used
/// to send the RP2040 back in the bootloader so that all the boot
/// sequence is performed.
fn jump_to_bootloader();
}

global_asm!(
"
.section .jump_to_bootloader, \"ax\"
.global jump_to_bootloader
.thumb_func
jump_to_bootloader:
movs r0, #0
ldr r1, =(0xe0000000 + 0x0000ed08)
str r0, [r1]
ldmia r0!, {{r1, r2}}
msr msp, r1
bx r2
",
options(noreturn)
);
}
"
);

fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
// Start tick in watchdog
Expand Down
44 changes: 24 additions & 20 deletions boards/raspberry_pi_pico/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![deny(missing_docs)]
#![feature(naked_functions)]

use core::arch::asm;
use core::arch::global_asm;

use capsules_core::i2c_master::I2CMasterDriver;
use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
Expand Down Expand Up @@ -153,31 +153,35 @@ impl KernelResources<Rp2040<'static, Rp2040DefaultPeripherals<'static>>> for Ras
}
}

/// Entry point used for debugger
///
/// When loaded using gdb, the Raspberry Pi Pico is not reset
/// by default. Without this function, gdb sets the PC to the
/// beginning of the flash. This is not correct, as the RP2040
/// has a more complex boot process.
///
/// This function is set to be the entry point for gdb and is used
/// to send the RP2040 back in the bootloader so that all the boot
/// sequence is performed.
#[no_mangle]
#[naked]
pub unsafe extern "C" fn jump_to_bootloader() {
asm!(
"
#[allow(dead_code)]
extern "C" {
/// Entry point used for debugger
///
/// When loaded using gdb, the Raspberry Pi Pico is not reset
/// by default. Without this function, gdb sets the PC to the
/// beginning of the flash. This is not correct, as the RP2040
/// has a more complex boot process.
///
/// This function is set to be the entry point for gdb and is used
/// to send the RP2040 back in the bootloader so that all the boot
/// sequence is performed.
fn jump_to_bootloader();
}

global_asm!(
"
.section .jump_to_bootloader, \"ax\"
.global jump_to_bootloader
.thumb_func
jump_to_bootloader:
movs r0, #0
ldr r1, =(0xe0000000 + 0x0000ed08)
str r0, [r1]
ldmia r0!, {{r1, r2}}
msr msp, r1
bx r2
",
options(noreturn)
);
}
"
);

fn init_clocks(peripherals: &Rp2040DefaultPeripherals) {
// Start tick in watchdog
Expand Down

0 comments on commit 0a0e830

Please sign in to comment.