summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-08-14 15:23:19 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2022-08-14 15:23:32 -0500
commit7fc4395298ae66c6a735e25f93eb86e26e08f3a2 (patch)
tree7e210e4073b8867740ccb951f2c5b7f36acbaebc
parente790a025787e0e1aa59b98b95e194cf4318d1578 (diff)
downloadSensor-Watch-7fc4395298ae66c6a735e25f93eb86e26e08f3a2.tar.gz
Sensor-Watch-7fc4395298ae66c6a735e25f93eb86e26e08f3a2.tar.bz2
Sensor-Watch-7fc4395298ae66c6a735e25f93eb86e26e08f3a2.zip
add watch_reset_to_bootloader function (resolves #81)
-rw-r--r--watch-library/hardware/watch/watch.c6
-rw-r--r--watch-library/shared/watch/watch.h4
-rw-r--r--watch-library/simulator/watch/watch.c4
3 files changed, 14 insertions, 0 deletions
diff --git a/watch-library/hardware/watch/watch.c b/watch-library/hardware/watch/watch.c
index b3dc4e8d..7bda9257 100644
--- a/watch-library/hardware/watch/watch.c
+++ b/watch-library/hardware/watch/watch.c
@@ -45,3 +45,9 @@ bool watch_is_buzzer_or_led_enabled(void){
bool watch_is_usb_enabled(void) {
return USB->DEVICE.CTRLA.bit.ENABLE;
}
+
+void watch_reset_to_bootloader(void) {
+ volatile uint32_t *dbl_tap_ptr = ((volatile uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 4));
+ *dbl_tap_ptr = 0xf01669ef; // from the UF2 bootloaer: uf2.h line 255
+ NVIC_SystemReset();
+}
diff --git a/watch-library/shared/watch/watch.h b/watch-library/shared/watch/watch.h
index b94d36fb..7526d03a 100644
--- a/watch-library/shared/watch/watch.h
+++ b/watch-library/shared/watch/watch.h
@@ -80,6 +80,10 @@ bool watch_is_buzzer_or_led_enabled(void);
*/
bool watch_is_usb_enabled(void);
+/** @brief Resets in the UF2 bootloader mode
+ */
+void watch_reset_to_bootloader(void);
+
/** @brief Reads up to len bytes from the USB serial.
* @param file ignored, you can pass in 0
* @param ptr pointer to a buffer of at least len bytes
diff --git a/watch-library/simulator/watch/watch.c b/watch-library/simulator/watch/watch.c
index 749651af..4e89f3d3 100644
--- a/watch-library/simulator/watch/watch.c
+++ b/watch-library/simulator/watch/watch.c
@@ -7,3 +7,7 @@ bool watch_is_buzzer_or_led_enabled(void) {
bool watch_is_usb_enabled(void) {
return true;
}
+
+void watch_reset_to_bootloader(void) {
+ // No bootloader in the simulator; nothing to do here
+}