Пример #1
0
void boardInit()
{
  RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph, ENABLE);
  RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph, ENABLE);
  RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph | EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph, ENABLE);

#if !defined(REV9E)
  // some REV9E boards need that the pwrInit() is moved a little bit later
  pwrInit();
#endif

  keysInit();
  adcInit();
  delaysInit();
  lcdInit();    // delaysInit() must be called before
  audioInit();
  init2MhzTimer();
  init5msTimer();
  __enable_irq();
  i2cInit();
  usbInit();
  
#if defined(HAPTIC)  
  hapticInit();
#endif

#if defined(REV9E)
  bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
#endif

#if defined(DEBUG)
  DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif

#if defined(REV9E)
  if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
    lcd_clear();
    lcd_bmp(76, 2, bmp_lock, 0, 60);
    lcdRefresh();
    lcdRefreshWait();

    tmr10ms_t start = get_tmr10ms();
    tmr10ms_t duration = 0;
    uint8_t pwr_on = 0;
    while (pwrPressed()) {
      duration = get_tmr10ms() - start;
      if (duration < PWR_PRESS_DURATION_MIN) {
        unsigned index = duration / (PWR_PRESS_DURATION_MIN / 4);
        lcd_clear();
        lcd_bmp(76, 2, bmp_startup, index*60, 60);
      }
      else if (duration >= PWR_PRESS_DURATION_MAX) {
        displaySleepBitmap();
        turnBacklightOff();
      }
      else {
        if (pwr_on != 1) {
          pwr_on = 1;
          pwrInit();
          backlightInit();
          haptic.play(15, 3, PLAY_NOW);
        }
      }
      lcdRefresh();
      lcdRefreshWait();
    }
    if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
      boardOff();
    }
  }
  else {
    pwrInit();
    backlightInit();
  }
  topLcdInit();
#else
  backlightInit();
#endif
}
Пример #2
0
void _bootStart()
{
    // turn soft power on now
#ifdef PCB9XT
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOAEN ; 		// Enable portC and A clock
    __ASM volatile ("nop") ;	// Needed for the STM32F4
    __ASM volatile ("nop") ;
    GPIOC->PUPDR = 0x0020 ;	// PIN_MCU_PWR
#else
#ifdef REV9E
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOGEN ; // Enable portD clock
#else
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOEEN ; // Enable portD clock
#endif
    __ASM volatile ("nop") ;	// Needed for the STM32F4
    __ASM volatile ("nop") ;

#ifdef REV9E
    if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE())
#endif
    {
        GPIOD->BSRRL = 1; // set PWR_GPIO_PIN_ON pin to 1
        GPIOD->MODER = (GPIOD->MODER & 0xFFFFFFFC) | 1; // General purpose output mode
    }
#endif

#ifdef PCB9XT
    GPIOA->PUPDR = 0x14000000 ;
    GPIOC->PUPDR = 0x04004000 ;		// PortC clock enabled above
#else

    GPIOC->PUPDR = 0x00000004 ;
#ifdef REV9E
    GPIOG->PUPDR = 0x00000001 ;
#else
    GPIOE->PUPDR = 0x00000040 ;
#endif
#endif

    uint32_t i ;
    for ( i = 0 ; i < 50000 ; i += 1 )
    {
        bwdt_reset() ;
    }
// now the second part of power on sequence
// If we got here and the radio was not started by the watchdog/software reset,
// then we must have a power button pressed. If not then we are in power on/off loop
// and to terminate it, just wait here without turning on PWR pin. The power supply will
// eventually exhaust and the radio will turn off.
#ifdef REV9E
    if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE())
    {
        // wait here until the power key is pressed
        while (GPIOD->IDR & PWR_GPIO_PIN_SWITCH)
        {
            bwdt_reset();
        }
    }
#endif

//#ifndef PCB9XT
#ifdef PCB9XT
//	if ( 1 )
//	{
//		if ( 1 )
//		{
    if ( (GPIOA->IDR & 0x00004000 ) == 0 )
    {
        if ( (GPIOC->IDR & 0x00002000 ) == 0 )
        {
#else
#ifdef REV9E
    if ( (GPIOG->IDR & 0x00000001 ) == 0 )
#else
    if ( (GPIOE->IDR & 0x00000008 ) == 0 )
#endif
    {
        if ( (GPIOC->IDR & 0x00000002 ) == 0 )
        {
#endif
            // Bootloader needed
            const uint8_t *src ;
            uint8_t *dest ;
            uint32_t size ;

            bwdt_reset() ;
            size = sizeof(BootCode) ;
            src = BootCode ;
            dest = (uint8_t *)0x20000000 ;

            for ( ; size ; size -= 1 )
            {
                *dest++ = *src++ ;
            }
            // Could check for a valid copy to RAM here
            // Go execute bootloader
            bwdt_reset() ;

            uint32_t address = *(uint32_t *)0x20000004 ;

            ((void (*)(void)) (address))() ;		// Go execute the loaded application

        }
    }
//#endif

//	run_application() ;
    asm(" mov.w	r1, #134217728");	// 0x8000000
    asm(" add.w	r1, #32768");			// 0x8000

    asm(" movw	r0, #60680");			// 0xED08
    asm(" movt	r0, #57344");			// 0xE000
    asm(" str	r1, [r0, #0]");			// Set the VTOR

    asm("ldr	r0, [r1, #0]");			// Stack pointer value
    asm("msr msp, r0");						// Set it
    asm("ldr	r0, [r1, #4]");			// Reset address
    asm("mov.w	r1, #1");
    asm("orr		r0, r1");					// Set lsbit
    asm("bx r0");									// Execute application
}