Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Essential Hub stuck after exiting DFU Mode without USB cable. #821

Closed
laurensvalk opened this issue Dec 1, 2022 · 2 comments
Closed
Assignees
Labels
bug Something isn't working platform: essentialhub Issues related to the LEGO SPIKE Essential hub software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)

Comments

@laurensvalk
Copy link
Member

Describe the bug
If you enter DFU mode on the Essential Hub but you forget to plug in USB, the hub won't turn on after you release the button.

You have to remove the battery first and try again. Then everything works normally.

Since this doesn't happen with the stock firmware, this is probably not a bug in the bootloader as we initially thought.

So we may be able to fix it in the firmware.

To reproduce
Steps to reproduce the behavior:

  1. Press and hold the button until the link blinks pink.
  2. Release the button.

Expected behavior
Boot Pybricks normally, just like it normally boots the stock firmware if that is installed.

@laurensvalk laurensvalk added bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) platform: essentialhub Issues related to the LEGO SPIKE Essential hub labels Dec 1, 2022
@laurensvalk
Copy link
Member Author

This partially fixes it:

diff --git a/lib/pbio/platform/essential_hub/platform.c b/lib/pbio/platform/essential_hub/platform.c
index 117da2f2..589c7a88 100644
--- a/lib/pbio/platform/essential_hub/platform.c
+++ b/lib/pbio/platform/essential_hub/platform.c
@@ -692,6 +692,15 @@ void SystemInit(void) {
     // since the firmware starts at 0x08008000, we need to set the vector table offset
     SCB->VTOR = (uint32_t)&_fw_isr_vector_src;
 
+    // Keep main power on (PB1)
+    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;
+    GPIO_InitTypeDef gpio_init = {
+        .Pin = GPIO_PIN_1,
+        .Mode = GPIO_MODE_OUTPUT_PP,
+    };
+    HAL_GPIO_Init(GPIOB, &gpio_init);
+    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
+
     // bootloader disables interrupts
     __enable_irq();
 
@@ -722,19 +731,11 @@ void SystemInit(void) {
     HAL_RCC_ClockConfig(&clk_init, FLASH_LATENCY_5);
 
     // enable clocks
-    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN |
+    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOCEN |
         RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_DMA1EN | RCC_AHB1ENR_DMA2EN;
     RCC->APB1ENR |= RCC_APB1ENR_USART2EN | RCC_APB1ENR_USART3EN | RCC_APB1ENR_UART5EN |
         RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN | RCC_APB1ENR_TIM4EN |
         RCC_APB1ENR_I2C3EN | RCC_APB1ENR_FMPI2C1EN | RCC_APB1ENR_SPI2EN;
     RCC->APB2ENR |= RCC_APB2ENR_TIM8EN | RCC_APB2ENR_ADC1EN | RCC_APB2ENR_SYSCFGEN;
     RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
-
-    // Keep main power on (PB1)
-    GPIO_InitTypeDef gpio_init = {
-        .Pin = GPIO_PIN_1,
-        .Mode = GPIO_MODE_OUTPUT_PP,
-    };
-    HAL_GPIO_Init(GPIOB, &gpio_init);
-    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
 }

But it is only fixed if you reboot after just installing the firmware. If you remove the batteries at least once, then it isn't fixed.

@laurensvalk
Copy link
Member Author

Actually, maybe this is just coincidental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform: essentialhub Issues related to the LEGO SPIKE Essential hub software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)
Projects
None yet
Development

No branches or pull requests

2 participants