Merge pull request #296 from xoviat/rcc

rcc: fix data mutability
This commit is contained in:
xoviat 2023-10-20 02:09:45 +00:00 committed by GitHub
commit 8a501c0438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -2267,7 +2267,7 @@ enum/SW:
- name: HSE
description: HSE selected as system clock
value: 2
- name: PLL1_P
- name: PLL1_R
description: PLL selected as system clock
value: 3
enum/SWPMI1SEL:

View File

@ -1,3 +1,4 @@
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use anyhow::{anyhow, Ok};
@ -256,7 +257,24 @@ impl PeripheralToClock {
mux,
};
family_clocks.insert(peri.to_string(), res);
match family_clocks.entry(peri.to_string()) {
Entry::Vacant(e) => {
e.insert(res);
}
Entry::Occupied(mut e) => {
if (e.get().clock != "pclk1" || e.get().clock != "hclk1")
&& (res.clock == "pclk1" || res.clock == "hclk1")
{
e.insert(res);
} else if !(e.get().clock == "pclk1" || e.get().clock == "hclk1") {
return Err(anyhow!(
"rcc: duplicate entry for peri {} for rcc_{}",
peri.to_string(),
rcc_name
));
}
}
}
}
}
}