We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 836a13a commit 8187f9fCopy full SHA for 8187f9f
1 file changed
hal/lpc.c
@@ -106,19 +106,19 @@ static uint8_t flash_page_cache[FLASH_PAGE_SIZE];
106
107
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
108
{
109
- int w = 0;
110
- int ret;
111
int idx = 0;
112
uint32_t page_address;
113
uint32_t offset;
114
int size;
115
while (idx < len) {
116
page_address = ((address + idx) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE;
117
- offset = address - page_address;
+ if(address > page_address)
+ offset = address - page_address;
+ else
118
+ offset = 0;
119
size = FLASH_PAGE_SIZE - offset;
120
if (size > (len - idx))
121
size = len - idx;
-
122
if (size > 0) {
123
memcpy(flash_page_cache, (void *)page_address, FLASH_PAGE_SIZE);
124
memcpy(flash_page_cache + offset, data + idx, size);
0 commit comments