add usb failure mode to st bootstub

master
Firmware Batman 2017-05-03 22:28:22 -07:00
parent 49c1e9c3da
commit be7d2ee397
3 changed files with 21 additions and 4 deletions

View File

@ -26,7 +26,21 @@ void __initialize_hardware_early() {
void fail() {
#ifdef PANDA
spi_flasher();
volatile int i;
// detect usb host
GPIOA->PUPDR |= GPIO_PUPDR_PUPDR11_0;
for (i=0;i<PULL_EFFECTIVE_DELAY;i++);
int no_usb = GPIOA->IDR & (1 << 11);
GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR11_0);
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();
@ -38,7 +52,7 @@ int main() {
// validate length
int len = (int)_app_start[0];
if (len < 8) fail();
if ((len < 8) || (((uint32_t)&_app_start[0] + RSANUMBYTES) >= 0x8100000)) fail();
// compute SHA hash
uint8_t digest[SHA_DIGEST_SIZE];

View File

@ -78,6 +78,9 @@ inline void early() {
#endif
if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
// ESP OFF
GPIOC->ODR &= ~((1 << 14) | (1 << 5));
// green LED on
// sadly, on the NEO board the bootloader turns it off
#ifdef PANDA

View File

@ -20,8 +20,8 @@
void spi_flasher() {
// green LED on for flashing
GPIOC->MODER |= GPIO_MODER_MODER7_0;
GPIOC->ODR &= ~(1 << (6 + 1));
GPIOC->MODER |= GPIO_MODER_MODER6_0;
GPIOC->ODR &= ~(1 << 6);
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;