diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-05-06 17:06:27 -0400 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-05-06 17:12:14 -0400 |
commit | d4ebe64af05e2fa163bcea0dd699ae9c8934cc6f (patch) | |
tree | 0f9db98200a7fc0028ef2549ddfba15918b7465d /apps/eeprom-emulation-upgrade | |
parent | 21026c8eb750b35c07bb3ae9fb043fd01e502a06 (diff) | |
download | Sensor-Watch-d4ebe64af05e2fa163bcea0dd699ae9c8934cc6f.tar.gz Sensor-Watch-d4ebe64af05e2fa163bcea0dd699ae9c8934cc6f.tar.bz2 Sensor-Watch-d4ebe64af05e2fa163bcea0dd699ae9c8934cc6f.zip |
add support for a small filesystem on the watch
Diffstat (limited to 'apps/eeprom-emulation-upgrade')
-rwxr-xr-x | apps/eeprom-emulation-upgrade/Makefile | 10 | ||||
-rw-r--r-- | apps/eeprom-emulation-upgrade/app.c | 62 |
2 files changed, 72 insertions, 0 deletions
diff --git a/apps/eeprom-emulation-upgrade/Makefile b/apps/eeprom-emulation-upgrade/Makefile new file mode 100755 index 00000000..5534c178 --- /dev/null +++ b/apps/eeprom-emulation-upgrade/Makefile @@ -0,0 +1,10 @@ +TOP = ../.. +include $(TOP)/make.mk + +INCLUDES += \ + -I./ + +SRCS += \ + ./app.c + +include $(TOP)/rules.mk diff --git a/apps/eeprom-emulation-upgrade/app.c b/apps/eeprom-emulation-upgrade/app.c new file mode 100644 index 00000000..edd73e44 --- /dev/null +++ b/apps/eeprom-emulation-upgrade/app.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <peripheral_clk_config.h> +#include "watch.h" + +void app_init(void) { +} + +void app_wake_from_backup(void) { +} + +void app_setup(void) { + delay_ms(5000); + while (!(NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY)); + uint32_t user_row = (*((uint32_t *)NVMCTRL_AUX0_ADDRESS)); + uint8_t eeprom = (user_row >> NVMCTRL_FUSES_EEPROM_SIZE_Pos) & 7; + printf("User row read successfully: 0x%lx\n", user_row); + + if (eeprom != 1) { + user_row &= ~NVMCTRL_FUSES_EEPROM_SIZE_Msk; + user_row |= NVMCTRL_FUSES_EEPROM_SIZE(1); + if (NVMCTRL->STATUS.reg & NVMCTRL_STATUS_SB) { + printf("Secured bit was set; cannot perform upgrade.\n"); + return; + } + printf("EEPROM configuration was %d.\nApplying change...\n", eeprom); + + uint32_t temp = NVMCTRL->CTRLB.reg; // Backup settings + NVMCTRL->CTRLB.reg = temp | NVMCTRL_CTRLB_CACHEDIS; // Disable Cache + NVMCTRL->STATUS.reg |= NVMCTRL_STATUS_MASK; // Clear error flags + NVMCTRL->ADDR.reg = NVMCTRL_AUX0_ADDRESS / 2; // Set address, command will be issued elsewhere + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_EAR | NVMCTRL_CTRLA_CMDEX_KEY; // Erase the user page + while (!(NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY)); // Wait for NVM command to complete + NVMCTRL->STATUS.reg |= NVMCTRL_STATUS_MASK; // Clear error flags + NVMCTRL->ADDR.reg = NVMCTRL_AUX0_ADDRESS / 2; // Set address, command will be issued elsewhere + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_PBC | NVMCTRL_CTRLA_CMDEX_KEY; // Erase the page buffer before buffering new data + while (!(NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY)); // Wait for NVM command to complete + NVMCTRL->STATUS.reg |= NVMCTRL_STATUS_MASK; // Clear error flags + NVMCTRL->ADDR.reg = NVMCTRL_AUX0_ADDRESS / 2; // Set address, command will be issued elsewhere + *((uint32_t *)NVMCTRL_AUX0_ADDRESS) = user_row; // write the new fuse values to the memory buffer + NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMD_WAP | NVMCTRL_CTRLA_CMDEX_KEY; // Write the user page + NVMCTRL->CTRLB.reg = temp; // Restore settings + + printf("Done! Resetting...\n"); + delay_ms(1000); + NVIC_SystemReset(); + } else { + printf("EEPROM configuration was %d (8192 bytes). Upgrade successful!\n", eeprom); + } + printf("%d %d\n", eeprom, NVMCTRL->PARAM.bit.RWWEEP); +} + +void app_prepare_for_standby(void) { +} + +void app_wake_from_standby(void) { +} + +bool app_loop(void) { + return true; +} |