-
Notifications
You must be signed in to change notification settings - Fork 1
Funny Monkey Coding (FMC) Time #131
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
Merged
Merged
Changes from 54 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
e97f649
added FMC.hpp and FMC.cpp, have not tested
oc6723 712e8b7
replaced private vars with structs stored in class
oc6723 3dd7cad
changed structs to pass by value instead of reference
oc6723 0160aa4
fixed CMakeLists.txt i think
oc6723 27cb4f1
renamed to FMCf4xx
oc6723 7258706
improved read and write functions to check bounds and enforce bit ali…
oc6723 8496802
created generic FMC interface
oc6723 2f47125
fixed compile bug
oc6723 2de2205
used getSdramBaseAddress() in FMC constructor
oc6723 d63112a
Merge branch 'main' into feature/ChongOscar/fmc-support
ChongOscar 565b9c4
Applied Formatting Changes During GitHub Build
cb91f45
removed unnecessary #defines in FMCf4xx.hpp and swapped pin typedefs …
oc6723 db7d9a4
made default init config functions so the definitions can be moved to…
oc6723 1646c19
Merge remote-tracking branch 'origin/feature/ChongOscar/fmc-support' …
oc6723 ab4bfc3
removed duplicate namespace declaration
oc6723 f9d0ced
Applied Formatting Changes During GitHub Build
4f2798f
added back sdramMemoryAddress as public void* but init looks ugly
oc6723 01d8b29
Merge remote-tracking branch 'origin/feature/ChongOscar/fmc-support' …
oc6723 7ce4e85
why cant i push
oc6723 3498621
Applied Formatting Changes During GitHub Build
99cb57e
formatting changes
oc6723 a5c77d7
merged with github
oc6723 4f87078
Applied Formatting Changes During GitHub Build
6a996e6
moved everyting back to f4xx because sdram is not supported on te f3's
oc6723 7b558ad
Merge remote-tracking branch 'origin/feature/ChongOscar/fmc-support' …
oc6723 6823191
chaned clock frequency #defines to functions
ChongOscar 62e6fd6
split FMC and SDRAM into 3 classes, FMC being the base class, SDRAM i…
ChongOscar 1417f62
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato 4978d6f
Made throughout the file to make things slightly better. If anyone is…
DannyCato 41a27b5
Remove line that makes F302 always fail to build, so that samples can…
DannyCato ee5ab85
Compilation for every device now works and added specifier for F469 h…
DannyCato dfd49a1
Applied Formatting Changes During GitHub Build
9b7c071
Oops, accidentally had it so that SDRAM would never build. Adjusted i…
DannyCato 5a4bb81
Merge branch 'feature/ChongOscar/fmc-support' of github.com:RIT-EVT/E…
DannyCato e0e37b9
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato 84b4e15
Some changes made, but still need to make lots of progress
DannyCato 05f49bf
Changed how sending SDRAM Commands work to take in arguments instead …
DannyCato ae5ec73
Saw a lot of things that could be improved and tried to make those im…
DannyCato 3c0e255
Forgot to add Cmake
DannyCato 6dbc03f
Changed Function descriptions
DannyCato b3445a8
Remove old fmc.hpp include
DannyCato d1dced3
Applied Formatting Changes During GitHub Build
1c14237
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato 1c02890
SDRAM edits, everything is building
DannyCato 61ba5c4
Merge branch 'feature/ChongOscar/fmc-support' of github.com:RIT-EVT/E…
DannyCato 84a0fec
Applied Formatting Changes During GitHub Build
c1a5245
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato 649dd9a
Integrated into a working system using the HUDL projectgit add .
DannyCato 4f4f2d6
readded peripheral guards for SDRAM
DannyCato 7ade10f
Applied Formatting Changes During GitHub Build
4a62fab
Changed structure to add a new interface and make programmer facing c…
DannyCato e588483
Push more changes and fix CMake
DannyCato 4b63dc1
Fix missing project in CMake :/
DannyCato cb34552
Applied Formatting Changes During GitHub Build
257821a
Added comments and made some changed to how the NSToSDRAMClockCycles …
DannyCato b41579f
Fixing SDRAM to use input config
DannyCato 7900a3f
Applied Formatting Changes During GitHub Build
43140da
repush to ensure it works
DannyCato 512a827
Merge branch 'feature/ChongOscar/fmc-support' of https://github.com/R…
DannyCato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| #ifndef EVT_SDRAM_HPP | ||
| #define EVT_SDRAM_HPP | ||
| #include <core/io/pin.hpp> | ||
|
|
||
| #ifdef STM32F4xx | ||
| #include <HALf4/stm32f4xx_hal.h> | ||
|
|
||
| namespace core::io { | ||
| class SDRAMDevice; | ||
| /** | ||
| * Interface for configuring and accessing external SDRAM. | ||
| * Provides clock frequency functions | ||
| */ | ||
| class SDRAM { | ||
| public: | ||
| /** | ||
| * Represents the status of operation of the SDRAM | ||
| * | ||
| * This can be used to represent the overall state of the SDRAM | ||
| */ | ||
| enum class Status { | ||
| OK = 0x00U, | ||
| ERROR = 0x01U, | ||
| BUSY = 0x02U, | ||
| TIMEOUT = 0x03U, | ||
| }; | ||
|
|
||
| /** | ||
| * Target for when sending an SDRAM Command | ||
| */ | ||
| enum class SDRAMCommandTarget { | ||
| BANK1 = FMC_SDCMR_CTB1, | ||
| BANK2 = FMC_SDCMR_CTB2, | ||
| BOTH = FMC_SDCMR_CTB1 | FMC_SDCMR_CTB2, | ||
| }; | ||
|
|
||
| /** | ||
| * SDRAM Command modes for initialization and state change | ||
| */ | ||
| enum class SDRAMCommand { | ||
| NORMAL = 0, | ||
| CLK_ENABLE = 1, | ||
| PRECHARGE_ALL = 2, | ||
| AUTO_REFRESH = 3, | ||
| SET_OPERATION = 4, | ||
| SELF_REFRESH = 5, | ||
| POWER_DOWN = 6, | ||
| }; | ||
|
|
||
| enum class SDRAMState { | ||
|
DannyCato marked this conversation as resolved.
|
||
| NORMAL_MODE = 0, | ||
| SELF_REFRESH_MODE, | ||
| POWER_DOWN_MODE | ||
| }; | ||
|
|
||
| enum class SDRAMBank { | ||
|
DannyCato marked this conversation as resolved.
Outdated
|
||
| BANK1 = 0, | ||
| BANK2 = 1 | ||
| }; | ||
|
|
||
| /** | ||
| * Holds all SDRAM controller settings that map directly to | ||
| * the HAL_SDRAM_Init configuration structure. | ||
| * | ||
| * Must be initialized before passing into the constructor | ||
| */ | ||
| struct SDRAMInitConfig { | ||
|
DannyCato marked this conversation as resolved.
|
||
| uint32_t sdBank; | ||
| uint32_t columnBitsNumber; | ||
| uint32_t rowBitsNumber; | ||
| uint32_t memoryDataWidth; | ||
| uint32_t internalBankNumber; | ||
| uint32_t casLatency; | ||
| uint32_t writeProtection; | ||
| uint32_t sdClockPeriod; | ||
| uint32_t readBurst; | ||
| uint32_t readPipeDelay; | ||
| }; | ||
|
|
||
| /** | ||
| * Structure to simplify SDRAM timing initialization, contains all required SDRAM timing delays in clock cycles. | ||
| * | ||
| * Must be initialized before passing into the constructor | ||
| */ | ||
| struct SDRAMTimingConfig { | ||
| uint32_t loadToActiveDelay; | ||
| uint32_t exitSelfRefreshDelay; | ||
| uint32_t selfRefreshTime; | ||
| uint32_t rowCycleDelay; | ||
| uint32_t writeRecoveryTime; | ||
| uint32_t rpDelay; | ||
| uint32_t rcdDelay; | ||
| }; | ||
|
|
||
| struct SDRAMPinGroup { | ||
| Pin* pins; | ||
| uint8_t numPins; | ||
| }; | ||
|
|
||
| /** | ||
| * Constructor for initializing an SDRAM to control external SDRAM | ||
| * | ||
| * @param memoryAddress first address of SDRAM memory | ||
| * @param pins the pins for use by the SDRAM Controller | ||
| * @param initConfig HAL-level SDRAM parameters for how initialization works | ||
| * @param timingConfig HAL-level SDRAM parameters for properly orchestrating hardware timing | ||
| * @param device interface class with abstract function that is overridden with a specific implementation | ||
| */ | ||
| SDRAM(uint32_t* memoryAddress, SDRAMPinGroup& pins, const SDRAMInitConfig& initConfig, | ||
| const SDRAMTimingConfig& timingConfig, const SDRAMDevice& device); | ||
|
|
||
| /** | ||
| * Gets the Frequency of the SDRAM CLK | ||
| * | ||
|
DannyCato marked this conversation as resolved.
Outdated
|
||
| * @return the SDRAM clock frequency | ||
| */ | ||
| static uint32_t getSdramClockFrequency(); | ||
|
|
||
| /** | ||
| * Get how long one SDRAM Clock cycle is in picoseconds | ||
| * | ||
|
DannyCato marked this conversation as resolved.
Outdated
|
||
| * @return the SDRAM clock period in picoseconds | ||
| */ | ||
| static uint32_t getSdramClockPeriodPS(); | ||
|
|
||
| /** | ||
| * Transform a time given in nanoseconds into how many clock cycles fit in that range | ||
| * | ||
|
DannyCato marked this conversation as resolved.
Outdated
|
||
| * @return the SDRAM clock period in nanoseconds | ||
| */ | ||
| static uint32_t NSToSdramClockCycles(uint32_t nanoseconds); | ||
|
|
||
| /** | ||
| * Enable write protection for the sdram | ||
| * | ||
| * @return the result of attempting to enable the write protection | ||
| */ | ||
| virtual Status EnableWriteProtection() = 0; | ||
|
|
||
| /** | ||
| * Disable write protection for the sdram | ||
| * | ||
| * @return the result of attempting to disable the write protection | ||
| */ | ||
| virtual Status DisableWriteProtection() = 0; | ||
|
|
||
| /** | ||
| * @brief Send a command to the sdram | ||
| * | ||
| * @param type is the kind of the command to be sent, can be a value from enum SDRAM::Command | ||
| * @param target specifies which device to send the command to, can be a value from SDRAM::Bank | ||
| * @param refreshNumber defines the number of SDRAM clock cycles where the controller sends the auto refresh | ||
| * command (essentially a halted state where the SDRAM will ignore any requests), can be a value between 1 and 15 | ||
| * @param modeRegister defines how the SDRAM will operate when sending the SET_OPERATION command, ignored | ||
| * when sending any other command. The specific value to send depends on the datasheet usually | ||
| * under Mode Register Definition | ||
| * @return the result of attempting to send a command to the sdram | ||
| */ | ||
| virtual Status SendCommand(SDRAMCommand type, SDRAMCommandTarget target, uint16_t refreshNumber, | ||
| uint16_t modeRegister) = 0; | ||
|
|
||
| /** | ||
| * Program the SDRAM Memory Refresh rate. | ||
| * | ||
| * @param rowCount The number of rows in the SDRAM (1 << num_of_row_bits) | ||
| * @param refreshTime The amount of time to do all refresh cycles | ||
| * @return the result of attempting to program the refresh rate of the sdram | ||
| */ | ||
| virtual Status ProgramRefreshRate(uint32_t rowCount, uint32_t refreshTime) = 0; | ||
|
|
||
| /** | ||
| * Force a number of Refresh Commands to the SDRAM, effectively making it idle. | ||
| * | ||
| * @param autoRefreshNumber Specifies the auto Refresh number. | ||
| * @return | ||
| */ | ||
| virtual Status SetAutoRefreshNumber(uint32_t autoRefreshNumber) = 0; | ||
|
|
||
| /** | ||
| * Returns the indicated SDRAM bank mode status. | ||
| * | ||
| * @return The SDRAM bank mode status, could be on of the following HAL defines: | ||
| * FMC_SDRAM_NORMAL_MODE, FMC_SDRAM_SELF_REFRESH_MODE or | ||
| * FMC_SDRAM_POWER_DOWN_MODE. | ||
| */ | ||
| virtual SDRAMState GetModeStatus() = 0; | ||
|
|
||
| virtual ~SDRAM() = default; | ||
|
|
||
| [[nodiscard]] uint32_t* getSdramMemoryAddress() const { | ||
| return this->memoryAddress; | ||
| } | ||
|
|
||
| protected: | ||
|
DannyCato marked this conversation as resolved.
|
||
| uint32_t* memoryAddress; | ||
| SDRAMPinGroup& pins; | ||
| SDRAMInitConfig initConfig; | ||
| SDRAMTimingConfig timingConfig; | ||
| const SDRAMDevice& device; | ||
|
|
||
| static constexpr Status HALStatusToSDRAMStatus(uint32_t hal_status) { | ||
| return static_cast<Status>(hal_status); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Interface class to force SDRAM realizations to implement sendStartUpCommands, so that on creation everything can | ||
| * be made and handled at once. No waiting or calling extra functions after calling getSDRAM() | ||
| */ | ||
| class SDRAMDevice { | ||
| public: | ||
| virtual ~SDRAMDevice() = default; | ||
| virtual SDRAM::Status sendStartUpCommands(SDRAM& controller) = 0; | ||
| }; | ||
|
|
||
| } // namespace core::io | ||
|
|
||
| #endif | ||
|
DannyCato marked this conversation as resolved.
Outdated
|
||
|
|
||
| #endif // STM32F4xx | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #ifndef EVT_SDRAMF4xx_HPP | ||
| #define EVT_SDRAMF4xx_HPP | ||
|
|
||
| /** | ||
| * FMC SDRAM driver for STM32F4 series. | ||
| * | ||
| * Provides a C++ abstraction for configuring and accessing external SDRAM | ||
| * using the Flexible Memory Controller (FMC) peripheral. | ||
| * | ||
| * This driver wraps STM32 HAL functionality and simplifies: | ||
| * - GPIO configuration for FMC pins | ||
| * - SDRAM timing configuration | ||
| * - SDRAM operations | ||
| */ | ||
|
|
||
| #include <HALf4/stm32f4xx_hal.h> | ||
| #include <core/io/SDRAM.hpp> | ||
|
|
||
| namespace core::io { | ||
|
|
||
| /** | ||
| * Class initializes the FMC peripheral and associated GPIO pins, | ||
| * configures SDRAM timing parameters, and provides simple SDRAM methods. | ||
| */ | ||
| class SDRAMf4xx : public SDRAM { | ||
| public: | ||
| static constexpr auto SDRAM_BANK1 = 0xC0000000; | ||
| static constexpr auto SDRAM_BANK2 = 0xD0000000; | ||
|
|
||
| /** | ||
| * Initializes an FMC device by enabling the specific peripheral clock, | ||
| * setting up the SDRAM Controller | ||
| * | ||
| * @param[in] pins a struct containing an array of pins and their length for use by the SDRAM Controller. | ||
| * @param[in] sdramInitConfig SDRAM controller configuration parameters. | ||
| * @param[in] sdramTimingConfig SDRAM timing configuration parameters. | ||
| * @param[in] device interface class with abstract function that is overridden with a specific implementation | ||
| * | ||
| */ | ||
| SDRAMf4xx(SDRAMPinGroup& pins, const SDRAMInitConfig& sdramInitConfig, const SDRAMTimingConfig& sdramTimingConfig, | ||
| SDRAMDevice& device); | ||
|
|
||
| /** | ||
| * Enable write protection for the sdram | ||
| * | ||
| * @return the result of attempting to enable the write protection | ||
| */ | ||
| Status EnableWriteProtection() override; | ||
|
|
||
| /** | ||
| * Disable write protection for the sdram | ||
| * | ||
| * @return the result of attempting to disable the write protection | ||
| */ | ||
| Status DisableWriteProtection() override; | ||
|
|
||
| /** | ||
| * @brief Send a command to the sdram | ||
| * @param type is the kind of the command to be sent, can be a value from enum SDRAM::Command | ||
| * @param target specifies which device to send the command to, can be a value from SDRAM::Bank | ||
| * @param refreshNumber defines the number of SDRAM clock cycles where the controller sends the auto refresh | ||
| * command (essentially a halted state where the SDRAM will ignore any requests), can be a value between 1 and 15 | ||
| * @param modeRegister defines how the SDRAM will operate when sending the SET_SDRAM_MODE command, ignored | ||
| * when sending any other command. The specific value to send depends on the datasheet usually | ||
| * under Mode Register Definition | ||
| * @return the result of attempting to send a command to the sdram | ||
| */ | ||
| Status SendCommand(SDRAMCommand type, SDRAMCommandTarget target, uint16_t refreshNumber, | ||
| uint16_t modeRegister) override; | ||
|
|
||
| /** | ||
| * Program the SDRAM Memory Refresh rate. | ||
| * | ||
| * @param rowCount The number of rows in the SDRAM (1 << num_of_row_bits) | ||
| * @param refreshTime The amount of time to do all refresh cycles | ||
| * @return the result of attempting to program the refresh rate of the sdram | ||
| */ | ||
| Status ProgramRefreshRate(uint32_t rowCount, uint32_t refreshTime) override; | ||
|
|
||
| /** | ||
| * Force a number of Refresh Commands to the SDRAM, effectively making it idle. | ||
| * | ||
| * @param autoRefreshNumber Specifies the auto Refresh number. | ||
| * @return STATUS::OK | ||
| */ | ||
| Status SetAutoRefreshNumber(uint32_t autoRefreshNumber) override; | ||
|
|
||
| /** | ||
| * Returns the indicated FMC SDRAM bank mode status. | ||
| * | ||
| * @return The FMC SDRAM bank mode status, could be one of the following HAL defines: | ||
| * FMC_SDRAM_NORMAL_MODE, FMC_SDRAM_SELF_REFRESH_MODE or | ||
|
DannyCato marked this conversation as resolved.
|
||
| * FMC_SDRAM_POWER_DOWN_MODE. | ||
| */ | ||
| SDRAMState GetModeStatus() override; | ||
|
|
||
| /** | ||
| * Returns a SdramInitConfig struct pre-filled with default values. | ||
| * Intended to be overridden to suit the specific use case before being passed into the constructor. | ||
| */ | ||
| static SDRAMInitConfig defaultSdramInitConfig(); | ||
|
|
||
| /** | ||
| * Returns a SdramTimingConfig pre-filled with default values. | ||
| * Intended to be overridden to suit the specific use case before being passed into the constructor. | ||
| */ | ||
| static SDRAMTimingConfig defaultSdramTimingConfig(); | ||
|
|
||
| private: | ||
| /** | ||
| * Helper function to determine the memory address based on the bank number | ||
| */ | ||
| [[nodiscard]] void* getSDRAMMemoryAddress() const; | ||
|
|
||
| /** | ||
| * Helper function to initialize all GPIO SDRAM pins | ||
| * | ||
| * @param[in] pins a struct containing an array of all SDRAM GPIO pins and their length | ||
| */ | ||
| static void InitHardware(SDRAMPinGroup& pins); | ||
|
|
||
| FMC_SDRAM_TypeDef* sdramDevice; | ||
|
DannyCato marked this conversation as resolved.
|
||
|
|
||
| SDRAM_HandleTypeDef sdram; | ||
| FMC_SDRAM_TimingTypeDef sdramTiming; | ||
| }; | ||
|
|
||
| } // namespace core::io | ||
|
|
||
| #endif // EVT_SDRAMF4xx_HPP | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.