Beispiel #1
0
void ANO_Hexacopter_board_Init(void)
{
	//中断优先级组别设置
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
	
	//初始化系统滴答定时器
	cycleCounterInit();
	SysTick_Config(SystemCoreClock / 1000);	
	
	//初始化模拟I2C
	ANO_I2C_Soft::Init();
	//初始化SPI2
	ANO_SPI2::Init();
	//初始化NRF
	nrf.Init(MODEL_TX2,89);
	
	//初始化定时器输出PWM,24KHz
	ANO_PWM::out_Init(24000);

	uart3.Init(9600);
	
	ANO_LED::Init();	
	
	//解锁flash
	FLASH_Unlock();	
	//初始化虚拟eeprom设置
	EE_Init();	
}
Beispiel #2
0
void systemInit(void)
{
#ifdef CC3D
    /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
    extern void *isr_vector_table_base;

    NVIC_SetVectorTable((uint32_t)&isr_vector_table_base, 0x0);
#endif
    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);

#ifdef STM32F10X
    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#endif

    RCC_ClearFlag();


    enableGPIOPowerUsageAndNoiseReductions();


#ifdef STM32F10X
    // Turn off JTAG port 'cause we're using the GPIO for leds
#define AFIO_MAPR_SWJ_CFG_NO_JTAG_SW            (0x2 << 24)
    AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#endif

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);
}
Beispiel #3
0
void systemInit(void)
{
    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);

#ifdef STM32F10X
    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#endif

    // cache RCC->CSR value to use it in isMPUSoftreset() and others
    cachedRccCsrValue = RCC->CSR;
    RCC_ClearFlag();


    enableGPIOPowerUsageAndNoiseReductions();


#ifdef STM32F10X
    // Turn off JTAG port 'cause we're using the GPIO for leds
#define AFIO_MAPR_SWJ_CFG_NO_JTAG_SW            (0x2 << 24)
    AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#endif

    // Init cycle counter
    cycleCounterInit();


    memset(&exti15_10_handlers, 0x00, sizeof(exti15_10_handlers));
    // SysTick
    SysTick_Config(SystemCoreClock / 1000);
}
Beispiel #4
0
void systemInit(void)
{
    checkForBootLoaderRequest();

    SetSysClock();

    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);

    // cache RCC->CSR value to use it in isMPUSoftreset() and others
    cachedRccCsrValue = RCC->CSR;

    /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
    extern void *isr_vector_table_base;
    NVIC_SetVectorTable((uint32_t)&isr_vector_table_base, 0x0);
    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, DISABLE);

    RCC_ClearFlag();

    enableGPIOPowerUsageAndNoiseReductions();

    // Init cycle counter
    cycleCounterInit();

    memset(extiHandlerConfigs, 0x00, sizeof(extiHandlerConfigs));
    // SysTick
    SysTick_Config(SystemCoreClock / 1000);
}
Beispiel #5
0
void systemInit(void)
{
    checkForBootLoaderRequest();

    //SystemClock_Config();

    // Configure NVIC preempt/priority groups
    HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITY_GROUPING);

    // cache RCC->CSR value to use it in isMPUSoftReset() and others
    cachedRccCsrValue = RCC->CSR;

    /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
    //extern void *isr_vector_table_base;
    //NVIC_SetVectorTable((uint32_t)&isr_vector_table_base, 0x0);
    //__HAL_RCC_USB_OTG_FS_CLK_DISABLE;

    //RCC_ClearFlag();

    enableGPIOPowerUsageAndNoiseReductions();

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    //SysTick_Config(SystemCoreClock / 1000);
    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
}
Beispiel #6
0
void systemInit(bool overclock)
{

#ifdef STM32F303xC
    // start fpu
    SCB->CPACR = (0x3 << (10*2)) | (0x3 << (11*2));
#endif

#ifdef STM32F303xC
    SetSysClock();
#endif
#ifdef STM32F10X_MD
    // Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers
    // Configure the Flash Latency cycles and enable prefetch buffer
    SetSysClock(overclock);
#endif

    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

#ifdef STM32F10X_MD
    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#endif

    RCC_ClearFlag();


    enableGPIOPowerUsageAndNoiseReductions();


#ifdef STM32F10X_MD
    // Turn off JTAG port 'cause we're using the GPIO for leds
#define AFIO_MAPR_SWJ_CFG_NO_JTAG_SW            (0x2 << 24)
    AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#endif

    ledInit();
    beeperInit();

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

#ifdef CC3D
    spiInit(SPI1);
    spiInit(SPI2);
#endif

#ifndef CC3D
    // Configure the rest of the stuff
    i2cInit(I2C2);
#endif

    // sleep for 100ms
    delay(100);
}
Beispiel #7
0
static void systemTimekeepingSetup(void)
{
    RCC_ClocksTypeDef clocks;
    RCC_GetClocksFreq(&clocks);

    cycleCounterInit();
    SysTick_Config(clocks.SYSCLK_Frequency / 1000);
}
Beispiel #8
0
void systemInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    uint8_t i;

    gpio_config_t gpio_cfg[] = {
        { LED0_GPIO, LED0_PIN, GPIO_Mode_Out_PP }, // PB3 (LED)
        { LED1_GPIO, LED1_PIN, GPIO_Mode_Out_PP }, // PB4 (LED)
#ifndef FY90Q
        { BEEP_GPIO, BEEP_PIN, GPIO_Mode_Out_OD }, // PA12 (Buzzer)
#endif
    };
    uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);

    // Turn on clocks for stuff we use
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_TIM1 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
    RCC_ClearFlag();

    // Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    // Configure gpio
    for (i = 0; i < gpio_count; i++) {
        GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;
        GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
    }

    LED0_OFF;
    LED1_OFF;
    BEEP_OFF;

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Configure the rest of the stuff
    adcInit();
