mciantyre / teensy4-rs

Rust support for the Teensy 4
Apache License 2.0
271 stars 31 forks source link

EEPROM #100

Open karniv00l opened 3 years ago

karniv00l commented 3 years ago

Hi there, thanks for all the great work!

I can't seem to find any information about reading and writing from / to EEPROM. Is this something that is on the roadmap, or am I looking in the wrong place?

Thanks

mciantyre commented 3 years ago

Thanks for checking out the project. There's no EEPROM emulation in today's BSP. You're the first to ask about it, and there hasn't been a plan to add it until someone would use it.

I'm happy to mentor you or anyone in contributing a FlexSPI driver, and EEPROM emulation based on that driver.

karniv00l commented 3 years ago

Unfortunately I have very little experience with embedded world and with Rust, although I am interested in how one would go about developing such a functionality.

I believe this is implemented here: https://github.com/PaulStoffregen/cores/blob/master/teensy4/eeprom.c and this should be used as a reference while porting?


I came across this library while researching components for a future hobby project that can be written in Rust. I think Teensy is a great platform and having good tooling and libraries is essential.

I hope I can help in some way.

mciantyre commented 3 years ago

Yup, the EEPROM module may be a good reference implementation. We'll notice that we're using the FlexSPI peripheral throughout that code to emulate EEPROM memory. The i.MX RT reference manual describes how the peripheral works. Rather than using macros for registers, we could use the imxrt-ral crate, which already exports the FlexSPI registers.

If you want something working quickly, it might be easier to integrate the EEPROM code directly into the BSP, then create a Rust wrapper around the C code. c0f1fcdae2 shows what that might look like.

dstric-aqueduct commented 1 year ago

Hi all - I attempted to modify Ian's proto/eeprom branch to add support for the Teensy 4.1.

You can see my updates here: https://github.com/dstric-aqueduct/teensy4-rs/tree/proto/eeprom

The steps taken were:

  1. Modify the bin/eeprom.c file to include board specific memory offsets and sizes.
  2. Modify the Makefile bin/Makefile to include board specific CPPFLAG options for compiling. The resulting library .a files are located in bin/.
  3. Modify the /teensy4-fcb/src/lib.rs to change the flash_size (see bootdata.c).
  4. Add a feature flag (t41) for board specific building using two new linker files.

Building for both boards is successful, but data written to the Teensy 4.1 does not persist between power cycles. I'm wondering if anyone can spot my error?