Skip to content

Commit

Permalink
Merge pull request #12 from r2axz/r2axz-fix-flash-config-storage
Browse files Browse the repository at this point in the history
Fix Storing Configuration
  • Loading branch information
r2axz authored Nov 25, 2020
2 parents c299798 + 81f917f commit d6904bf
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions device_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ void device_config_save() {
uint16_t *src_word_p = (uint16_t*)&current_device_config;
uint16_t *dst_word_p;
size_t bytes_left = sizeof(current_device_config);
while (config_pages--) {
while (config_pages-- && (last_config_magic == 0)) {
const device_config_t *stored_config = (device_config_t*)config_page;
if ((stored_config->magic == DEVICE_CONFIG_MAGIC) &&
(device_config_calc_crc(stored_config) == stored_config->crc)) {
last_config_magic = (uint16_t*)&stored_config->magic;
} else {
break;
}
config_page += DEVICE_CONFIG_PAGE_SIZE;
}
if (config_pages == 0) {
if (config_page == ((uint8_t*)DEVICE_CONFIG_BASE_ADDR + (DEVICE_CONFIG_NUM_PAGES * DEVICE_CONFIG_PAGE_SIZE))) {
config_page = (uint8_t*)DEVICE_CONFIG_BASE_ADDR;
}
dst_word_p = (uint16_t*)config_page;
Expand Down

0 comments on commit d6904bf

Please sign in to comment.