diff --git a/board/bootstub.c b/board/bootstub.c index 8f3d385b..e23e9a29 100644 --- a/board/bootstub.c +++ b/board/bootstub.c @@ -10,9 +10,14 @@ #endif #include "libc.h" -#include "drivers/spi.h" #include "gpio.h" + +void spi_cb_rx(uint8_t *data, int len) {}; + +#include "drivers/drivers.h" +#include "drivers/spi.h" + #include "crypto/rsa.h" #include "crypto/sha.h" @@ -20,30 +25,23 @@ #include "spi_flasher.h" -void spi_cb_rx(uint8_t *data, int len) {}; - void __initialize_hardware_early() { early(); + + if (is_entering_bootmode) { + spi_flasher(); + } } void fail() { #ifdef PANDA - volatile int i; // detect usb host - GPIOA->PUPDR |= GPIO_PUPDR_PUPDR11_0; - for (i=0;iIDR & (1 << 11); - GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR11_0); + int no_usb = detect_with_pull(GPIOA, 11, PULL_UP); if (no_usb) { // no usb host, go to SPI flasher spi_flasher(); - } else { - // has usb host, go to USB flasher - enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; - NVIC_SystemReset(); } - #else enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC; NVIC_SystemReset(); diff --git a/board/gpio.h b/board/gpio.h index 8ad097f3..3066fa8f 100644 --- a/board/gpio.h +++ b/board/gpio.h @@ -243,6 +243,7 @@ void set_esp_mode(int mode) { set_gpio_output(GPIOC, 5, 0); break; case ESP_ENABLED: + // ESP ON set_gpio_output(GPIOC, 14, 1); set_gpio_output(GPIOC, 5, 1); break; @@ -419,12 +420,6 @@ void early() { } else { set_esp_mode(ESP_ENABLED); } - - #ifdef BOOTSTUB - if (is_entering_bootmode) { - spi_flasher(); - } - #endif #endif