uint16_t dev_id = stm_dev_id();
switch (dev_id) {
- case 0x440: /* stm32f05x */
- case 0x444: /* stm32f03x */
- case 0x445: /* stm32f04x */
+ case 0x412: /* low-density devices */
+ case 0x410: /* medium-density devices */
return 1024;
- case 0x442: /* stm32f09x */
- case 0x448: /* stm32f07x */
+ case 0x414: /* high-density devices */
+ case 0x430: /* XL-density devices */
+ case 0x418: /* Connectivity devices */
return 2048;
}
ao_panic(AO_PANIC_FLASH);
}
static void __attribute__ ((section(".sdata2.flash"), noinline))
-_ao_flash_page(uint16_t *dst, uint16_t *src)
+_ao_flash_page(uint16_t *dst, uint16_t *src, unsigned int shorts)
{
uint8_t i;
stm_flash.cr |= (1 << STM_FLASH_CR_PG);
- for (i = 0; i < 128; i++) {
+ for (i = 0; i < shorts; i++) {
*dst++ = *src++;
ao_flash_wait_bsy();
}
ao_arch_block_interrupts();
ao_flash_unlock();
- _ao_flash_page((uint16_t *) page, (uint16_t *) src);
+ _ao_flash_page((uint16_t *) page, (uint16_t *) src, 128);
+
+ ao_flash_lock();
+ ao_arch_release_interrupts();
+}
+
+/* Stores less than a full page while still smashing the full page */
+void
+ao_flash_bytes(void *page, void *src, size_t size)
+{
+ unsigned int shorts = (unsigned int) ((size + 1) >> 1);
+
+ ao_flash_erase_page(page);
+
+ ao_arch_block_interrupts();
+ ao_flash_unlock();
+
+ _ao_flash_page((uint16_t *) page, (uint16_t *) src, shorts);
ao_flash_lock();
ao_arch_release_interrupts();