#ifndef FY90Q
    i2cInit(I2C2);
#endif

    // sleep for 100ms
    delay(100);
}
Beispiel #9
0
void systemInit(void)
{
#ifdef CC3D
    /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
    extern void *isr_vector_table_base;

    NVIC_SetVectorTable((uint32_t)&isr_vector_table_base, 0x0);
#endif
    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);

#ifdef STM32F10X
    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#endif

    // cache RCC->CSR value to use it in isMPUSoftreset() and others
    cachedRccCsrValue = RCC->CSR;
#ifdef STM32F40_41xxx
    /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */
    extern void *isr_vector_table_base;

    NVIC_SetVectorTable((uint32_t)&isr_vector_table_base, 0x0);

    RCC_AHB2PeriphClockCmd( RCC_AHB2Periph_OTG_FS, DISABLE);
#endif

    RCC_ClearFlag();

    enableGPIOPowerUsageAndNoiseReductions();

#ifdef STM32F10X
    // Set USART1 TX (PA9) to output and high state to prevent a rs232 break condition on reset.
    // See issue https://github.com/cleanflight/cleanflight/issues/1433
    gpio_config_t gpio;

    gpio.mode = Mode_Out_PP;
    gpio.speed = Speed_2MHz;
    gpio.pin = Pin_9;
    digitalHi(GPIOA, gpio.pin);
    gpioInit(GPIOA, &gpio);

    // Turn off JTAG port 'cause we're using the GPIO for leds
