6
6
7
7
#define DT_DRV_COMPAT st_stm32_fmc_nor_psram
8
8
9
- #include <zephyr/device.h>
10
9
#include <soc.h>
11
- #include <errno.h>
12
-
10
+ #include <zephyr/device.h>
13
11
#include <zephyr/logging/log.h>
14
12
LOG_MODULE_REGISTER (memc_stm32_nor_psram , CONFIG_MEMC_LOG_LEVEL );
15
13
16
- /** SRAM base register offset, see FMC_Bank1_R_BASE */
17
- #define SRAM_OFFSET 0x0000UL
18
- /** SRAM extended mode register offset, see FMC_Bank1E_R_BASE */
19
- #define SRAM_EXT_OFFSET 0x0104UL
20
-
21
14
/** FMC NOR/PSRAM controller bank configuration fields. */
22
15
struct memc_stm32_nor_psram_bank_config {
23
16
FMC_NORSRAM_InitTypeDef init ;
@@ -27,8 +20,6 @@ struct memc_stm32_nor_psram_bank_config {
27
20
28
21
/** FMC NOR/PSRAM controller configuration fields. */
29
22
struct memc_stm32_nor_psram_config {
30
- FMC_NORSRAM_TypeDef * nor_psram ;
31
- FMC_NORSRAM_EXTENDED_TypeDef * extended ;
32
23
const struct memc_stm32_nor_psram_bank_config * banks ;
33
24
size_t banks_len ;
34
25
};
@@ -37,12 +28,11 @@ static int memc_stm32_nor_init(const struct memc_stm32_nor_psram_config *config,
37
28
const struct memc_stm32_nor_psram_bank_config * bank_config )
38
29
{
39
30
FMC_NORSRAM_TimingTypeDef * ext_timing ;
40
- NOR_HandleTypeDef hnor = { 0 };
41
-
42
- hnor .Instance = config -> nor_psram ;
43
- hnor .Extended = config -> extended ;
44
-
45
- memcpy (& hnor .Init , & bank_config -> init , sizeof (hnor .Init ));
31
+ NOR_HandleTypeDef hnor = {
32
+ .Instance = FMC_NORSRAM_DEVICE ,
33
+ .Extended = FMC_NORSRAM_EXTENDED_DEVICE ,
34
+ .Init = bank_config -> init
35
+ };
46
36
47
37
if (bank_config -> init .ExtendedMode == FMC_EXTENDED_MODE_ENABLE ) {
48
38
ext_timing = (FMC_NORSRAM_TimingTypeDef * )& bank_config -> timing_ext ;
@@ -63,12 +53,11 @@ static int memc_stm32_psram_init(const struct memc_stm32_nor_psram_config *confi
63
53
const struct memc_stm32_nor_psram_bank_config * bank_config )
64
54
{
65
55
FMC_NORSRAM_TimingTypeDef * ext_timing ;
66
- SRAM_HandleTypeDef hsram = { 0 };
67
-
68
- hsram .Instance = config -> nor_psram ;
69
- hsram .Extended = config -> extended ;
70
-
71
- memcpy (& hsram .Init , & bank_config -> init , sizeof (hsram .Init ));
56
+ SRAM_HandleTypeDef hsram = {
57
+ .Instance = FMC_NORSRAM_DEVICE ,
58
+ .Extended = FMC_NORSRAM_EXTENDED_DEVICE ,
59
+ .Init = bank_config -> init
60
+ };
72
61
73
62
if (bank_config -> init .ExtendedMode == FMC_EXTENDED_MODE_ENABLE ) {
74
63
ext_timing = (FMC_NORSRAM_TimingTypeDef * )& bank_config -> timing_ext ;
@@ -88,21 +77,21 @@ static int memc_stm32_psram_init(const struct memc_stm32_nor_psram_config *confi
88
77
static int memc_stm32_nor_psram_init (const struct device * dev )
89
78
{
90
79
const struct memc_stm32_nor_psram_config * config = dev -> config ;
91
- uint32_t memory_type ;
80
+ const struct memc_stm32_nor_psram_bank_config * bank_config ;
92
81
size_t bank_idx ;
93
- int ret = 0 ;
82
+ int ret ;
94
83
95
84
for (bank_idx = 0U ; bank_idx < config -> banks_len ; ++ bank_idx ) {
96
- memory_type = config -> banks [bank_idx ]. init . MemoryType ;
85
+ bank_config = & config -> banks [bank_idx ];
97
86
98
- switch (memory_type ) {
87
+ switch (bank_config -> init . MemoryType ) {
99
88
case FMC_MEMORY_TYPE_NOR :
100
- ret = memc_stm32_nor_init (config , & config -> banks [ bank_idx ] );
89
+ ret = memc_stm32_nor_init (config , bank_config );
101
90
break ;
102
91
case FMC_MEMORY_TYPE_PSRAM :
103
92
__fallthrough ;
104
93
case FMC_MEMORY_TYPE_SRAM :
105
- ret = memc_stm32_psram_init (config , & config -> banks [ bank_idx ] );
94
+ ret = memc_stm32_psram_init (config , bank_config );
106
95
break ;
107
96
default :
108
97
ret = - ENOTSUP ;
@@ -112,13 +101,13 @@ static int memc_stm32_nor_psram_init(const struct device *dev)
112
101
if (ret < 0 ) {
113
102
LOG_ERR ("Unable to initialize memory type: "
114
103
"0x%08X, NSBank: %d, err: %d" ,
115
- memory_type , config -> banks [bank_idx ].init .NSBank , ret );
116
- goto end ;
104
+ bank_config -> init .MemoryType ,
105
+ bank_config -> init .NSBank , ret );
106
+ return ret ;
117
107
}
118
108
}
119
109
120
- end :
121
- return ret ;
110
+ return 0 ;
122
111
}
123
112
124
113
/** SDRAM bank/s configuration initialization macro. */
@@ -165,9 +154,6 @@ static const struct memc_stm32_nor_psram_bank_config bank_config[] = {
165
154
166
155
/** SRAM configuration. */
167
156
static const struct memc_stm32_nor_psram_config config = {
168
- .nor_psram = (FMC_NORSRAM_TypeDef * )(DT_REG_ADDR (DT_INST_PARENT (0 )) + SRAM_OFFSET ),
169
- .extended = (FMC_NORSRAM_EXTENDED_TypeDef * )(DT_REG_ADDR (DT_INST_PARENT (0 ))
170
- + SRAM_EXT_OFFSET ),
171
157
.banks = bank_config ,
172
158
.banks_len = ARRAY_SIZE (bank_config ),
173
159
};
0 commit comments