summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2017-09-27 18:37:54 -0700
committerScott Shawcroft <scott@tannewt.org>2017-09-27 21:58:54 -0400
commit8466d760f9990a0fbd735ebdc703cfb9a223805a (patch)
treeaa5acc064a3d4694d3f228154af1d22794abc9dd
parent6839fff31303463d5c7942387fa498895edf1abf (diff)
atmel-samd: Port baudrate reset to asf4 so we no longer hose Rosie.
We still won't be able to run tests but we will be reset into the bootloader to test other stuff.
-rw-r--r--atmel-samd/mphalport.c37
-rw-r--r--atmel-samd/reset.c4
-rw-r--r--atmel-samd/usb.c19
3 files changed, 14 insertions, 46 deletions
diff --git a/atmel-samd/mphalport.c b/atmel-samd/mphalport.c
index dc23c7190..201063929 100644
--- a/atmel-samd/mphalport.c
+++ b/atmel-samd/mphalport.c
@@ -22,43 +22,6 @@
extern struct usart_module usart_instance;
-// Read by main to know when USB is connected.
-volatile bool mp_msc_enabled = false;
-bool mp_msc_enable(void) {
- mp_msc_enabled = true;
- return true;
-}
-
-void mp_msc_disable(void) {
- mp_msc_enabled = false;
-}
-
-bool mp_cdc_enable(uint8_t port) {
- mp_cdc_enabled = false;
- return true;
-}
-
-void mp_cdc_disable(uint8_t port) {
- mp_cdc_enabled = false;
-}
-
-volatile bool reset_on_disconnect = false;
-
-void usb_dtr_notify(uint8_t port, bool set) {
- mp_cdc_enabled = set;
- if (!set && reset_on_disconnect) {
- reset_to_bootloader();
- }
-}
-
-void usb_rts_notify(uint8_t port, bool set) {
- return;
-}
-
-// void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding) {
-// reset_on_disconnect = coding->dwDTERate == 1200;
-// }
-
int mp_hal_stdin_rx_chr(void) {
for (;;) {
#ifdef MICROPY_VM_HOOK_LOOP
diff --git a/atmel-samd/reset.c b/atmel-samd/reset.c
index 0aef56d4c..ab940285b 100644
--- a/atmel-samd/reset.c
+++ b/atmel-samd/reset.c
@@ -24,10 +24,10 @@
* THE SOFTWARE.
*/
-#include "flash_api.h"
#include "reset.h"
#include "include/sam.h"
+#include "supervisor/filesystem.h"
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
#ifdef SAMD21
@@ -40,7 +40,7 @@
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
void reset_to_bootloader(void) {
- flash_flush();
+ filesystem_flush();
*DBL_TAP_PTR = DBL_TAP_MAGIC;
NVIC_SystemReset();
}
diff --git a/atmel-samd/usb.c b/atmel-samd/usb.c
index 11be282a2..e812283b9 100644
--- a/atmel-samd/usb.c
+++ b/atmel-samd/usb.c
@@ -39,6 +39,7 @@
#include "hpl/gclk/hpl_gclk_base.h"
#include "lib/utils/interrupt_char.h"
+#include "reset.h"
#include "supervisor/shared/autoreload.h"
@@ -153,22 +154,25 @@ static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc,
return false;
}
+volatile bool reset_on_disconnect = false;
+
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
{
- //uint8_t buf[64];
if (state.rs232.DTR) {
- // Start Rx and throw away packet.
- //cdcdf_acm_read((uint8_t *)buf, 64);
+ } else if (!state.rs232.DTR && reset_on_disconnect) {
+ reset_to_bootloader();
}
/* No error. */
return false;
}
-// static void usbd_sof_event(void)
-// {
-// // Triggers button state checks and HID response.
-// }
+static bool usb_device_cb_line_coding_c(const usb_cdc_line_coding_t* coding)
+{
+ reset_on_disconnect = coding->dwDTERate == 1200;
+ /* Ok to change. */
+ return true;
+}
void init_usb(void) {
init_hardware();
@@ -195,6 +199,7 @@ static inline bool cdc_enabled(void) {
cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out);
cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in);
cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c);
+ cdcdf_acm_register_callback(CDCDF_ACM_CB_LINE_CODING_C, (FUNC_PTR)usb_device_cb_line_coding_c);
mp_cdc_enabled = true;
// Ignored read.