Skip to content

Commit 8466d76

Browse files
committed
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.
1 parent 6839fff commit 8466d76

File tree

3 files changed

+14
-46
lines changed

3 files changed

+14
-46
lines changed

atmel-samd/mphalport.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,6 @@
2222

2323
extern struct usart_module usart_instance;
2424

25-
// Read by main to know when USB is connected.
26-
volatile bool mp_msc_enabled = false;
27-
bool mp_msc_enable(void) {
28-
mp_msc_enabled = true;
29-
return true;
30-
}
31-
32-
void mp_msc_disable(void) {
33-
mp_msc_enabled = false;
34-
}
35-
36-
bool mp_cdc_enable(uint8_t port) {
37-
mp_cdc_enabled = false;
38-
return true;
39-
}
40-
41-
void mp_cdc_disable(uint8_t port) {
42-
mp_cdc_enabled = false;
43-
}
44-
45-
volatile bool reset_on_disconnect = false;
46-
47-
void usb_dtr_notify(uint8_t port, bool set) {
48-
mp_cdc_enabled = set;
49-
if (!set && reset_on_disconnect) {
50-
reset_to_bootloader();
51-
}
52-
}
53-
54-
void usb_rts_notify(uint8_t port, bool set) {
55-
return;
56-
}
57-
58-
// void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding) {
59-
// reset_on_disconnect = coding->dwDTERate == 1200;
60-
// }
61-
6225
int mp_hal_stdin_rx_chr(void) {
6326
for (;;) {
6427
#ifdef MICROPY_VM_HOOK_LOOP

atmel-samd/reset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "flash_api.h"
2827
#include "reset.h"
2928

3029
#include "include/sam.h"
30+
#include "supervisor/filesystem.h"
3131

3232
// Copied from inc/uf2.h in https://github.com/Microsoft/uf2-samd21
3333
#ifdef SAMD21
@@ -40,7 +40,7 @@
4040
#define DBL_TAP_MAGIC 0xf01669ef // Randomly selected, adjusted to have first and last bit set
4141

4242
void reset_to_bootloader(void) {
43-
flash_flush();
43+
filesystem_flush();
4444
*DBL_TAP_PTR = DBL_TAP_MAGIC;
4545
NVIC_SystemReset();
4646
}

atmel-samd/usb.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "hpl/gclk/hpl_gclk_base.h"
4040

4141
#include "lib/utils/interrupt_char.h"
42+
#include "reset.h"
4243

4344
#include "supervisor/shared/autoreload.h"
4445

@@ -153,22 +154,25 @@ static bool usb_device_cb_bulk_in(const uint8_t ep, const enum usb_xfer_code rc,
153154
return false;
154155
}
155156

157+
volatile bool reset_on_disconnect = false;
158+
156159
static bool usb_device_cb_state_c(usb_cdc_control_signal_t state)
157160
{
158-
//uint8_t buf[64];
159161
if (state.rs232.DTR) {
160-
// Start Rx and throw away packet.
161-
//cdcdf_acm_read((uint8_t *)buf, 64);
162+
} else if (!state.rs232.DTR && reset_on_disconnect) {
163+
reset_to_bootloader();
162164
}
163165

164166
/* No error. */
165167
return false;
166168
}
167169

168-
// static void usbd_sof_event(void)
169-
// {
170-
// // Triggers button state checks and HID response.
171-
// }
170+
static bool usb_device_cb_line_coding_c(const usb_cdc_line_coding_t* coding)
171+
{
172+
reset_on_disconnect = coding->dwDTERate == 1200;
173+
/* Ok to change. */
174+
return true;
175+
}
172176

173177
void init_usb(void) {
174178
init_hardware();
@@ -195,6 +199,7 @@ static inline bool cdc_enabled(void) {
195199
cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)usb_device_cb_bulk_out);
196200
cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)usb_device_cb_bulk_in);
197201
cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c);
202+
cdcdf_acm_register_callback(CDCDF_ACM_CB_LINE_CODING_C, (FUNC_PTR)usb_device_cb_line_coding_c);
198203
mp_cdc_enabled = true;
199204

200205
// Ignored read.

0 commit comments

Comments
 (0)