Skip to content
Snippets Groups Projects
Commit 692f7fa6 authored by Samuel Tardieu's avatar Samuel Tardieu
Browse files

Add chip identification at boot time

parent fd842936
No related branches found
No related tags found
No related merge requests found
use embassy_stm32::pac;
pub fn identify() {
let dbgmcu = pac::DBGMCU.idcode().read();
let (density, rev) = match (dbgmcu.dev_id(), dbgmcu.rev_id()) {
(0x412, 0x1000) => ("low-density", "A"),
(0x412, _) => ("low-density", "?"),
(0x410, 0x0000) => ("medium-density", "A"),
(0x410, 0x2000) => ("medium-density", "B"),
(0x410, 0x2001) => ("medium-density", "Z"),
(0x410, 0x2003) => ("medium-density", "1/2/3/X/Y"),
(0x414, 0x1000) => ("high-density", "1/A"),
(0x414, 0x1001) => ("high-density", "Z"),
(0x414, 0x1003) => ("high-density", "1/2/3/X/Y"),
(0x414, _) => ("high-density", "?"),
(0x430, 0x1000) => ("XL-density", "1/A"),
(0x430, _) => ("XL-density", "?"),
(0x418, 0x1000) => ("connectivity", "A"),
(0x418, 0x1001) => ("connectivity", "Z"),
(0x418, _) => ("connectivity", "?"),
(_, _) => ("?", "?"),
};
let flash_size = unsafe { *(0x1FFF_F7E0 as *const u16) };
defmt::info!(
"Device type: {}, revision: {} – flash size: {}kB",
density,
rev,
flash_size
);
let pid = 0xe00f_ffe0 as *const [u32; 3];
let pid = unsafe { *pid };
let used = pid[2] & 8 != 0;
let identity_code = ((pid[1] & 0xf0) >> 4) | ((pid[2] & 0x7) << 4);
let continuation_code = unsafe { *(0xe00f_ffd0 as *const u32) };
defmt::info!(
"used = {}, identity_code = {:#04x}, continuation_code = {:#04x}",
used,
identity_code,
continuation_code
);
}
...@@ -15,6 +15,7 @@ use embassy_stm32::{ ...@@ -15,6 +15,7 @@ use embassy_stm32::{
use panic_probe as _; use panic_probe as _;
pub mod blinker; pub mod blinker;
mod chip;
mod encoders; mod encoders;
mod logic; mod logic;
mod power; mod power;
...@@ -87,6 +88,8 @@ async fn main(spawner: Spawner) { ...@@ -87,6 +88,8 @@ async fn main(spawner: Spawner) {
defmt::Debug2Format(&reset_cause), defmt::Debug2Format(&reset_cause),
); );
chip::identify();
spawner spawner
.spawn(blinker::blink(p.PB15, blink_pattern(reset_cause))) .spawn(blinker::blink(p.PB15, blink_pattern(reset_cause)))
.unwrap(); .unwrap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment