@@ -37,12 +37,57 @@ AT_QUICKACCESS_SECTION_CODE(status_t flexspi_nor_flash_page_program_ram(uint32_t
37
37
AT_QUICKACCESS_SECTION_CODE (void flexspi_nor_flash_read_data_ram (uint32_t addr ,
38
38
uint32_t * buffer ,
39
39
uint32_t size ));
40
+ AT_QUICKACCESS_SECTION_CODE (void * flexspi_memset (void * buf , int c , size_t n ));
41
+ /**
42
+ * @brief Set bytes in memory. If put this code in SRAM, Make sure this code
43
+ * does not call functions in Flash.
44
+ *
45
+ * @return pointer to start of buffer
46
+ */
47
+ void * flexspi_memset (void * buf , int c , size_t n )
48
+ {
49
+ /* do byte-sized initialization until word-aligned or finished */
50
+ unsigned char * d_byte = (unsigned char * )buf ;
51
+ unsigned char c_byte = (unsigned char )c ;
52
+
53
+ while (((unsigned int )d_byte ) & 0x3 ) {
54
+ if (n == 0 ) {
55
+ return buf ;
56
+ }
57
+ * (d_byte ++ ) = c_byte ;
58
+ n -- ;
59
+ };
60
+
61
+ /* do word-sized initialization as long as possible */
62
+
63
+ unsigned int * d_word = (unsigned int * )d_byte ;
64
+ unsigned int c_word = (unsigned int )(unsigned char )c ;
65
+
66
+ c_word |= c_word << 8 ;
67
+ c_word |= c_word << 16 ;
68
+
69
+ while (n >= sizeof (unsigned int )) {
70
+ * (d_word ++ ) = c_word ;
71
+ n -= sizeof (unsigned int );
72
+ }
73
+
74
+ /* do byte-sized initialization until finished */
75
+
76
+ d_byte = (unsigned char * )d_word ;
77
+
78
+ while (n > 0 ) {
79
+ * (d_byte ++ ) = c_byte ;
80
+ n -- ;
81
+ }
82
+
83
+ return buf ;
84
+ }
40
85
41
86
void flexspi_update_lut_ram (void )
42
87
{
43
88
flexspi_config_t config ;
44
89
45
- memset (& config , 0 , sizeof (config ));
90
+ flexspi_memset (& config , 0 , sizeof (config ));
46
91
47
92
/*Get FLEXSPI default settings and configure the flexspi. */
48
93
FLEXSPI_GetDefaultConfig (& config );
@@ -77,7 +122,7 @@ status_t flexspi_nor_write_enable_ram(uint32_t baseAddr)
77
122
flexspi_transfer_t flashXfer ;
78
123
status_t status = kStatus_Success ;
79
124
80
- memset (& flashXfer , 0 , sizeof (flashXfer ));
125
+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
81
126
82
127
/* Write enable */
83
128
flashXfer .deviceAddress = baseAddr ;
@@ -99,7 +144,7 @@ status_t flexspi_nor_wait_bus_busy_ram(void)
99
144
status_t status = kStatus_Success ;
100
145
flexspi_transfer_t flashXfer ;
101
146
102
- memset (& flashXfer , 0 , sizeof (flashXfer ));
147
+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
103
148
104
149
flashXfer .deviceAddress = 0 ;
105
150
flashXfer .port = kFLEXSPI_PortA1 ;
@@ -138,7 +183,7 @@ status_t flexspi_nor_flash_erase_sector_ram(uint32_t address)
138
183
status_t status = kStatus_Success ;
139
184
flexspi_transfer_t flashXfer ;
140
185
141
- memset (& flashXfer , 0 , sizeof (flashXfer ));
186
+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
142
187
143
188
/* Write enable */
144
189
status = flexspi_nor_write_enable_ram (address );
@@ -229,7 +274,7 @@ status_t flexspi_nor_flash_page_program_ram(uint32_t address, const uint32_t *sr
229
274
flexspi_transfer_t flashXfer ;
230
275
uint32_t offset = 0 ;
231
276
232
- memset (& flashXfer , 0 , sizeof (flashXfer ));
277
+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
233
278
234
279
flexspi_lower_clock_ram ();
235
280
0 commit comments