Skip to content

Commit 8496802

Browse files
committed
created generic FMC interface
1 parent 7258706 commit 8496802

6 files changed

Lines changed: 72 additions & 24 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ target_sources(${PROJECT_NAME} PRIVATE
4444
src/core/dev/RTCTimer.cpp
4545
src/core/dev/storage/M24C32.cpp
4646
src/core/dev/Thermistor.cpp
47-
src/core/utils/log.cpp)
47+
src/core/utils/log.cpp
48+
src/core/io/FMC.cpp)
4849

4950
get_directory_property(COMPDEFS COMPILE_DEFINITIONS)
5051
if(COMPDEFS MATCHES "(.*)STM32F3xx(.*)")
@@ -74,7 +75,8 @@ elseif(COMPDEFS MATCHES "(.*)STM32F4xx(.*)")
7475
src/core/io/platform/f4xx/SPIf4xx.cpp
7576
src/core/dev/platform/f4xx/IWDGf4xx.cpp
7677
src/core/dev/platform/f4xx/RTCf4xx.cpp
77-
src/core/dev/platform/f4xx/Timerf4xx.cpp)
78+
src/core/dev/platform/f4xx/Timerf4xx.cpp
79+
src/core/io/platform/f4xx/FMCf4xx.cpp)
7880
else()
7981
message(FATAL_ERROR "the HAL didnt compile in top level CMake")
8082
endif()

include/core/io/FMC.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef EVT_FMC_HPP
2+
#define EVT_FMC_HPP
3+
4+
#include <cstdint>
5+
6+
namespace core::io {
7+
8+
class FMC {
9+
public:
10+
/**
11+
* Initializes an FMC device
12+
*/
13+
FMC(uint32_t sdramMemoryAddress);
14+
15+
/**
16+
* Write a value to SDRAM at the specified byte offset.
17+
*
18+
* @param[in] offset Byte offset from the SDRAM base address
19+
* @param[in] value Value to write to memory
20+
*/
21+
void write32(uint32_t offset, uint32_t value) const;
22+
23+
/**
24+
* Read a value SDRAM at the specified byte offset.
25+
*
26+
* @param[in] offset Byte offset from the SDRAM base address
27+
*/
28+
uint32_t read32(uint32_t offset) const;
29+
protected:
30+
uint32_t sdramMemoryAddress;
31+
};
32+
33+
}
34+
35+
#endif // EVT_FMC_HPP
36+
37+

include/core/io/platform/f4xx/FMCf4xx.hpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "HALf4/stm32f4xx_ll_fmc.h"
2020
#include "HALf4/stm32f4xx_hal_sdram.h"
2121

22+
#include "core/io/FMC.hpp"
23+
2224
#define SDRAM_TIMEOUT (0x0000FFFFUL)
2325

