2022-08-30 10:01:12 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-11-16 05:23:48 -06:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#define FLASH_BSY (1 << 0)
|
|
|
|
#define FLASH_PGERR (1 << 2)
|
|
|
|
#define FLASH_WRPRTERR (1 << 4)
|
|
|
|
|
|
|
|
void flash_write(volatile uint32_t *flash_sr,
|
|
|
|
uint32_t hwords_count,
|
|
|
|
uint16_t *buffer,
|
|
|
|
uint16_t *target_addr) __attribute__((naked));
|
|
|
|
|
|
|
|
void flash_write(volatile uint32_t *flash_sr,
|
|
|
|
uint32_t hwords_count,
|
|
|
|
uint16_t *buffer,
|
|
|
|
uint16_t *target_addr)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
*target_addr = *buffer++;
|
|
|
|
|
|
|
|
register uint32_t sr;
|
|
|
|
do {
|
|
|
|
sr = *flash_sr;
|
|
|
|
} while (sr & FLASH_BSY);
|
|
|
|
|
|
|
|
if (sr & (FLASH_PGERR | FLASH_WRPRTERR))
|
|
|
|
break;
|
|
|
|
|
|
|
|
target_addr++;
|
|
|
|
} while (--hwords_count);
|
|
|
|
asm("ebreak");
|
|
|
|
}
|