Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 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 Feb 14, 2026
712e8b7
replaced private vars with structs stored in class
oc6723 Feb 17, 2026
3dd7cad
changed structs to pass by value instead of reference
oc6723 Feb 17, 2026
0160aa4
fixed CMakeLists.txt i think
oc6723 Feb 17, 2026
27cb4f1
renamed to FMCf4xx
oc6723 Feb 20, 2026
7258706
improved read and write functions to check bounds and enforce bit ali…
oc6723 Feb 20, 2026
8496802
created generic FMC interface
oc6723 Feb 28, 2026
2f47125
fixed compile bug
oc6723 Feb 28, 2026
2de2205
used getSdramBaseAddress() in FMC constructor
oc6723 Feb 28, 2026
d63112a
Merge branch 'main' into feature/ChongOscar/fmc-support
ChongOscar Feb 28, 2026
565b9c4
Applied Formatting Changes During GitHub Build
Feb 28, 2026
cb91f45
removed unnecessary #defines in FMCf4xx.hpp and swapped pin typedefs …
oc6723 Mar 5, 2026
db7d9a4
made default init config functions so the definitions can be moved to…
oc6723 Mar 6, 2026
1646c19
Merge remote-tracking branch 'origin/feature/ChongOscar/fmc-support' …
oc6723 Mar 6, 2026
ab4bfc3
removed duplicate namespace declaration
oc6723 Mar 6, 2026
f9d0ced
Applied Formatting Changes During GitHub Build
Mar 6, 2026
4f2798f
added back sdramMemoryAddress as public void* but init looks ugly
oc6723 Mar 6, 2026
01d8b29
Merge remote-tracking branch 'origin/feature/ChongOscar/fmc-support' …
oc6723 Mar 6, 2026
7ce4e85
why cant i push
oc6723 Mar 6, 2026
3498621
Applied Formatting Changes During GitHub Build
Mar 6, 2026
99cb57e
formatting changes
oc6723 Mar 16, 2026
a5c77d7
merged with github
oc6723 Mar 16, 2026
4f87078
Applied Formatting Changes During GitHub Build
Mar 16, 2026
6a996e6
moved everyting back to f4xx because sdram is not supported on te f3's
oc6723 Mar 24, 2026
7b558ad
Merge remote-tracking branch 'origin/feature/ChongOscar/fmc-support' …
oc6723 Mar 24, 2026
6823191
chaned clock frequency #defines to functions
ChongOscar Mar 28, 2026
62e6fd6
split FMC and SDRAM into 3 classes, FMC being the base class, SDRAM i…
ChongOscar Apr 10, 2026
1417f62
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato Apr 19, 2026
4978d6f
Made throughout the file to make things slightly better. If anyone is…
DannyCato Apr 19, 2026
41a27b5
Remove line that makes F302 always fail to build, so that samples can…
DannyCato Apr 19, 2026
ee5ab85
Compilation for every device now works and added specifier for F469 h…
DannyCato Apr 19, 2026
dfd49a1
Applied Formatting Changes During GitHub Build
Apr 19, 2026
9b7c071
Oops, accidentally had it so that SDRAM would never build. Adjusted i…
DannyCato Apr 19, 2026
5a4bb81
Merge branch 'feature/ChongOscar/fmc-support' of github.com:RIT-EVT/E…
DannyCato Apr 19, 2026
e0e37b9
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato Apr 21, 2026
84b4e15
Some changes made, but still need to make lots of progress
DannyCato Apr 22, 2026
05f49bf
Changed how sending SDRAM Commands work to take in arguments instead …
DannyCato Apr 22, 2026
ae5ec73
Saw a lot of things that could be improved and tried to make those im…
DannyCato Apr 23, 2026
3c0e255
Forgot to add Cmake
DannyCato Apr 23, 2026
6dbc03f
Changed Function descriptions
DannyCato May 1, 2026
b3445a8
Remove old fmc.hpp include
DannyCato May 1, 2026
d1dced3
Applied Formatting Changes During GitHub Build
May 1, 2026
1c14237
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato May 2, 2026
1c02890
SDRAM edits, everything is building
DannyCato May 2, 2026
61ba5c4
Merge branch 'feature/ChongOscar/fmc-support' of github.com:RIT-EVT/E…
DannyCato May 2, 2026
84a0fec
Applied Formatting Changes During GitHub Build
May 2, 2026
c1a5245
Merge branch 'main' into feature/ChongOscar/fmc-support
DannyCato May 16, 2026
649dd9a
Integrated into a working system using the HUDL projectgit add .
DannyCato May 16, 2026
4f4f2d6
readded peripheral guards for SDRAM
DannyCato May 16, 2026
7ade10f
Applied Formatting Changes During GitHub Build
May 16, 2026
4a62fab
Changed structure to add a new interface and make programmer facing c…
DannyCato May 16, 2026
e588483
Push more changes and fix CMake
DannyCato May 16, 2026
4b63dc1
Fix missing project in CMake :/
DannyCato May 16, 2026
cb34552
Applied Formatting Changes During GitHub Build
May 16, 2026
257821a
Added comments and made some changed to how the NSToSDRAMClockCycles …
DannyCato May 25, 2026
b41579f
Fixing SDRAM to use input config
DannyCato May 29, 2026
7900a3f
Applied Formatting Changes During GitHub Build
May 29, 2026
43140da
repush to ensure it works
DannyCato May 29, 2026
512a827
Merge branch 'feature/ChongOscar/fmc-support' of https://github.com/R…
DannyCato May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ target_sources(${PROJECT_NAME} PRIVATE
src/core/dev/RTCTimer.cpp
src/core/dev/storage/M24C32.cpp
src/core/dev/Thermistor.cpp
src/core/utils/log.cpp)
src/core/utils/log.cpp
src/core/io/FMC.cpp)