#define AFIO_MAPR_SWJ_CFG_NO_JTAG_SW            (0x2 << 24)
    AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#endif

    // Init cycle counter
    cycleCounterInit();


    memset(extiHandlerConfigs, 0x00, sizeof(extiHandlerConfigs));
    // SysTick
    SysTick_Config(SystemCoreClock / 1000);
}
Beispiel #10
0
void systemInit(void)
{
	// Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    ///////////////////////////////////

    checkFirstTime(false);
	readEEPROM();

	if (eepromConfig.receiverType == SPEKTRUM)
		checkSpektrumBind();

	checkResetType();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

	initMixer();

    ledInit();
    cliInit();

    BLUE_LED_ON;

    delay(20000);  // 20 sec total delay for sensor stabilization - probably not long enough.....

    adcInit();
    batteryInit();
    gpsInit();
    i2cInit(I2C1);
    i2cInit(I2C2);
    pwmEscInit(eepromConfig.escPwmRate);
    pwmServoInit(eepromConfig.servoPwmRate);
    rxInit();
    spiInit(SPI2);
    spiInit(SPI3);
    telemetryInit();
    timingFunctionsInit();

    initFirstOrderFilter();
    initGPS();
    initMax7456();
    initPID();

    GREEN_LED_ON;

    initMPU6000();
    initMag(HMC5883L_I2C);
    initPressure(MS5611_I2C);
}
Beispiel #11
0
void systemInit(void) {
    GPIO_InitTypeDef GPIO_InitStructure;
    gpio_config_t gpio_cfg[] = {
      { LEDR_GPIO, LEDR_PIN, GPIO_Mode_Out_PP },
      { LEDG_GPIO, LEDG_PIN, GPIO_Mode_Out_PP },
    };
    uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);
    uint32_t i;

    // This is needed because some shit inside Keil startup f***s with SystemCoreClock, setting it back to 72MHz even on HSI.
    SystemCoreClockUpdate();

    // Turn on clocks for stuff we use
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C2 | RCC_APB1Periph_SPI2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_TIM1 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
    RCC_ClearFlag();

    // Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);

    // Configure gpio
    for (i = 0; i < gpio_count; i++) {
        GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;
        GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
    }

    LEDR_OFF
    LEDG_OFF

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Configure the rest of the stuff
    i2cInit(I2C2);

    // sleep for 100ms
    delay(100);
}
Beispiel #12
0
void systemInit(void)
{
    checkForBootLoaderRequest();

    // Enable FPU
    SCB->CPACR = (0x3 << (10 * 2)) | (0x3 << (11 * 2));
    SetSysClock();

    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING);

    // cache RCC->CSR value to use it in isMPUSoftreset() and others
    cachedRccCsrValue = RCC->CSR;
    RCC_ClearFlag();

    enableGPIOPowerUsageAndNoiseReductions();

    // Init cycle counter
    cycleCounterInit();

    memset(extiHandlerConfigs, 0x00, sizeof(extiHandlerConfigs));
    // SysTick
    SysTick_Config(SystemCoreClock / 1000);
}
Beispiel #13
0
void systemInit(bool overclock)
{
    //RCC_ClocksTypeDef rccClocks;
    int i;

    // start fpu
    SCB->CPACR = (0x3 << (10*2)) | (0x3 << (11*2));

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div256);  // 72 MHz divided by 256 = 281.25 kHz

    // Turn on peripherial clocks
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);  // USART1, USART2
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);  // ADC2

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);


    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);  // PWM Out  + PWM RX
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);  // PWM Out
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);  // PWM Out  + PWM RX
//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);  // i2c
//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);  //
//
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);  // PPM + PWM RX
//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);  //
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);  // PWM Out
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);  // PWM Out
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE);  // PWM Out

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);  // Telemetry
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);  // GPS
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);  // Spektrum RX

    RCC_ClearFlag();

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

    gpioStart();

    spiInit();

    for (i = 0; i < 10; i++) {
        LED0_TOGGLE
        delay(25);
        BEEP_ON
        delay(25);
        BEEP_OFF
    }
    LED0_OFF

}
Beispiel #14
0
void systemInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    uint8_t i;

    gpio_config_t gpio_cfg[] = {
        {LED0_GPIO, LED0_PIN, GPIO_Mode_Out_PP},        // PB3 (LED)
        {LED1_GPIO, LED1_PIN, GPIO_Mode_Out_PP},        // PB4 (LED)
    };

    uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);

    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
    RCC_ClearFlag();

    // Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    // Configure gpio
    for (i = 0; i < gpio_count; i++) {
        GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;

        GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
    }

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    LED0_OFF;
    LED1_OFF;

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);     // 2 bits for pre-emption priority, 2 bits for subpriority

    checkFirstTime(false, false);
    readEEPROM();

    initMixer();

    pwmOutputConfig.escPwmRate = systemConfig.escPwmRate;
    pwmOutputConfig.servoPwmRate = systemConfig.servoPwmRate;

    //i2cInit(SENSOR_I2C);
    pwmInputInit();
    pwmOutputInit(&pwmOutputConfig);
    uartInit(115200);

    //delay(10000);               // 10 sec delay for sensor stabilization - probably not long enough.....

    //initAccel();
    //initGyro();
    //initMag();
    adcInit();
    //initPressure(); // no pressure sensor

    initPID();
}
Beispiel #15
0
void testInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    uint8_t i;

    struct __gpio_config_t {
    GPIO_TypeDef *gpio;
    uint16_t pin;
    GPIOMode_TypeDef mode;
    }
    gpio_cfg[] = {
        {LED0_GPIO, LED0_PIN, GPIO_Mode_Out_PP},        // PB3 (LED)
        {LED1_GPIO, LED1_PIN, GPIO_Mode_Out_PP},        // PB4 (LED)
    };

    uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);

    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
    RCC_ClearFlag();

    // Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    // Configure gpio
    for (i = 0; i < gpio_count; i++) {
        GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;

        GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
    }

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    LED0_OFF;
    LED1_OFF;

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);     // 2 bits for pre-emption priority, 2 bits for subpriority
    
    checkFirstTime(true,true);
    initMixer();
    
    pwmOutputConfig.motorPwmRate = 10*1000;
    pwmOutputConfig.noEsc = true;
    pwmOutputInit(&pwmOutputConfig);
    
    
    i2cInit(SENSOR_I2C);
    initGyro();
    initAccel();
    initMag();
    nrf_init();
    nrf_detect();
}
Beispiel #16
0
void systemInit(void)
{
    RCC_ClocksTypeDef rccClocks;

    ///////////////////////////////////

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                           RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO  |
                           RCC_APB2Periph_TIM1  | RCC_APB2Periph_TIM8  |
                           RCC_APB2Periph_ADC1, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3  | RCC_APB1Periph_TIM4  |
                           RCC_APB1Periph_TIM5  | RCC_APB1Periph_TIM6  |
                           RCC_APB1Periph_I2C2, ENABLE);

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

