Skip to content

Commit c16740b

Browse files
committed
drv/core: move enable interrupts to driver init
On hubs with the USB/DFU bootloaders, interrupts are disabled by the `cpsid` instruction in the bootloader before jumping to the main firmware. We were reenabling them in early boot. However, this caused the Essential hub to hang if you press and hold the button to activate the bootloader without connecting USB then release the button after the lights start flashing. This is fixed by moving the enable until after all of the driver init functions have run as in the official LEGO firmware. Fixes: pybricks/support#821
1 parent 4f9885d commit c16740b

File tree

6 files changed

+11
-6
lines changed

6 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
### Fixed
88
- Fixed SPIKE/MINDSTORMS hubs advertising after disconnect while user program
99
is still running ([support#849]).
10+
- Fixed Essential hub hanging on boot when bootloader entered but USB cable
11+
not connected ([support#821]).
1012

13+
[support#821]: https://github.com/pybricks/support/issues/821
1114
[support#849]: https://github.com/pybricks/support/issues/849
1215

1316
## [3.2.0c1] - 2022-12-09

lib/pbio/drv/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ void pbdrv_init(void) {
4747
pbdrv_usb_init();
4848
pbdrv_watchdog_init();
4949

50+
// Some hubs have a bootloader that disables interrupts. Has to be done
51+
// here otherwise Essential hub can hang on boot if it is earlier.
52+
#if PBDRV_CONFIG_INIT_ENABLE_INTERRUPTS_ARM
53+
__asm volatile ("cpsie i" : : : "memory");
54+
#endif
55+
5056
while (pbdrv_init_busy()) {
5157
process_run();
5258
}

lib/pbio/platform/essential_hub/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,4 @@
111111
#define PBDRV_CONFIG_NUM_MOTOR_CONTROLLER (2)
112112

113113
#define PBDRV_CONFIG_SYS_CLOCK_RATE 96000000
114+
#define PBDRV_CONFIG_INIT_ENABLE_INTERRUPTS_ARM (1)

lib/pbio/platform/essential_hub/platform.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,6 @@ void SystemInit(void) {
692692
// since the firmware starts at 0x08008000, we need to set the vector table offset
693693
SCB->VTOR = (uint32_t)&_fw_isr_vector_src;
694694

695-
// bootloader disables interrupts
696-
__enable_irq();
697-
698695
// Using external 16Mhz oscillator
699696
RCC_OscInitTypeDef osc_init;
700697
osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSE;

lib/pbio/platform/prime_hub/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,4 @@
130130
#define PBDRV_CONFIG_NUM_MOTOR_CONTROLLER (6)
131131

132132
#define PBDRV_CONFIG_SYS_CLOCK_RATE 96000000
133+
#define PBDRV_CONFIG_INIT_ENABLE_INTERRUPTS_ARM (1)

lib/pbio/platform/prime_hub/platform.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,6 @@ void SystemInit(void) {
985985
// since the firmware starts at 0x08008000, we need to set the vector table offset
986986
SCB->VTOR = (uint32_t)&_fw_isr_vector_src;
987987

988-
// bootloader disables interrupts
989-
__enable_irq();
990-
991988
// Using external 16Mhz oscillator
992989
RCC_OscInitTypeDef osc_init;
993990
osc_init.OscillatorType = RCC_OSCILLATORTYPE_HSE;

0 commit comments

Comments
 (0)