Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash changes #104

Closed
wants to merge 10 commits into from
Closed

Flash changes #104

wants to merge 10 commits into from

Conversation

usbalbin
Copy link
Contributor

@usbalbin usbalbin commented Dec 17, 2023

(This PR contains too many unrelated commits, will clean that up) - Done

Noticed some weird things when trying to use the flash on a nucleo-g474. Some of it related to dual bank but not not all of it...

At some point i got the feeling that reading during the verify-thing in page_erase and write gave weird values back as if there were some race condition or maybe wrong data width or something... Will try to find the problem.

pll_config.mux = stm32g4xx_hal::rcc::PLLSrc::HSI; // 16MHz
pll_config.n = stm32g4xx_hal::rcc::PllNMul::MUL_32;
pll_config.m = stm32g4xx_hal::rcc::PllMDiv::DIV_2; // f(vco) = 16MHz*32/2 = 256MHz
pll_config.r = Some(stm32g4xx_hal::rcc::PllRDiv::DIV_2); // f(sysclock) = 256MHz/2 = 128MHz
Copy link
Contributor Author

@usbalbin usbalbin Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong but the clock setup is not really needed for this example, right? Thought I'd remove all but the essentials to give more focus on the flash related things

flash.acr.modify(|_, w| {
w.latency().bits(0b1000) // 8 wait states
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with the custom clock setup above, this should not really be needed, right? This should be done automatically here when setting the clock settings. However by my math, the auto-thing would set it to 4 wait states for a f_sys of 128MHz. Does it for some reason need to be 8, or is that incorrect?

@@ -48,21 +47,22 @@ pub enum FlashSize {
Sz1M = 1024,
}
impl FlashSize {
const fn kbytes(self) -> u32 {
const fn bytes(self) -> u32 {
Copy link
Contributor Author

@usbalbin usbalbin Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to bytes since, from what I can tell really returns a value in units of bytes

SZ_1K * self as u32
}
}

pub struct FlashWriter<'a, const SECTOR_SZ_KB: u32> {
pub struct FlashWriter<'a, const SECTOR_SIZE: u32> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@usbalbin
Copy link
Contributor Author

I just had a sneak peak at stm32h7xx-hal which puts memory fences in the program function to prevent the compiler from doing bad things. That is likely the way to actually solve the problem.

@usbalbin
Copy link
Contributor Author

usbalbin commented Aug 1, 2024

I will try to re-visit this at a later time

@usbalbin usbalbin closed this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant