Triggering the dfu bootloader works
This commit is contained in:
parent
9cfc02340b
commit
72bf0d8793
7 changed files with 137 additions and 36 deletions
73
Cargo.lock
generated
73
Cargo.lock
generated
|
|
@ -1118,6 +1118,15 @@ dependencies = [
|
||||||
"nom",
|
"nom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nu-ansi-term"
|
||||||
|
version = "0.50.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num"
|
name = "num"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
|
@ -1395,6 +1404,8 @@ dependencies = [
|
||||||
"tokio-serial",
|
"tokio-serial",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower-http",
|
"tower-http",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -1641,6 +1652,15 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sharded-slab"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|
@ -1821,6 +1841,15 @@ dependencies = [
|
||||||
"syn 2.0.111",
|
"syn 2.0.111",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thread_local"
|
||||||
|
version = "1.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.44"
|
version = "0.3.44"
|
||||||
|
|
@ -1959,9 +1988,21 @@ checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"tracing-attributes",
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-attributes"
|
||||||
|
version = "0.1.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.111",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-core"
|
name = "tracing-core"
|
||||||
version = "0.1.36"
|
version = "0.1.36"
|
||||||
|
|
@ -1969,6 +2010,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"valuable",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-log"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-subscriber"
|
||||||
|
version = "0.3.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
|
||||||
|
dependencies = [
|
||||||
|
"nu-ansi-term",
|
||||||
|
"sharded-slab",
|
||||||
|
"smallvec",
|
||||||
|
"thread_local",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2059,6 +2126,12 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "valuable"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcell"
|
name = "vcell"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@ serde_json = "1.0.118"
|
||||||
serialport = "4.5.1"
|
serialport = "4.5.1"
|
||||||
tokio = {version = "1.37.0", features = ["full"]}
|
tokio = {version = "1.37.0", features = ["full"]}
|
||||||
tower-http = { version = "0.6.8", features = ["fs", "trace"] }
|
tower-http = { version = "0.6.8", features = ["fs", "trace"] }
|
||||||
radomctl-protocol = { path = "../protocol" }
|
|
||||||
postcard = {version = "1.0.10", features = ["use-std"]}
|
|
||||||
dfu-libusb = "0.5.5"
|
dfu-libusb = "0.5.5"
|
||||||
rusb = "0.9"
|
rusb = "0.9"
|
||||||
clap = { version = "4.5.19", features = ["derive"] }
|
clap = { version = "4.5.19", features = ["derive"] }
|
||||||
|
|
@ -25,3 +23,8 @@ tokio-util = { version = "0.7.13", features = ["codec", "rt"] }
|
||||||
bytes = "1.9.0"
|
bytes = "1.9.0"
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
nom-language = "0.1.0"
|
nom-language = "0.1.0"
|
||||||
|
tracing = "0.1.40"
|
||||||
|
tracing-subscriber = "0.3.18"
|
||||||
|
radomctl-protocol = { path = "../protocol" }
|
||||||
|
postcard = {version = "1.0.10", features = ["use-std"]}
|
||||||
|
|
||||||
|
|
|
||||||
16
daemon/src/bin/trigger-dfu.rs
Normal file
16
daemon/src/bin/trigger-dfu.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use postcard::{from_bytes_cobs, to_stdvec_cobs};
|
||||||
|
use radomctl_protocol::*;
|
||||||
|
use radomctld::logger::setup_logger;
|
||||||
|
|
||||||
|
pub fn main() -> () {
|
||||||
|
let mut port = serialport::new("/dev/ttyACM0", 115_200)
|
||||||
|
.timeout(Duration::from_millis(10))
|
||||||
|
.open()
|
||||||
|
.expect("Failed to open port");
|
||||||
|
|
||||||
|
let host_msg = HostMessage::TriggerDFUBootloader;
|
||||||
|
let msg_bytes = to_stdvec_cobs(&host_msg).unwrap();
|
||||||
|
port.write_all(&msg_bytes).unwrap();
|
||||||
|
}
|
||||||
|
|
@ -12,13 +12,17 @@ use tokio::{
|
||||||
task::JoinSet,
|
task::JoinSet,
|
||||||
};
|
};
|
||||||
use tokio_serial;
|
use tokio_serial;
|
||||||
use tower_http::{services::ServeFile, trace::TraceLayer};
|
|
||||||
|
|
||||||
use radomctld::{
|
use radomctld::{
|
||||||
logger::setup_logger,
|
logger::setup_logger,
|
||||||
rotctlprotocol::{parse_command, Command},
|
rotctlprotocol::{parse_command, Command},
|
||||||
rotor::control_rotor,
|
rotor::control_rotor,
|
||||||
};
|
};
|
||||||
|
use tower_http::{
|
||||||
|
services::{ServeDir, ServeFile},
|
||||||
|
trace::TraceLayer,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
async fn process_socket(
|
async fn process_socket(
|
||||||
socket: TcpStream,
|
socket: TcpStream,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
|
use core::ptr::addr_of_mut;
|
||||||
use stm32f4xx_hal::pac;
|
use stm32f4xx_hal::pac;
|
||||||
|
|
||||||
fn jump_to_bootloader() {
|
fn jump_to_bootloader() {
|
||||||
|
|
@ -23,19 +23,25 @@ fn jump_to_bootloader() {
|
||||||
|
|
||||||
const BOOTLOADER_REQUESTED: u32 = 0xdecafbad;
|
const BOOTLOADER_REQUESTED: u32 = 0xdecafbad;
|
||||||
|
|
||||||
#[link_section = ".uninit.DFU_FLAG"]
|
fn magic_mut_ptr() -> *mut u32 {
|
||||||
static mut DFU_FLAG: MaybeUninit<u32> = MaybeUninit::uninit();
|
extern "C" {
|
||||||
|
#[link_name = "_dfu_magic"]
|
||||||
|
static mut magic: u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe { addr_of_mut!(magic) }
|
||||||
|
}
|
||||||
|
|
||||||
fn get_bootloader_flag() -> u32 {
|
fn get_bootloader_flag() -> u32 {
|
||||||
unsafe { DFU_FLAG.assume_init() }
|
unsafe { magic_mut_ptr().read_volatile() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_bootloader_flag() {
|
fn set_bootloader_flag() {
|
||||||
unsafe { DFU_FLAG.write(BOOTLOADER_REQUESTED) };
|
unsafe { magic_mut_ptr().write_volatile(BOOTLOADER_REQUESTED) };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_bootloader_flag() {
|
fn clear_bootloader_flag() {
|
||||||
unsafe { DFU_FLAG.write(0) };
|
unsafe { magic_mut_ptr().write_volatile(BOOTLOADER_REQUESTED) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,15 @@ mod app {
|
||||||
|
|
||||||
use as5048a::AS5048A;
|
use as5048a::AS5048A;
|
||||||
|
|
||||||
|
use crate::bootloader;
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use heapless::{String, Vec};
|
use heapless::{String, Vec};
|
||||||
use num_traits::{Float, FloatConst};
|
use num_traits::{Float, FloatConst};
|
||||||
use postcard::{from_bytes_cobs, to_vec_cobs};
|
use postcard::{from_bytes_cobs, to_vec_cobs};
|
||||||
|
use qmc5883l::{self, QMC5883L};
|
||||||
|
use radomctl_protocol::*;
|
||||||
|
use radomctl_protocol::{HostMessage, *};
|
||||||
|
use rtic_monotonics::systick::prelude::*;
|
||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
gpio::{gpioa, gpiob, gpioc, Output, PushPull},
|
gpio::{gpioa, gpiob, gpioc, Output, PushPull},
|
||||||
i2c,
|
i2c,
|
||||||
|
|
@ -39,20 +44,9 @@ mod app {
|
||||||
use usb_device::prelude::*;
|
use usb_device::prelude::*;
|
||||||
use usb_device::{class_prelude::UsbBusAllocator, device};
|
use usb_device::{class_prelude::UsbBusAllocator, device};
|
||||||
use usbd_serial::SerialPort;
|
use usbd_serial::SerialPort;
|
||||||
|
|
||||||
use xca9548a::{SlaveAddr, Xca9548a};
|
use xca9548a::{SlaveAddr, Xca9548a};
|
||||||
|
|
||||||
use qmc5883l::{self, QMC5883L};
|
systick_monotonic!(Mono, 1000);
|
||||||
|
|
||||||
use radomctl_protocol::{HostMessage, *};
|
|
||||||
|
|
||||||
use crate::bootloader;
|
|
||||||
|
|
||||||
use radomctl_protocol::*;
|
|
||||||
|
|
||||||
use rtic_monotonics::systick::prelude::*;
|
|
||||||
|
|
||||||
systick_monotonic!(Mono, 4000);
|
|
||||||
|
|
||||||
const USB_BUFFER_SIZE: usize = 64;
|
const USB_BUFFER_SIZE: usize = 64;
|
||||||
|
|
||||||
|
|
@ -104,6 +98,8 @@ mod app {
|
||||||
|
|
||||||
Mono::start(cx.core.SYST, rcc.clocks.sysclk().to_Hz());
|
Mono::start(cx.core.SYST, rcc.clocks.sysclk().to_Hz());
|
||||||
|
|
||||||
|
defmt::info!("Clock Setup done");
|
||||||
|
|
||||||
// Acquire the GPIO peripherials
|
// Acquire the GPIO peripherials
|
||||||
let gpioa = cx.device.GPIOA.split(&mut rcc);
|
let gpioa = cx.device.GPIOA.split(&mut rcc);
|
||||||
let gpiob = cx.device.GPIOB.split(&mut rcc);
|
let gpiob = cx.device.GPIOB.split(&mut rcc);
|
||||||
|
|
@ -132,22 +128,11 @@ mod app {
|
||||||
|
|
||||||
let usb_serial = usbd_serial::SerialPort::new(unsafe { USB_BUS.as_ref().unwrap() });
|
let usb_serial = usbd_serial::SerialPort::new(unsafe { USB_BUS.as_ref().unwrap() });
|
||||||
|
|
||||||
let serial = unsafe {
|
let uid = signature::Uid::get();
|
||||||
let u_id0 = 0x1FFF_7A10 as *const u32;
|
|
||||||
let u_id2 = 0x1FFF_7A18 as *const u32;
|
|
||||||
|
|
||||||
defmt::debug!("UID0: {:x}", u_id0.read());
|
|
||||||
defmt::debug!("UID2: {:x}", u_id2.read());
|
|
||||||
|
|
||||||
// See https://community.st.com/t5/stm32-mcus-products/usb-bootloader-serial-number/td-p/432148
|
|
||||||
(u_id0.read() as u64 + u_id2.read() as u64) << 16
|
|
||||||
| (u_id2.read() as u64 & 0xFF00) >> 8
|
|
||||||
| (u_id2.read() as u64 & 0x00FF) << 8
|
|
||||||
};
|
|
||||||
|
|
||||||
static mut SERIAL: String<16> = String::new();
|
static mut SERIAL: String<16> = String::new();
|
||||||
unsafe {
|
unsafe {
|
||||||
write!(SERIAL, "{:X}", serial).unwrap();
|
write!(SERIAL, "{}{:x}{:x}", uid.lot_num(), uid.x(), uid.y()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let usb_dev = unsafe {
|
let usb_dev = unsafe {
|
||||||
|
|
@ -177,7 +162,7 @@ mod app {
|
||||||
defmt::info!("I2C Setup done");
|
defmt::info!("I2C Setup done");
|
||||||
|
|
||||||
let mut i2cmux = Xca9548a::new(i2c, SlaveAddr::default());
|
let mut i2cmux = Xca9548a::new(i2c, SlaveAddr::default());
|
||||||
i2cmux.select_channels(0b0000_0001).unwrap();
|
//i2cmux.select_channels(0b0000_0001).unwrap();
|
||||||
|
|
||||||
defmt::info!("I2C MUX Setup done");
|
defmt::info!("I2C MUX Setup done");
|
||||||
|
|
||||||
|
|
|
||||||
16
memory.x
16
memory.x
|
|
@ -1,9 +1,23 @@
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
||||||
RAM : ORIGIN = 0x20000000, LENGTH = 64K
|
UNINIT : ORIGIN = 0x20000000, LENGTH = 0x10
|
||||||
|
RAM : ORIGIN = 0x20000010, LENGTH = 64K - LENGTH(UNINIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTIONS {
|
||||||
|
.uninit_flags (NOLOAD) : ALIGN(4)
|
||||||
|
{
|
||||||
|
. = ALIGN(4);
|
||||||
|
__suninit_flags = .;
|
||||||
|
_dfu_magic = .; . += 4;
|
||||||
|
*(.uninit_flags .uninit_flags.*)
|
||||||
|
. = ALIGN(4);
|
||||||
|
__euninit_flags = .;
|
||||||
|
} > UNINIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This is where the call stack will be allocated. */
|
/* This is where the call stack will be allocated. */
|
||||||
/* The stack is of the full descending type. */
|
/* The stack is of the full descending type. */
|
||||||
/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
|
/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue