From 8466d760f9990a0fbd735ebdc703cfb9a223805a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 27 Sep 2017 18:37:54 -0700 Subject: 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. --- atmel-samd/mphalport.c | 37 ------------------------------------- atmel-samd/reset.c | 4 ++-- atmel-samd/usb.c | 19 ++++++++++++------- 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. -- cgit v1.2.3