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:
parent
6839fff313
commit
8466d760f9
@ -22,43 +22,6 @@
|
|||||||
|
|
||||||
extern struct usart_module usart_instance;
|
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) {
|
int mp_hal_stdin_rx_chr(void) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
#ifdef MICROPY_VM_HOOK_LOOP
|
||||||
|
@ -24,10 +24,10 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "flash_api.h"
|
|
||||||
#include "reset.h"
|
#include "reset.h"
|
||||||
|
|
||||||
#include "include/sam.h"
|
#include "include/sam.h"
|
||||||
|
#include "supervisor/filesystem.h"
|
||||||
|
|
||||||
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
|
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
|
||||||
#ifdef SAMD21
|
#ifdef SAMD21
|
||||||
@ -40,7 +40,7 @@
|
|||||||
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
|
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
|
||||||
|
|
||||||
void reset_to_bootloader(void) {
|
void reset_to_bootloader(void) {
|
||||||
flash_flush();
|
filesystem_flush();
|
||||||
*DBL_TAP_PTR = DBL_TAP_MAGIC;
|
*DBL_TAP_PTR = DBL_TAP_MAGIC;
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "hpl/gclk/hpl_gclk_base.h"
|
#include "hpl/gclk/hpl_gclk_base.h"
|
||||||
|
|
||||||
#include "lib/utils/interrupt_char.h"
|
#include "lib/utils/interrupt_char.h"
|
||||||
|
#include "reset.h"
|
||||||
|
|
||||||
#include "supervisor/shared/autoreload.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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile bool reset_on_disconnect = false;
|
||||||
|
|
||||||
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
|
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
|
||||||
{
|
{
|
||||||
//uint8_t buf[64];
|
|
||||||
if (state.rs232.DTR) {
|
if (state.rs232.DTR) {
|
||||||
// Start Rx and throw away packet.
|
} else if (!state.rs232.DTR && reset_on_disconnect) {
|
||||||
//cdcdf_acm_read((uint8_t *)buf, 64);
|
reset_to_bootloader();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No error. */
|
/* No error. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static void usbd_sof_event(void)
|
static bool usb_device_cb_line_coding_c(const usb_cdc_line_coding_t* coding)
|
||||||
// {
|
{
|
||||||
// // Triggers button state checks and HID response.
|
reset_on_disconnect = coding->dwDTERate == 1200;
|
||||||
// }
|
/* Ok to change. */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void init_usb(void) {
|
void init_usb(void) {
|
||||||
init_hardware();
|
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_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_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_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;
|
mp_cdc_enabled = true;
|
||||||
|
|
||||||
// Ignored read.
|
// Ignored read.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user