2426
typedef struct {
@@ -127,7 +129,7 @@ namespace core::io {
127129
* configures SDRAM timing parameters, and provides simple 32-bit
128130
* memory read/write access methods.
129131
*/
130-
class FMCf4xx {
132+
class FMCf4xx : public FMC {
131133
public:
132134
/**
133135
* Structure to simplify SDRAM initialization, pre-filled with default values
@@ -236,20 +238,9 @@ class FMCf4xx {
236238
*/
237239
FMCf4xx(FMCPinConfig pinConfig, SdramInitConfig sdramInitConfig, SdramTimingConfig sdramTimingConfig);
238240

239-
/**
240-
* Write a value to SDRAM at the specified byte offset.
241-
*
242-
* @param[in] offset Byte offset from the SDRAM base address
243-
* @param[in] value Value to write to memory
244-
*/
245241
void write32(uint32_t offset, uint32_t value) const;
246242

247-
/**
248-
* Read a value SDRAM at the specified byte offset.
249-
*
250-
* @param[in] offset Byte offset from the SDRAM base address
251-
*/
252-
[[nodiscard]] uint32_t read32(uint32_t offset) const;
243+
uint32_t read32(uint32_t offset) const;
253244

254245
private:
255246
/**
@@ -267,14 +258,17 @@ class FMCf4xx {
267258
*/
268259
void InitPinGroup(const FMC_GPIO* pins, uint8_t count);
269260

261+
/**
262+
* @return the base address depending on the bank number
263+
*/
264+
uint32_t getSdramBaseAddress();
265+
270266
SdramInitConfig sdramInitConfig;
271267
SdramTimingConfig sdramTimingConfig;
272268
FMCPinConfig fmcPinConfig;
273269

274270
SDRAM_HandleTypeDef sdram;
275271
FMC_SDRAM_TimingTypeDef sdramTiming;
276-
277-
uint32_t sdramMemoryAddress; //address to read and write to
278272
};
279273

280274
}

libs/HALf4/src/stm32f4xx_hal_sdram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ uint32_t HAL_SDRAM_GetModeStatus(SDRAM_HandleTypeDef *hsdram)
12121212
* the configuration information for SDRAM module.
12131213
* @retval HAL state
12141214
*/
1215-
HAL_SDRAM_StateTypeDef HAL_SDRAM_GetState(const SDRAM_HandleTypeDef *hsdram)
1215+
HAL_SDRAM_StateTypeDef HAL_SDRAM_GetState(SDRAM_HandleTypeDef *hsdram)
12161216
{
12171217
return hsdram->State;
12181218
}

src/core/io/FMC.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "core/io/FMC.hpp"
2+
3+
namespace core::io {
4+
5+
FMC::FMC(uint32_t sdramMemoryAddress) {
6+
this->sdramMemoryAddress = sdramMemoryAddress;
7+
}
8+
9+
} // namespace core::io

src/core/io/platform/f4xx/FMCf4xx.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#include <core/io/platform/f4xx/FMCf4xx.hpp>
2+
#include <core/io/FMC.hpp>
23

34
namespace core::io {
45

5-
FMCf4xx::FMCf4xx(const FMCPinConfig pinConfig, const SdramInitConfig sdramInitConfig, const SdramTimingConfig sdramTimingConfig) :
6+
FMCf4xx::FMCf4xx(FMCPinConfig pinConfig, SdramInitConfig sdramInitConfig, SdramTimingConfig sdramTimingConfig) :
7+
FMC(0xC0000000),
68
sdramInitConfig(sdramInitConfig),
79
sdramTimingConfig(sdramTimingConfig),
810
fmcPinConfig(pinConfig),
911
sdram({nullptr}),
1012
sdramTiming({0}) {
13+
// FMC(getSdramBaseAddress());
14+
1115
InitHardware(pinConfig);
1216

1317
// map the class init structs to the hal structs
@@ -30,11 +34,6 @@ sdramTiming({0}) {
3034
sdramTiming.RCDDelay = sdramTimingConfig.rcdDelay;
3135

3236
HAL_SDRAM_Init(&sdram, &sdramTiming);
33-
34-
if (sdramInitConfig.sdBank == FMC_SDRAM_BANK1) //determine read write memory address
35-
sdramMemoryAddress = 0xC0000000;
36-
else
37-
sdramMemoryAddress = 0xD0000000;
3837
}
3938

4039
void FMCf4xx::write32(uint32_t offset, uint32_t value) const {
@@ -67,6 +66,13 @@ uint32_t FMCf4xx::read32(uint32_t offset) const {
6766
return *ptr;
6867
}
6968

69+
uint32_t FMCf4xx::getSdramBaseAddress() {
70+
if (sdramInitConfig.sdBank == FMC_SDRAM_BANK1) //determine read write memory address
71+
return 0xC0000000;
72+
73+
return 0xD0000000; //else
74+
}
75+
7076
void FMCf4xx::InitHardware(const FMCPinConfig& pinConfig) {
7177
__HAL_RCC_FMC_CLK_ENABLE();
7278

0 commit comments

Comments
 (0)