| 46 | } |
| 47 | |
| 48 | static int write(long offset, const uint8_t *buf, size_t size) |
| 49 | { |
| 50 | size_t i; |
| 51 | uint32_t addr = OCFLASH_ADDR + offset; |
| 52 | |
| 53 | FLASH->KEYR = 0x45670123; |
| 54 | FLASH->KEYR = 0xCDEF89AB; |
| 55 | FLASH->SR = 0x00000001 | 0x00000004 | 0x00000010; |
| 56 | FLASH->CR |= 0x1; |
| 57 | |
| 58 | i = 0; |
| 59 | while (i < size) |
| 60 | { |
| 61 | *(__IO uint16_t *)addr = *buf | *(buf + 1) << 8; |
| 62 | addr = addr + 2; |
| 63 | buf += 2; |
| 64 | i += 2; |
| 65 | } |
| 66 | //Lock flash |
| 67 | FLASH->CR |= 0x00000080; |
| 68 | |
| 69 | return size; |
| 70 | } |
| 71 | |
| 72 | static int erase(long offset, size_t size) |
| 73 | { |
no outgoing calls