#ifdef _DTIMING
    timingSetup();
#endif

    ///////////////////////////////////////////////////////////////////////////

    checkFirstTime(false);
    readEEPROM();

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

    pwmMotorDriverInit();

    cliInit();
    gpioInit();
    adcInit();

    LED2_ON;

    delay(10000);  // 10 seconds of 20 second delay for sensor stabilization

    if (GetVCPConnectMode() != eVCPConnectReset)
    {
        cliPrintF("\r\nUSB startup delay...\r\n");
        delay(3000);

        if (GetVCPConnectMode() == eVCPConnectData)
        {
            cliPrintF("\r\nBGC32 firmware starting up, USB connected...\r\n");
        }
    }
    else
    {
        cliPrintF("\r\nDelaying for usb/serial driver to settle\r\n");
        delay(3000);
        cliPrintF("\r\nBGC32 firmware starting up, serial active...\r\n");
    }

#ifdef __VERSION__
    cliPrintF("\ngcc version " __VERSION__ "\n");
#endif

    cliPrintF("BGC32 Firmware V%s, Build Date " __DATE__ " "__TIME__" \n", __BGC32_VERSION);

    if ((RCC->CR & RCC_CR_HSERDY) != RESET)
    {
        cliPrintF("\nRunning on external HSE clock....\n");
    }
    else
    {
        cliPrintF("\nERROR: Running on internal HSI clock....\n");
    }

    RCC_GetClocksFreq(&rccClocks);

    cliPrintF("\nADCCLK-> %2d MHz\n",   rccClocks.ADCCLK_Frequency / 1000000);
    cliPrintF(  "HCLK->   %2d MHz\n",   rccClocks.HCLK_Frequency   / 1000000);
    cliPrintF(  "PCLK1->  %2d MHz\n",   rccClocks.PCLK1_Frequency  / 1000000);
    cliPrintF(  "PCLK2->  %2d MHz\n",   rccClocks.PCLK2_Frequency  / 1000000);
    cliPrintF(  "SYSCLK-> %2d MHz\n\n", rccClocks.SYSCLK_Frequency / 1000000);

    delay(10000);  // Remaining 10 seconds of 20 second delay for sensor stabilization - probably not long enough..

    LED1_ON;

    i2cInit(I2C2);
    rcInit();
    timingFunctionsInit();

    BKPInit();

    initFirstOrderFilter();
    initPID();
    initSinArray();

    orientIMU();

    initMPU6050();
    // initMag();
}
Beispiel #17
0
int main(void)
{
	static char ledsta;
	/***********************************/
	SystemClock_HSI(9);           //系统时钟初始化,时钟源内部HSI
	cycleCounterInit();				    // Init cycle counter
	SysTick_Config(SystemCoreClock / 1000);	//SysTick开启系统tick定时器并初始化其中断,1ms
	UART1_init(SysClock,uart1baudSet); //串口1初始化
  NVIC_INIT();	                //中断初始化
  STMFLASH_Unlock();            //内部flash解锁
  LoadParamsFromEEPROM();				//加载系统参数配置表
  LedInit();	                  //IO初始化
  Adc_Init();										//摇杆AD初始化
	KeyInit();										//按键初始化
 	NRF24L01_INIT();              //NRF24L01初始化
  SetTX_Mode();                 //设无线模块为接收模式
  controlClibra();							//遥控摇杆校准
#ifdef UART_DEBUG  
	TIM3_Init(SysClock,2000);			//定时器初始化,1s为周期打印摇杆值
#endif
	TIM4_Init(SysClock,TIME4_Preiod);	  //定时器4初始化,定时时间单位:(TIME4_Preiod)微秒
	
	LedSet(led2,1);
	LedSet(led3,1);
	
	LoadRCdata();                //摇杆赋值
	//RockerUnlockcrazepony();	 //摆杆启动
  Lockflag = 0;								 //解锁标志,1表示产生了一次按键操作,0表示该按键操作已经发送到飞控
	
  LedSet(led2,0);
	LedSet(led3,0);
	 
  while (1)             
	{ 
		//10Hz loop
		if(flag10Hz == 1)  //10Hz 
		{		
			flag10Hz = 0;
			/*status led*/
			ledsta = !ledsta;
			LedSet(signalLED,ledsta);				        
			/*crazepony Lock*/
			KeyLockcrazepony();
			/*IMUcalibrate  */
			IMUcalibrate();
			/*remote calibrate*/
			Remotecalibrate();
		}

		//50Hz loop
		if(flag50Hz == 1)
		{
			LoadRCdata();
			flag50Hz = 0;
			
		}
		
		// 80Hz 12.5ms
		if(flag80Hz)
		{
			flag80Hz = 0;
			CommUAVUpload(MSP_SET_4CON);   
		}
	}
}
void systemInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    //uint32_t i;

    //GPIO_InitTypeDef GPIO_InitStructure;
				/*RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOE, ENABLE);
				GPIO_InitStructure.GPIO_Pin = LED0_PIN | LED1_PIN | LED2_PIN| LED3_PIN;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOE, &GPIO_InitStructure);*/
				
	/* Configure the GPIO_LED pins */
	RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD, ENABLE);
  GPIO_InitStructure.GPIO_Pin = LED0_PIN | LED1_PIN | LED2_PIN| LED3_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);			