get_directory_property(COMPDEFS COMPILE_DEFINITIONS)
if(COMPDEFS MATCHES "(.*)STM32F3xx(.*)")
Expand Down Expand Up @@ -76,7 +77,9 @@ elseif(COMPDEFS MATCHES "(.*)STM32F4xx(.*)")
src/core/io/platform/f4xx/SPIf4xx.cpp
src/core/dev/platform/f4xx/IWDGf4xx.cpp
src/core/dev/platform/f4xx/RTCf4xx.cpp
src/core/dev/platform/f4xx/Timerf4xx.cpp)
src/core/dev/platform/f4xx/Timerf4xx.cpp
src/core/io/SDRAM.cpp # STM32F469xx only peripheral
src/core/io/platform/f4xx/SDRAMf4xx.cpp)
else()
message(FATAL_ERROR "the HAL didnt compile in top level CMake")
endif()
Expand Down
105 changes: 105 additions & 0 deletions include/core/io/FMC.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#ifndef EVT_FMC_HPP
#define EVT_FMC_HPP

#include <core/io/GPIO.hpp>

// #ifdef STM32F3xx
// #error Controlling SDRAM through an FMC is not supported on F3xx chips
// #endif
Comment thread
DannyCato marked this conversation as resolved.
Outdated

namespace core::io {

/**
* The FMC is a Flexible Memory Controller used for controlling various forms of memory, including external SDRAM,
* NOR flash, NAND flash, and SRAM, the F3 series chips only support SRAM.
Comment thread
DannyCato marked this conversation as resolved.
Outdated
*/
class FMC {
public:
/**
* Represents the status of operation of the FMC
*
* This can be used to represent the state of the SDRAM or the
* result of an FMC operation.
*/
enum class Status {
OK = 0x00U,
ERROR = 0x01U,
BUSY = 0x02U,
TIMEOUT = 0x03U,
};

/**
* Structure to hold an array of GPIO address pins for the FMC
*/
struct FMCAddressPins {
Pin* pins;
uint8_t count;
};

/**
* Structure to hold an array of GPIO address pins for the FMC
*/
struct FMCDataPins {
Pin* pins;
uint8_t count;
};

/**
* Structure to hold an array of GPIO command pins for the FMC
*/
struct FMCCommandPins {
Pin* pins;
uint8_t count;
};

/**
* Structure to hold an array of GPIO byte enable pins for the FMC
*/
struct FMCByteEnablePins {
Pin* pins;
uint8_t count;
};

/**
* Structure to hold an array of GPIO bank pins for the FMC
*/
struct FMCBankPins {
Pin* pins;
uint8_t count;
};

/**
* Groups all FMC GPIO pin configurations.
*
* Contains arrays of:
* - Address pins
* - Data pins
* - Bank select pins
* - Command pins
* - Byte enable pins
*/
struct FMCPinConfig {
FMCAddressPins address;
FMCDataPins data;
FMCByteEnablePins byteEnable;
FMCBankPins bank;
FMCCommandPins command;
};

/**
* Initializes an FMC device for controlling memory
*/
FMC(void* memoryAddress, const FMCPinConfig& pinConfig);

virtual ~FMC() = default;

[[nodiscard]] void* getStartingAddress() const;

Comment thread
DannyCato marked this conversation as resolved.
Outdated
protected:
FMCPinConfig fmcPinConfig;
void* memoryAddress;
};
Comment thread
DannyCato marked this conversation as resolved.
Outdated

} // namespace core::io

