stm32f4xx-hal
stm32f4xx-hal copied to clipboard
Basic SDRAM FMC driver
Title says it all. This is a basic driver allowing one to use the FMC peripheral to drive an SDRAM module which can then be accessed directly in the memory space of the MCU. It /should/ work on F427, F429, F437, and F439 devices. However, I only have a STM32F429I-Discovery board to test it against. Mostly ported from the STM32 HAL/LL libraries. Included is a simple RAM test in examples/ targeting the STM32F429I-Discovery board
It'd be nice if this could be expanded to support NOR/PSRAM and all the other goodies that the FMC offers, but I don't have any hardware to test it with. I believe the 429I-EVAL includes a NOR Flash and SDRAM on a single bus, so that may be interesting to ultimately target.
One particular divergence from the usual patterns in this module is that we Peripherals::steal() to get access to the GPIOs to set up their AF/Speed/Pullup. This is mainly due to the sheer number of pins that would otherwise have to be passed by the user, which seemed inconvenient at best. The majority of the FMC pins aren't swappable, so it made the most sense ergonomically to just manipulate them directly using steal(). The few pins which /are/ swappable (and whose usage of swapping affects behavior) are captured in the type system.
Thanks for the PR. I was planning to add FSMC support at some point and since they're very similar we should probably try to add them in one go and in a consolidated way.
I need to look at your proposal at more detail but I'll add a few things I've noticed right away.
Thanks for taking a look at this and giving valuable feedback! I've replied to a few of these with my motivations/thought process, and will fix the remainder later tonight. Happy to keep discussing and refining this until its something everyone's OK with! I originally wanted to kickstart a discussion of how an FMC API would work as an issue, but it seemed more fruitful to start with an MVP and refine it with something that can be tested for ergonomics and functionality -- hence the PR.
@iostat I absolutely prefer the MVP approach!
I've started a crate to provide FMC/FSMC drivers that can be used for all the stm32 parts. It currently only supports some F7, some H7, and F469/F479, and also only has SDRAM support so far.
Would you be interested in combining this PR into the crate? I think some of the tasks would be:
- Looking at the register defintions and deciding if they apply to F427/F429/F437/F439, otherwise creating another file.
- Creating a memory device definition for the SDRAM on the STM32F429I-Discovery
- Adding anything else that's needed to the stm32-fmc crate
- Finally creating an implementation here in the F4 HAL
Let me know your thoughts. I will be adding more support for the H7, but happy to help here as well.