Skip to content

Commit e7806d3

Browse files
committed
Bootloader for test rig
1 parent 80bddb5 commit e7806d3

File tree

7 files changed

+42
-2
lines changed

7 files changed

+42
-2
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TARGETS = firmware boot test_rig
1+
TARGETS = firmware boot test_rig test_rig_boot
22
BUILD = build
33

44
all: $(TARGETS)

boot/boot.h

+7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99

1010
#pragma once
1111
#include "class/dfu/dfu.h"
12+
13+
#ifdef TEST_RIG_BOOTLOADER
14+
#include "test_rig/test_rig_board.h"
15+
#define PIN_BTN PIN_START_BUTTON
16+
#define PIN_LED DIGITAL_PINS[4]
17+
#else
1218
#include "common/board.h"
19+
#endif
1320

1421
#define GCLK_SYSTEM 0
1522
#define DFU_INTF 0

boot/main.c

+4
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,25 @@ void led_task() {
8282
}
8383

8484
void bootloader_main() {
85+
#ifndef TEST_RIG_BOOTLOADER
8586
if (PM->RCAUSE.reg & (PM_RCAUSE_POR | PM_RCAUSE_BOD12 | PM_RCAUSE_BOD33)) {
8687
// On powerup, power off MT7620
8788
pin_low(PIN_SOC_RST);
8889
pin_out(PIN_SOC_RST);
8990
}
91+
#endif
9092

9193
clock_init_usb(GCLK_SYSTEM);
9294
init_systick();
9395
nvm_init();
9496

97+
#ifndef TEST_RIG_BOOTLOADER
9598
pin_low(PORT_A.power);
9699
pin_out(PORT_A.power);
97100

98101
pin_low(PORT_B.power);
99102
pin_out(PORT_B.power);
103+
#endif
100104

101105
pin_out(PIN_LED);
102106

boot/usb.c

+5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ const USB_DeviceDescriptor device_descriptor = {
2323
.bDeviceProtocol = USB_CSCP_NoDeviceProtocol,
2424

2525
.bMaxPacketSize0 = 64,
26+
#ifdef TEST_RIG_BOOTLOADER
27+
.idVendor = 0x59E3,
28+
.idProduct = 0xCDA7,
29+
#else
2630
.idVendor = 0x1209,
2731
.idProduct = 0x7551,
32+
#endif
2833
.bcdDevice = 0x0002,
2934

3035
.iManufacturer = 0x01,

test_rig.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ $(TARGET)_SRC += \
1313
test_rig/button.c \
1414

1515
$(TARGET)_DEFINE += -D __SAMD21J18A__
16-
$(TARGET)_LDSCRIPT = deps/sam0/linker_scripts/samd21/gcc/samd21j18a_flash.ld
16+
$(TARGET)_LDSCRIPT = common/samd21g15a_firmware_partition.ld

test_rig/usb.c

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#define REQ_INFO 0x30
1010
#define REQ_INFO_GIT_HASH 0x0
11+
#define REQ_BOOT 0xBB
1112

1213
USB_ENDPOINTS(5);
1314

@@ -215,6 +216,12 @@ void req_info(uint16_t wIndex) {
215216
return usb_ep0_in(len);
216217
}
217218

219+
void req_boot() {
220+
wdt_reset(GCLK_32K);
221+
usb_ep0_out();
222+
return usb_ep0_in(0);
223+
}
224+
218225
void usb_cb_control_setup(void) {
219226
uint8_t recipient = usb_setup.bmRequestType & USB_REQTYPE_RECIPIENT_MASK;
220227
if (recipient == USB_RECIPIENT_DEVICE) {
@@ -228,6 +235,7 @@ void usb_cb_control_setup(void) {
228235
return usb_control_req_digital_read_all();
229236
case ANALOG_SAMPLE:
230237
return usb_control_req_analog_read(usb_setup.wIndex, usb_setup.wValue);
238+
case REQ_BOOT: return req_boot();
231239
}
232240
} else if (recipient == USB_RECIPIENT_INTERFACE) {
233241
}

test_rig_boot.mk

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TARGET := test_rig_boot
2+
3+
include common.mk
4+
include usb.mk
5+
6+
$(TARGET)_INCLUDE += \
7+
-I boot \
8+
9+
$(TARGET)_SRC += \
10+
boot/main.c \
11+
boot/usb.c \
12+
$(USB_PATH)/class/dfu/dfu.c
13+
14+
$(TARGET)_LDSCRIPT = deps/sam0/linker_scripts/samd21/gcc/samd21j18a_flash.ld
15+
$(TARGET)_DEFINE += -D __SAMD21J18A__
16+
$(TARGET)_DEFINE += -D TEST_RIG_BOOTLOADER

0 commit comments

Comments
 (0)