<re_irc>
If we are using without delays, we are getting unpredictable results or just the code panics.
<re_irc>
<Abhishek Dhamale> Hello folks, I am a new bee with Rust on RP2040. Need insights while implementing the flash write/Erase function. We came across that calling ROM function needs delay to erase the flash, and to write the Flash. If we are using without delays, we are getting unpredictable results or just the code panics. Is there a way to use these ROM function without delay? unsafe { cortex_m::interrupt::free(|_cs| {...
<re_irc>
... rom_data::connect_internal_flash(); // asm::delay(8000000); delay.delay_ms(100); rom_data::flash_exit_xip(); // asm::delay(8000000); delay.delay_ms(100); rom_data::flash_range_erase(addr, SECTOR_SIZE, BLOCK_SIZE, SECTOR_ERASE); // asm::delay(8000000); delay.delay_ms(100); rom_data::flash_flush_cache(); // Get the XIP working again // asm::delay(8000000); delay.delay_ms(100); rom_data::flash_enter_cmd_xip(); // Start XIP back...
<re_irc>
... up // asm::delay(8000000); delay.delay_ms(100); }); }
<re_irc>
<dirbaio> is that code running from flash? it is disconnecting the flash XIP, so if it's running from flash it'll "suicide" itself
<re_irc>
Need insights while implementing the flash write/Erase function.
<re_irc>
<Abhishek Dhamale> Hello folks, I am a new bee with Rust on RP2040.
<re_irc>
If we are using without delays, we are getting unpredictable results or just the code panics.
<re_irc>
We came across that calling ROM function needs delay to erase the flash, and to write the Flash.
<re_irc>
<dirbaio> you need to run it from RAM, iirc with some "#[link_section = ..]"
<re_irc>
<dirbaio> and make sure it's not calling other functions that are still in flash
<re_irc>
<Abhishek Dhamale> yes I am using #[link_section = ".data.ram_func"]
<re_irc>
<dirbaio> if you're calling delay_ms or stuff from rom_data, they'll be in flash if the compiler decides to not inline them
<re_irc>
<dirbaio> you can mess with compiler flags, like enabling LTO, to try to get the compiler to inline everything
<re_irc>
<dirbaio> but it's still not guaranteed
<re_irc>
<dirbaio> the only really safe guaranteed way to do it is with "asm!()"
<re_irc>
<Anand Gedam> But while using asm!(), the code gets paniced!
<re_irc>
<dirbaio> if you reimplement everything in asm then it can't panic
<re_irc>
<dirbaio> * the above code
<re_irc>
<Abhishek Dhamale> are you referring to just delay or entire write function code in asm!() ?
<re_irc>
<dirbaio> the entire fn
<re_irc>
<dirbaio> the problem is
<re_irc>
<dirbaio> even if YOUR function is in RAM, you're calling other functions
<re_irc>
<dirbaio> and these OTHER functions might be in flash
<re_irc>
<dirbaio> like "delay_ms", or "rom_data::flash_flush_cache"
<re_irc>
<dirbaio> so you can't call other functions
<re_irc>
<dirbaio> you have to write everything in your function
<re_irc>
<Abhishek Dhamale> cant we use write and erase functions without delay?
<re_irc>
<dirbaio> if you write it in rust the compiler might still insert function calls to other stuff, like operators
<re_irc>
<dirbaio> (even then it'll likely work in rust)
<re_irc>
<dirbaio> but to be 100% guaranteed that doesn't call other functions, you have to write it in asm
<re_irc>
<dirbaio> yes, it should work without delays
<re_irc>
<Abhishek Dhamale> but when we used erase function without delays we get 0x00000000
<re_irc>
<dirbaio> it should work without delays _if you write correct code_
<re_irc>
<dirbaio> that code can call functions in flash, therefore it is _not correct_
<re_irc>
<Abhishek Dhamale> Can you give some reference code for writing and erasing flash .. we are using one example from this GitHub repo issue "https://github.com/rp-rs/rp-hal/issues/257"
<re_irc>
<dirbaio> the code there is incorrect, they're saying it randomly works or not depending on compiler flags in that very same issue
<re_irc>
<dirbaio> I'm pretty sure the only correct way to write it is with ASM
<re_irc>
<dirbaio> no one has done it, as far as I know
<re_irc>
<Abhishek Dhamale> Thanks for quick reply. we are targeting rust and implementing secure boot loader for rp2040 and we need these functions for write and erase partitions.
gsalazar has quit [Remote host closed the connection]
dne has quit [Remote host closed the connection]
dne has joined #rust-embedded
<re_irc>
<firefrommoonlight> Yooooo. Is there any advantage to Clion over PyCharm for embedded rust?
<re_irc>
<thejpster> Abhishek Dhamale: You can’t secure boot an RP2040 though.
Lumpio- has quit [Ping timeout: 272 seconds]
Lumpio- has joined #rust-embedded
<re_irc>
<Mehmet Ali> Hi all o/
<re_irc>
<Mehmet Ali> What do you use for time
<re_irc>
<Mehmet Ali> For, say keeping time sync with the RTC Timer
<re_irc>
<Mehmet Ali> And then converting to a datetime of a sort
<re_irc>
<Mehmet Ali> Leap days, years, what not all those issues
<re_irc>
<adamgreig> it has DateTime and can do useful calculations with it
<re_irc>
<Mehmet Ali> Thanks, that gives some confidence.
<re_irc>
<chemicstry> I've been using chrono in most of my projects, seems to work well too
<re_irc>
<adamgreig> I think modern chrono uses time internally? there was a while where time was unmaintained and chrono took the lead but when i last checked it seemed like time was a nice fit (and it's now back being maintained and such)
<re_irc>
<adamgreig> plain time was more lightweight perhaps
<re_irc>
<dirbaio> I've used chrono too, works great
<re_irc>
<dirbaio> except chrono-tz which is ~2mb of flash lol, had to roll my own
dc740 has joined #rust-embedded
<re_irc>
<Mehmet Ali> time requires std, it seems.
<re_irc>
<chemicstry> Mehmet Ali: you have to specify "default-features = false" in cargo.toml