bootloader: flash page erase is on-demand, now fits in 2K

Flash pages are only erased as needed during the flash routine, which makes flashing faster as well as making the transfer consistent.

Later datasheets have the flash clock set to 2MHz. I've set it to 2MHz here. I may undo this change later depending on how slow loading a 14K firmware feels.

Was able to save enough space to reduce bootloader size from almost 2.5K to 2K exactly. Adjusted flash offsets to start from 0x800.

GPIO values are now mostly reset to power-on defaults.

Fixed some formatting. Removed dead code.
This commit is contained in:
true
2023-06-25 05:01:16 -07:00
parent d5cbabf830
commit 46a3ab6007
15 changed files with 336 additions and 249 deletions

View File

@@ -15,8 +15,9 @@
#define FLASH_SIZE 16384 // size of overall flash available on MCU
#define FLASH_ERASE_PAGE_SIZE ((uint16_t)0x80) // erase page size
#define FLASH_ERASE_PAGE_MASK 0x7f // bitmask of page size
#define USER_APP_START_ADDR ((uint32_t)FLASH_BASE + 0xa00) // 2560 bytes (20 pages) rsvd for bootloader
#define USER_APP_START_ADDR ((uint32_t)FLASH_BASE + 0x800) // 2048 bytes (16 pages) rsvd for bootloader
#define USER_APP_END_ADDR ((uint32_t)FLASH_BASE + FLASH_SIZE)
@@ -32,7 +33,7 @@ typedef enum {
BL_flash_status flash_erase_user_app();
BL_flash_status flash_erase_page(uint32_t addr);
BL_flash_status flash_write(uint32_t addr, uint8_t *data, uint16_t length);
void jump_to_user_app();

View File

@@ -9,7 +9,7 @@
#define CODE_INC_USART_H_
#define COMM_TIMEOUT 512000;
#define COMM_TIMEOUT 0xffff;
@@ -24,7 +24,7 @@ typedef enum {
void comm_init();
BL_comm_status comm_rx(uint8_t *data, uint16_t length);
BL_comm_status comm_tx_str(uint8_t *data);
BL_comm_status comm_tx_str(char *data);
BL_comm_status comm_tx_byte(uint8_t data);

View File

@@ -29,7 +29,6 @@
void user_io_init();
void user_led_init();
void user_led_set(uint8_t lit);

View File

@@ -72,7 +72,9 @@ typedef enum {
X_ERROR = 0xFFu /**< Generic error. */
} BL_xmodem_status;
void xmodem_receive(void);
BL_xmodem_status xmodem_receive(void);