3030
3131/* Clock + RAM voltage settings */
3232#include "fsl_clock.h"
33- #include "fsl_spc.h"
33+ // #include "fsl_spc.h"
3434
3535/* Flash driver */
3636#include "fsl_device_registers.h"
3737#include "fsl_lpspi_flash.h"
38- #include "fsl_k4_flash.h"
38+ #include "fsl_flash_api.h"
39+ #include "fsl_ccm32k.h"
40+
41+ #define FLASH FMU0
3942
4043/*!< Core clock frequency: 48000000Hz */
4144#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 48000000U
@@ -87,24 +90,24 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
8790{
8891 int ret ;
8992 int w = 0 ;
90- const uint8_t empty_qword [16 ] = {
91- 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
92- 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF
93+ const uint32_t empty_qword [4 ] = {
94+ 0xFFFFFFF , 0xFFFFFFFF , 0xFFFFFFFF , 0xFFFFFFFF
9395 };
9496
9597 while (len > 0 ) {
96- if ((len < 16 ) || address & 0x0F ) {
97- uint8_t aligned_qword [16 ];
98+ if ((len < 16 ) || ( address & 0x0F ) ) {
99+ uint32_t aligned_qword [4 ];
98100 uint32_t address_align = address - (address & 0x0F );
99101 uint32_t start_off = address - address_align ;
100102 int i ;
101103
102104 memcpy (aligned_qword , (void * )address_align , 16 );
103105 for (i = start_off ; ((i < 16 ) && (i < len + (int )start_off )); i ++ ) {
104- aligned_qword [i ] = data [w ++ ];
106+ (( uint8_t * ) aligned_qword ) [i ] = data [w ++ ];
105107 }
106108 if (memcmp (aligned_qword , empty_qword , 16 ) != 0 ) {
107- ret = FLASH_Program (& pflash , FLASH , address_align , aligned_qword , 16 );
109+ ret = FLASH_Program (& pflash , FLASH , address_align , aligned_qword ,
110+ 16 );
108111 if (ret != kStatus_Success )
109112 return -1 ;
110113 }
@@ -113,7 +116,17 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
113116 }
114117 else {
115118 uint32_t len_align = len - (len & 0x0F );
116- ret = FLASH_Program (& pflash , FLASH , address , (uint8_t * )data + w , len_align );
119+ if (((uint32_t )data + w ) & 0x0F ) {
120+ uint32_t __attribute__((aligned (16 ))) aligned_data [4 ];
121+ memcpy (aligned_data , (void * )((uint32_t )data + w ), len_align );
122+ ret = FLASH_Program (& pflash , FLASH , address , (uint32_t * )data + w ,
123+ len_align );
124+ }
125+ else
126+ {
127+ ret = FLASH_Program (& pflash , FLASH , address , (uint32_t * )data + w ,
128+ len_align );
129+ }
117130 if (ret != kStatus_Success )
118131 return -1 ;
119132 len -= len_align ;
0 commit comments