#endif // EVT_FMC_HPP
171 changes: 171 additions & 0 deletions include/core/io/SDRAM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#ifndef EVT_SDRAM_HPP
#define EVT_SDRAM_HPP

#ifdef STM32F4xx
Comment thread
DannyCato marked this conversation as resolved.
#include <HALf4/stm32f4xx_hal.h>
#include <core/io/FMC.hpp>

/**
* SDRAM Command Mode
*/
constexpr uint32_t SDRAM_CMD_NORMAL_MODE = 0x00000000U;
Comment thread
DannyCato marked this conversation as resolved.
Outdated
constexpr uint32_t SDRAM_CMD_CLK_ENABLE = 0x00000001U;
constexpr uint32_t SDRAM_CMD_PALL = 0x00000002U;
constexpr uint32_t SDRAM_CMD_AUTOREFRESH_MODE = 0x00000003U;
constexpr uint32_t SDRAM_CMD_LOAD_MODE = 0x00000004U;
constexpr uint32_t SDRAM_CMD_SELFREFRESH_MODE = 0x00000005U;
constexpr uint32_t SDRAM_CMD_POWERDOWN_MODE = 0x00000006U;

/**
* SDRAM Command Target
*/
constexpr uint32_t SDRAM_CMD_TARGET_BANK2 = FMC_SDCMR_CTB2;
constexpr uint32_t SDRAM_CMD_TARGET_BANK1 = FMC_SDCMR_CTB1;
constexpr uint32_t SDRAM_CMD_TARGET_BANK1_2 = 0x00000018U;

namespace core::io {

/**
* Interface for configuring and accessing external SDRAM via FMC.
* Provides clock frequency functions
*/
class SDRAM : public FMC {
public:
/**
* 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 {
Comment thread
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;
};

/**
* Structure to send commands to the SDRAM through the FMC
*
* CommandMode is the mode of the command, cam be a value from the SDRAM Command Mode #define group
* CommandTarget specifies which device to send the command to, cam be a value from the SDRAM Command Target #define
* group AutoRefreshNumber defines the number of consecutive auto refresh command issued in auto refresh mode, can
* be a value between 1 and 15 ModeRegisterDefinition defines the SDRAM Mode to register content
*/
struct SDRAMCommandStruct {
uint32_t CommandMode;
uint32_t CommandTarget;
uint32_t AutoRefreshNumber;
uint32_t ModeRegisterDefinition;
};

/**
* Constructor for initializing an FMC to control external SDRAM
*
* @param sdramMemoryAddress
Comment thread
DannyCato marked this conversation as resolved.
Outdated
* @param pinConfig
* @param sdramInitConfig
* @param sdramTimingConfig
*/
SDRAM(void* sdramMemoryAddress, const FMCPinConfig& pinConfig, const SDRAMInitConfig& sdramInitConfig,
const SDRAMTimingConfig& sdramTimingConfig);

/**
*
Comment thread
DannyCato marked this conversation as resolved.
Outdated
* @return the SDRAM clock frequency
*/
static uint32_t getSdramClockFrequency();

/**
*
Comment thread
DannyCato marked this conversation as resolved.
Outdated
* @return the SDRAM clock period in microseconds
*/
static uint32_t getSdramClockPeriodPS();

/**
*
Comment thread
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 WriteProtectionEnable() = 0;

/**
* Disable write protection for the sdram
*
* @return the result of attempting to disable the write protection
*/
virtual Status WriteProtection_Disable() = 0;

/**
* Send a command to the sdram
*
* @param command The SdramCommandStruct holding the information of the command
* @param timeout How long to wait for the sdram command
* @return the result of attempting to send a command to the sdram
*/
virtual Status SendCommand(SDRAMCommandStruct* command, uint32_t timeout) = 0;

/**
* Program the SDRAM Memory Refresh rate.
*
* @param refreshRate The SDRAM refresh rate value
* @return the result of attempting to program the refresh rate of the sdram
*/
virtual Status ProgramRefreshRate(uint32_t refreshRate) = 0;

/**
* Set the Number of consecutive SDRAM Memory auto Refresh commands.
*
* @param autoRefreshNumber Specifies the auto Refresh number.
* @return
*/
virtual Status SetAutoRefreshNumber(uint32_t autoRefreshNumber) = 0;

/**
* Returns the indicated FMC SDRAM bank mode status.
*
* @return The FMC 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 uint32_t GetModeStatus() = 0;

// void* sdramMemoryAddress;

protected:
Comment thread
DannyCato marked this conversation as resolved.
SDRAMInitConfig sdramInitConfig;
SDRAMTimingConfig sdramTimingConfig;
};

} // namespace core::io

#endif // STM32F4xx

#endif // EVT_SDRAM_HPP
Loading
Loading