#ifdef BUZZER
        {
	RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD, ENABLE);
  GPIO_InitStructure.GPIO_Pin = BEEP_PIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;  
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;	
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  GPIO_Init(GPIOD, &GPIO_InitStructure);				
    };

#endif

  //  uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);
		
	// This is needed because some shit inside Keil startup f***s with SystemCoreClock, setting it back to 72MHz even on HSI.
    //SystemCoreClockUpdate();
    SystemInit();

    // Turn on clocks for stuff we use
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_TIM5 | RCC_APB1Periph_I2C2 | RCC_APB1Periph_SPI2 | RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3 , ENABLE);
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM8 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1 | RCC_APB2Periph_SPI1, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_DMA2, ENABLE);
    RCC_ClearFlag();

    /*/ Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    // Configure gpio
    for (i = 0; i < gpio_count; i++) {
        GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;
        GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
    }*/

    LED0_ON;
    LED1_ON;
    //LED2_OFF;
    //LED3_OFF;
		
    BEEP_OFF;

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Configure the rest of the stuff
#ifndef FY90Q
    i2cInit(I2C2);
#endif
    //spiInit();

    // sleep for 100ms
    delay(100);
}
Beispiel #19
0
void systemInit(void)
{
    RCC_ClocksTypeDef rccClocks;

	///////////////////////////////////

	// Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Turn on peripherial clcoks
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,   ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2,   ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,   ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,   ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,  ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,  ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,  ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,  ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,  ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,   ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2,   ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,   ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3,   ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,   ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,   ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,   ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,   ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,   ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,   ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,   ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10,  ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,  ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

    ///////////////////////////////////

    checkFirstTime(false);
	readEEPROM();

	if (eepromConfig.receiverType == SPEKTRUM)
		checkSpektrumBind();

	checkResetType();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

	///////////////////////////////////

	gpsPortClearBuffer       = &uart2ClearBuffer;
    gpsPortNumCharsAvailable = &uart2NumCharsAvailable;
    gpsPortPrintBinary       = &uart2PrintBinary;
    gpsPortRead              = &uart2Read;

	telemPortAvailable       = &uart1Available;
	telemPortPrint           = &uart1Print;
	telemPortPrintF          = &uart1PrintF;
	telemPortRead            = &uart1Read;

	///////////////////////////////////

	initMixer();

    usbInit();

    ledInit();

    uart1Init();
    uart2Init();

    BLUE_LED_ON;

    ///////////////////////////////////

    delay(10000);  // 10 seconds of 20 second delay for sensor stabilization

    checkUsbActive();

    #ifdef __VERSION__
        cliPortPrintF("\ngcc version " __VERSION__ "\n");
    #endif

    cliPortPrintF("\nAQ32Plus Firmware V%s, Build Date " __DATE__ " "__TIME__" \n", __AQ32PLUS_VERSION);

    if ((RCC->CR & RCC_CR_HSERDY) != RESET)
    {
        cliPortPrint("\nRunning on external HSE clock....\n");
    }
    else
    {
        cliPortPrint("\nERROR: Running on internal HSI clock....\n");
    }

    RCC_GetClocksFreq(&rccClocks);

    cliPortPrintF("\nHCLK->   %3d MHz\n",   rccClocks.HCLK_Frequency   / 1000000);
    cliPortPrintF(  "PCLK1->  %3d MHz\n",   rccClocks.PCLK1_Frequency  / 1000000);
    cliPortPrintF(  "PCLK2->  %3d MHz\n",   rccClocks.PCLK2_Frequency  / 1000000);
    cliPortPrintF(  "SYSCLK-> %3d MHz\n\n", rccClocks.SYSCLK_Frequency / 1000000);

    initUBLOX();

    delay(10000);  // Remaining 10 seconds of 20 second delay for sensor stabilization - probably not long enough..

    ///////////////////////////////////

    adcInit();
    i2cInit(I2C1);
    i2cInit(I2C2);
    pwmServoInit();
    rxInit();
    spiInit(SPI2);
    spiInit(SPI3);
    timingFunctionsInit();

    batteryInit();

    initFirstOrderFilter();
    initMavlink();
    initMax7456();
    initPID();

    GREEN_LED_ON;

    initMPU6000();
    initMag();
    initPressure();
}
Beispiel #20
0
void systemInit(void)
{
	// Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Turn on peripherial clocks
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12,    ENABLE);

	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,     ENABLE);  // USART1
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,     ENABLE);  // ADC2

	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,    ENABLE);
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,    ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,    ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,   ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,   ENABLE);  // PWM Servo Out 1 & 2
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,   ENABLE);  // PWM ESC Out 3 & 4
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,   ENABLE);  // PWM ESC Out 5,6,7, & 8
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,   ENABLE);  // 500 Hz dt Counter
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,   ENABLE);  // 100 Hz dt Counter
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15,  ENABLE);  // PWM ESC Out 1 & 2
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16,  ENABLE);  // PPM RX
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17,  ENABLE);  // Spektrum Frame Sync

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);  // Telemetry
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);  // Spektrum RX

    ///////////////////////////////////////////////////////////////////////////

    checkFirstTime(false);
	readEEPROM();

	if (eepromConfig.receiverType == SPEKTRUM)
		checkSpektrumBind();

    checkResetType();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

	initMixer();

	cliInit();
	gpioInit();
    telemetryInit();
    adcInit();

    LED0_OFF;

    delay(20000);  // 20 sec total delay for sensor stabilization - probably not long enough.....

    LED0_ON;

    batteryInit();
    pwmServoInit(eepromConfig.servoPwmRate);

    if (eepromConfig.receiverType == SPEKTRUM)
        spektrumInit();
    else
        ppmRxInit();

    spiInit(SPI2);
    timingFunctionsInit();

    initFirstOrderFilter();
    initPID();

    initMPU6000();
    initMag();
    initPressure();
}
Beispiel #21
0
void systemInit(bool overclock)
{
    //RCC_ClocksTypeDef rccClocks;
    int i;

    // start fpu
    SCB->CPACR = (0x3 << (10 * 2)) | (0x3 << (11 * 2));
    /* Reset the RCC clock configuration to the default reset state ------------*/
    /* Set HSION bit */
    RCC->CR |= (uint32_t)0x00000001;

    /* Reset CFGR register */
    RCC->CFGR = 0x00000000;

    /* Reset HSEON, CSSON and PLLON bits */
    RCC->CR &= (uint32_t)0xFEF6FFFF;

    /* Reset PLLCFGR register */
    RCC->PLLCFGR = 0x24003010;

    /* Reset HSEBYP bit */
    RCC->CR &= (uint32_t)0xFFFBFFFF;

    /* Disable all interrupts */
    RCC->CIR = 0x00000000;

#ifdef DATA_IN_ExtSRAM
    SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM */

    /* Configure the System clock source, PLL Multiplier and Divider factors,
     AHB/APBx prescalers and Flash settings ----------------------------------*/
    SetSysClock();
#define VECT_TAB_OFFSET  0x00 /*!< Vector Table base offset field.
     /* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
    SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
    SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

//    RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div256);  // 72 MHz divided by 256 = 281.25 kHz

// Turn on peripherial clocks
//    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ADC12, ENABLE);

//    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);  // USART1, USART2
//    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);  // ADC2

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);  // PWM Out  + PWM RX
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);  // PWM Out
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);  // PWM Out  + PWM RX

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE);  // i2c

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);  //
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);  //
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);  //
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);  //
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM12, ENABLE);  //

    //    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);  //
//
 // PPM + PWM RX
//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);  //
//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE);  // PWM Out
//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);  // PWM Out
//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE);  // PWM Out

//    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);  // Telemetry
//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);  // GPS
//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);  // Spektrum RX

    RCC_ClearFlag();

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

    gpioStart();

    spiInit();
//    if feature(FEATURE_I2C)
//        i2cInit(I2C2);

    for (i = 0; i < 10; i++) {
        LED0_TOGGLE
        delay(25);
        BEEP_ON
        delay(25);
        BEEP_OFF
    }
    LED0_OFF

}
Beispiel #22
0
void systemInit(void)
{
	RCC_ClocksTypeDef rccClocks;

	///////////////////////////////////

	// Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Turn on peripherial clocks
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12,    ENABLE);

	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,     ENABLE);  // USART1, USART2
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,     ENABLE);  // ADC2

	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,    ENABLE);
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,    ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,    ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,   ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,   ENABLE);  // PPM RX
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,   ENABLE);  // PWM ESC Out 1 & 2
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,   ENABLE);  // PWM ESC Out 5 & 6
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,   ENABLE);  // PWM Servo Out 1, 2, 3, & 4
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,   ENABLE);  // 500 Hz dt Counter
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,   ENABLE);  // 100 Hz dt Counter
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15,  ENABLE);  // PWM ESC Out 3 & 4
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16,  ENABLE);  // RangeFinder PWM
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17,  ENABLE);  // Spektrum Frame Sync

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);  // Telemetry
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);  // GPS
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);  // Spektrum RX

    ///////////////////////////////////////////////////////////////////////////

    spiInit(SPI2);

    ///////////////////////////////////

    checkSensorEEPROM(false);
	checkSystemEEPROM(false);

	readSensorEEPROM();
	readSystemEEPROM();

	///////////////////////////////////

	if (systemConfig.receiverType == SPEKTRUM)
		checkSpektrumBind();

    ///////////////////////////////////

	checkResetType();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

	///////////////////////////////////

	gpsPortClearBuffer       = &uart2ClearBuffer;
    gpsPortNumCharsAvailable = &uart2NumCharsAvailable;
    gpsPortPrintBinary       = &uart2PrintBinary;
    gpsPortRead              = &uart2Read;

    telemPortAvailable       = &uart1Available;
    telemPortPrint           = &uart1Print;
    telemPortPrintF          = &uart1PrintF;
    telemPortRead            = &uart1Read;

	///////////////////////////////////

	initMixer();

	usbInit();

	gpioInit();

	uart1Init();
    uart2Init();

    LED0_OFF;

    delay(10000);  // 10 seconds of 20 second delay for sensor stabilization

    checkUsbActive();

    ///////////////////////////////////

    #ifdef __VERSION__
        cliPortPrintF("\ngcc version " __VERSION__ "\n");
    #endif

    cliPortPrintF("\nFF32mini Firmware V%s, Build Date " __DATE__ " "__TIME__" \n", __FF32MINI_VERSION);

    if ((RCC->CR & RCC_CR_HSERDY) != RESET)
    {
        cliPortPrint("\nRunning on external HSE clock....\n");
    }
    else
    {
        cliPortPrint("\nERROR: Running on internal HSI clock....\n");
    }

    RCC_GetClocksFreq(&rccClocks);

    cliPortPrintF("\nHCLK->   %2d MHz\n",   rccClocks.HCLK_Frequency   / 1000000);
    cliPortPrintF(  "PCLK1->  %2d MHz\n",   rccClocks.PCLK1_Frequency  / 1000000);
    cliPortPrintF(  "PCLK2->  %2d MHz\n",   rccClocks.PCLK2_Frequency  / 1000000);
    cliPortPrintF(  "SYSCLK-> %2d MHz\n\n", rccClocks.SYSCLK_Frequency / 1000000);

    if (systemConfig.receiverType == PPM)
    	cliPortPrint("Using PPM Receiver....\n\n");
    else
    	cliPortPrint("Using Spektrum Satellite Receiver....\n\n");

    initUBLOX();

    delay(10000);  // Remaining 10 seconds of 20 second delay for sensor stabilization - probably not long enough..

    ///////////////////////////////////

	adcInit();
    aglInit();
    pwmServoInit();

    if (systemConfig.receiverType == SPEKTRUM)
        spektrumInit();
    else
        ppmRxInit();

    timingFunctionsInit();

    batteryInit();

    initFirstOrderFilter();
    initMavlink();
    initPID();

    LED0_ON;

    initMPU6000();
    initMag();
    initPressure();
}
Beispiel #23
0
void systemInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,   ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,   ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,   ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,   ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,   ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2,   ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,     ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,     ENABLE);
    RCC_ClearFlag();

    // Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);     // 2 bits for pre-emption priority, 2 bits for subpriority

    checkFirstTime(false);
    readEEPROM();

    ledInit();

    LED0_ON;

    initMixer();

    pwmOutputConfig.escPwmRate   = eepromConfig.escPwmRate;
    pwmOutputConfig.servoPwmRate = eepromConfig.servoPwmRate;

    cliInit(115200);
    i2cInit(I2C2);
    pwmOutputInit(&pwmOutputConfig);
    rxInit();

    delay(20000);               // 20 sec delay for sensor stabilization - probably not long enough.....

    LED1_ON;

    initAccel();
    initGyro();
    initMag();
    initPressure();

    initPID();
}
Beispiel #24
0
int main(void)
{  	
	u8 i;
	u8 RecvBuf[32];
	u8 SendBuf[32];
	u8 offline = 0;
	u8 recv_flag = 0;
	u32 pd2ms=0,pd20ams=0,pd20bms=0,pd100ms=0;

	SystemInit();
	RCC_Configuration();
	NVIC_Configuration();
	GPIO_Configuration();
	
	USART1_Configuration();
	dbgPrintf(" Init Ticktack !\r\n");
	cycleCounterInit();
	SysTick_Config(SystemCoreClock / 1000);	
	for(i=0;i<2;i++)
	{
		OP_LED1;OP_LED2;OP_LED3;OP_LED4;
		delay_ms(500);
		OP_LED1;OP_LED2;OP_LED3;OP_LED4;
		delay_ms(500);
	}
	FilterInit();
	controllerInit();

	dbgPrintf(" Init eeprom!\r\n");
	FLASH_Unlock();	
	EE_Init();
	EE_Read_ACC_GYRO_Offset();
	/* 如果PID丢失或者错误,将下面两行注释去掉,重新编译烧写,运行一遍,可将PID还原,然后重新注释,再烧写一遍 */
	//EE_Write_PID();
	//EE_Write_Rate_PID();
	EE_Read_PID();
	EE_Read_Rate_PID();

	dbgPrintf(" Init adc!\r\n");
	ADC_DMA_Init();

	dbgPrintf(" Init NRF24L01 !\r\n");
	SPI_NRF_Init();	
	Nrf24l01_Init();
	NRF24l01_SetRxMode();
	
	while(Nrf24l01_Check())	
	{
		dbgPrintf("NRF24L01 Fault !\r\n");
		delay_ms(500);
	}
	dbgPrintf("NRF24L01 Is Detected !\r\n");

	dbgPrintf("Init MPU6050...\r\n");
	IIC_Init();
	MPU6050_initialize();


	dbgPrintf("Init Motor...\r\n");
	Motor_Init();
	Motor_SetPwm(0,0,0,0);


	pd20bms = TIMIRQCNT + 10*ITS_PER_MS;
	while(1)
	{
		if(TIMIRQCNT>pd2ms + 2*ITS_PER_MS-1)	// every 4ms
		{
			GetEulerAngle();
			if(lock_flag==UNLOCK) 
				AttitudeToMotors(angle.y,angle.x,angle.z);
			else
			{
				MOTOR1=0;	 			
				MOTOR2=0;				
				MOTOR3=0;				
				MOTOR4=0;				
			}
			Motor_SetPwm(MOTOR1,MOTOR2,MOTOR3,MOTOR4);
			pd2ms = TIMIRQCNT;
		}
		
		if(TIMIRQCNT>pd20ams + 20*ITS_PER_MS-1)	// every 20ms
		{
				if(NRF24l01_Recv(RecvBuf)>10)
				{
						if((RecvBuf[RecvBuf[2]+3]==CheckSum(RecvBuf, RecvBuf[2]+3))&&(RecvBuf[0]==0xAA))
						{
								if(RecvBuf[1]!=0xC0)		
									OP_LED1;		
								offline=0;
								switch(RecvBuf[1])
								{
										case 0xC0:  //control
												Getdesireddata(RecvBuf);
												OP_LED2;
												break;
										case 0x10:  //W PID
												SetPID(RecvBuf);
												break;
										case 0x11:  //W Attitude
												SetAccGyroOffset(RecvBuf);
												break;
										case 0x12:  //W Control offset
												break;
										case 0x14:  //W Rate PID
												SetRatePID(RecvBuf);
												break;
										case 0x20:  //R PID
												recv_flag = RESEND;
												GetPID(SendBuf);
												break;
										case 0x21:  //R Attitude
												recv_flag = RESEND;
												GetAccGyroOffset(SendBuf);
												break;
										case 0x22:  //R Control offset
												break;
										case 0x24:  //R Rate PID
												recv_flag = RESEND;
												GetRatePID(SendBuf);
												break;
										case 0x40:	//校准姿态
												EnableCalibration();
												break;
										case 0x41:	//校准遥控器零点												
												break;
									 default:
												break;
								}
						}
				}
				pd20ams = TIMIRQCNT;
		}
		if(TIMIRQCNT>pd20bms + 20*ITS_PER_MS-1)	// every 20ms
		{
			if(recv_flag==0)
         		GetState(SendBuf);
      		else
         		recv_flag--;
			NRF_SendData(SendBuf);
			OP_LED3;
			pd20bms = TIMIRQCNT;
		}
		
		if(TIMIRQCNT>pd100ms + 100*ITS_PER_MS-1)	// every 100ms
		{
			if(offline>20)
				lock_flag = LOCK;
			offline++;
//			OP_LED4;
			pd100ms = TIMIRQCNT;
		}
	}
}