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.
This commit is contained in:
Scott Shawcroft 2017-09-27 18:37:54 -07:00 committed by Scott Shawcroft
parent 6839fff313
commit 8466d760f9
3 changed files with 14 additions and 46 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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.