8000 atmel-samd: Reboot to bootloader when a 1200 baud serial connection is · sparkfun/circuitpython@5d732f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d732f4

Browse files
committed
atmel-samd: Reboot to bootloader when a 1200 baud serial connection is
closed. This is how Arduino triggers the bootloader.
1 parent 0c4b273 commit 5d732f4

File tree

12 files changed

+127
-26
lines changed

12 files changed

+127
-26
lines changed

atmel-samd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ SRC_C = \
190190
main.c \
191191
moduos.c \
192192
mphalport.c \
193+
reset.c \
193194
samd21_pins.c \
194195
shared_dma.c \
195196
rgb_led_status.c \

atmel-samd/boards/arduino_zero/conf_usb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/circuitplayground_express/conf_usb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/feather_m0_adalogger/conf_usb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/feather_m0_basic/conf_usb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/feather_m0_express/conf_usb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/gemma_m0/conf_usb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/metro_m0_express/conf_usb.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -19,7 +21,7 @@
1921
#endif
2022

2123
#ifndef USB_DEVICE_PRODUCT_NAME
22-
# define USB_DEVICE_PRODUCT_NAME "Metro M0 with Flash (Experimental)"
24+
# define USB_DEVICE_PRODUCT_NAME "Metro M0 Express"
2325
#endif
2426
// #define USB_DEVICE_SERIAL_NAME "12...EF"
2527
#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number
@@ -55,7 +57,8 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
61+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5962
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6063
void usb_dtr_notify(uint8_t port, bool set);
6164
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/boards/trinket_m0/conf_usb.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdbool.h>
33
#include <stdint.h>
44

5+
#include "asf/common/services/usb/class/cdc/usb_protocol_cdc.h"
6+
57
#ifndef CONF_USB_H_INCLUDED
68
#define CONF_USB_H_INCLUDED
79

@@ -55,7 +57,9 @@ extern void mp_cdc_disable(uint8_t port);
5557

5658
#define UDI_CDC_RX_NOTIFY(port) usb_rx_notify()
5759
void usb_rx_notify(void);
58-
#define UDI_CDC_SET_CODING_EXT(port,cfg)
60+
61+
#define UDI_CDC_SET_CODING_EXT(port,cfg) usb_coding_notify(port, cfg)
62+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding);
5963
#define UDI_CDC_SET_DTR_EXT(port,set) usb_dtr_notify(port, set)
6064
void usb_dtr_notify(uint8_t port, bool set);
6165
#define UDI_CDC_SET_RTS_EXT(port,set) usb_rts_notify(port, set)

atmel-samd/mphalport.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,42 @@ extern struct usart_module usart_instance;
3939

4040
// Read by main to know when USB is connected.
4141
volatile bool mp_msc_enabled = false;
42-
bool mp_msc_enable()
43-
{
44-
mp_msc_enabled = true;
45-
return true;
42+
bool mp_msc_enable() {
43+
mp_msc_enabled = true;
44+
return true;
4645
}
4746

48-
void mp_msc_disable()
49-
{
50-
mp_msc_enabled = false;
47+
void mp_msc_disable() {
48+
mp_msc_enabled = false;
5149
}
5250

53-
bool mp_cdc_enable(uint8_t port)
54-
{
55-
mp_cdc_enabled = false;
56-
return true;
51+
bool mp_cdc_enable(uint8_t port) {
52+
mp_cdc_enabled = false;
53+
return true;
5754
}
5855

59-
void mp_cdc_disable(uint8_t port)
60-
{
61-
mp_cdc_enabled = false;
56+
void mp_cdc_disable(uint8_t port) {
57+
mp_cdc_enabled = false;
6258
}
6359

60+
volatile bool reset_on_disconnect = false;
61+
6462
void usb_dtr_notify(uint8_t port, bool set) {
65-
mp_cdc_enabled = set;
63+
mp_cdc_enabled = set;
64+
if (!set && reset_on_disconnect) {
65+
reset_to_bootloader();
66+
}
6667
}
6768

6869
void usb_rts_notify(uint8_t port, bool set) {
6970
return;
7071
}
7172

72-
void usb_rx_notify(void)
73-
{
73+
void usb_coding_notify(uint8_t port, usb_cdc_line_coding_t* coding) {
74+
reset_on_disconnect = coding->dwDTERate == 1200;
75+
}
76+
77+
void usb_rx_notify(void) {
7478
irqflags_t flags;
7579
if (mp_cdc_enabled) {
7680
while (udi_cdc_is_rx_ready()) {

0 commit comments

Comments
 (0)
0