You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					80 lines
				
				2.1 KiB
			
		
		
			
		
	
	
					80 lines
				
				2.1 KiB
			| 
								 
											6 years ago
										 
									 | 
							
								// Early bringup
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								#define ENTER_BOOTLOADER_MAGIC 0xdeadbeef
							 | 
						||
| 
								 | 
							
								#define ENTER_SOFTLOADER_MAGIC 0xdeadc0de
							 | 
						||
| 
								 | 
							
								#define BOOT_NORMAL 0xdeadb111
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								extern void *g_pfnVectors;
							 | 
						||
| 
								 | 
							
								extern uint32_t enter_bootloader_mode;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void jump_to_bootloader(void) {
							 | 
						||
| 
								 | 
							
								  // do enter bootloader
							 | 
						||
| 
								 | 
							
								  enter_bootloader_mode = 0;
							 | 
						||
| 
								 | 
							
								  void (*bootloader)(void) = (void (*)(void)) (*((uint32_t *)0x1fff0004));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // jump to bootloader
							 | 
						||
| 
								 | 
							
								  bootloader();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // reset on exit
							 | 
						||
| 
								 | 
							
								  enter_bootloader_mode = BOOT_NORMAL;
							 | 
						||
| 
								 | 
							
								  NVIC_SystemReset();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void early(void) {
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  // Reset global critical depth
							 | 
						||
| 
								 | 
							
								  global_critical_depth = 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // neccesary for DFU flashing on a non-power cycled white panda
							 | 
						||
| 
								 | 
							
								  enable_interrupts();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  // after it's been in the bootloader, things are initted differently, so we reset
							 | 
						||
| 
								 | 
							
								  if ((enter_bootloader_mode != BOOT_NORMAL) &&
							 | 
						||
| 
								 | 
							
								      (enter_bootloader_mode != ENTER_BOOTLOADER_MAGIC) &&
							 | 
						||
| 
								 | 
							
								      (enter_bootloader_mode != ENTER_SOFTLOADER_MAGIC)) {
							 | 
						||
| 
								 | 
							
								    enter_bootloader_mode = BOOT_NORMAL;
							 | 
						||
| 
								 | 
							
								    NVIC_SystemReset();
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // if wrong chip, reboot
							 | 
						||
| 
								 | 
							
								  volatile unsigned int id = DBGMCU->IDCODE;
							 | 
						||
| 
								 | 
							
								  #ifdef STM32F4
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    if ((id & 0xFFFU) != 0x463U) {
							 | 
						||
| 
								 | 
							
								      enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  #else
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    if ((id & 0xFFFU) != 0x411U) {
							 | 
						||
| 
								 | 
							
								      enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  #endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // setup interrupt table
							 | 
						||
| 
								 | 
							
								  SCB->VTOR = (uint32_t)&g_pfnVectors;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // early GPIOs float everything
							 | 
						||
| 
								 | 
							
								  RCC->AHB1ENR = RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  GPIOA->MODER = 0; GPIOB->MODER = 0; GPIOC->MODER = 0;
							 | 
						||
| 
								 | 
							
								  GPIOA->ODR = 0; GPIOB->ODR = 0; GPIOC->ODR = 0;
							 | 
						||
| 
								 | 
							
								  GPIOA->PUPDR = 0; GPIOB->PUPDR = 0; GPIOC->PUPDR = 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  detect_configuration();
							 | 
						||
| 
								 | 
							
								  detect_board_type();
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  #ifdef PANDA
							 | 
						||
| 
								 | 
							
								    // enable the ESP, disable ESP boot mode
							 | 
						||
| 
								 | 
							
								    // dont disable on grey panda
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  #endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
							 | 
						||
| 
								 | 
							
								  #ifdef PANDA
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								  #endif
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    current_board->set_led(LED_GREEN, 1);
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    jump_to_bootloader();
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  if (is_entering_bootmode) {
							 | 
						||
| 
								 | 
							
								    enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								}
							 |