@@ -37,12 +37,57 @@ AT_QUICKACCESS_SECTION_CODE(status_t flexspi_nor_flash_page_program_ram(uint32_t
3737AT_QUICKACCESS_SECTION_CODE (void flexspi_nor_flash_read_data_ram (uint32_t addr ,
3838 uint32_t * buffer ,
3939 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+ }
4085
4186void flexspi_update_lut_ram (void )
4287{
4388 flexspi_config_t config ;
4489
45- memset (& config , 0 , sizeof (config ));
90+ flexspi_memset (& config , 0 , sizeof (config ));
4691
4792 /*Get FLEXSPI default settings and configure the flexspi. */
4893 FLEXSPI_GetDefaultConfig (& config );
@@ -77,7 +122,7 @@ status_t flexspi_nor_write_enable_ram(uint32_t baseAddr)
77122 flexspi_transfer_t flashXfer ;
78123 status_t status = kStatus_Success ;
79124
80- memset (& flashXfer , 0 , sizeof (flashXfer ));
125+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
81126
82127 /* Write enable */
83128 flashXfer .deviceAddress = baseAddr ;
@@ -99,7 +144,7 @@ status_t flexspi_nor_wait_bus_busy_ram(void)
99144 status_t status = kStatus_Success ;
100145 flexspi_transfer_t flashXfer ;
101146
102- memset (& flashXfer , 0 , sizeof (flashXfer ));
147+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
103148
104149 flashXfer .deviceAddress = 0 ;
105150 flashXfer .port = kFLEXSPI_PortA1 ;
@@ -138,7 +183,7 @@ status_t flexspi_nor_flash_erase_sector_ram(uint32_t address)
138183 status_t status = kStatus_Success ;
139184 flexspi_transfer_t flashXfer ;
140185
141- memset (& flashXfer , 0 , sizeof (flashXfer ));
186+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
142187
143188 /* Write enable */
144189 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
229274 flexspi_transfer_t flashXfer ;
230275 uint32_t offset = 0 ;
231276
232- memset (& flashXfer , 0 , sizeof (flashXfer ));
277+ flexspi_memset (& flashXfer , 0 , sizeof (flashXfer ));
233278
234279 flexspi_lower_clock_ram ();
235280
0 commit comments