Skip to content

Commit 8187f9f

Browse files
committed
LPC: Fix aligned page address write
1 parent 836a13a commit 8187f9f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

hal/lpc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ static uint8_t flash_page_cache[FLASH_PAGE_SIZE];
106106

107107
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
108108
{
109-
int w = 0;
110-
int ret;
111109
int idx = 0;
112110
uint32_t page_address;
113111
uint32_t offset;
114112
int size;
115113
while (idx < len) {
116114
page_address = ((address + idx) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE;
117-
offset = address - page_address;
115+
if(address > page_address)
116+
offset = address - page_address;
117+
else
118+
offset = 0;
118119
size = FLASH_PAGE_SIZE - offset;
119120
if (size > (len - idx))
120121
size = len - idx;
121-
122122
if (size > 0) {
123123
memcpy(flash_page_cache, (void *)page_address, FLASH_PAGE_SIZE);
124124
memcpy(flash_page_cache + offset, data + idx, size);

0 commit comments

Comments
 (0)