Skip to content

Commit 9b42782

Browse files
committed
Fixes to hal after review
1 parent c00fe36 commit 9b42782

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

hal/mcxw.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
/* Clock + RAM voltage settings */
3232
#include "fsl_clock.h"
33-
//#include "fsl_spc.h"
3433

3534
/* Flash driver */
3635
#include "fsl_device_registers.h"
@@ -87,24 +86,25 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
8786
{
8887
int ret;
8988
int w = 0;
89+
const uint32_t flash_word_size = 16;
9090
const uint32_t empty_qword[4] = {
9191
0xFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
9292
};
9393

9494
while (len > 0) {
95-
if ((len < 16) || (address & 0x0F)) {
95+
if ((len < (int)flash_word_size) || (address & (flash_word_size - 1))) {
9696
uint32_t aligned_qword[4];
97-
uint32_t address_align = address - (address & 0x0F);
97+
uint32_t address_align = address - (address & (flash_word_size - 1));
9898
uint32_t start_off = address - address_align;
99-
int i;
99+
uint32_t i;
100100

101-
memcpy(aligned_qword, (void*)address_align, 16);
102-
for (i = start_off; ((i < 16) && (i < len + (int)start_off)); i++) {
101+
memcpy(aligned_qword, (void*)address_align, flash_word_size);
102+
for (i = start_off; ((i < flash_word_size) && (i < len + start_off)); i++) {
103103
((uint8_t *)aligned_qword)[i] = data[w++];
104104
}
105-
if (memcmp(aligned_qword, empty_qword, 16) != 0) {
105+
if (memcmp(aligned_qword, empty_qword, flash_word_size) != 0) {
106106
ret = FLASH_Program(&pflash, FLASH, address_align, aligned_qword,
107-
16);
107+
flash_word_size);
108108
if (ret != kStatus_Success)
109109
return -1;
110110
}

0 commit comments

Comments
 (0)