Beispiel #1
0
void mcu_arch_init(void) {
#ifdef USE_OPENCM3
  rcc_clock_setup_in_hse_12mhz_out_72mhz();
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  return;
#endif
#ifdef HSE_TYPE_EXT_CLK
#warning Info: Using external clock
  /* Setup the microcontroller system.
   *  Initialize the Embedded Flash Interface,
   *  initialize the PLL and update the SystemFrequency variable.
   */
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();
  /* Enable HSE with external clock ( HSE_Bypass ) */
  RCC_HSEConfig( STM32_RCC_MODE );
  /* Wait till HSE is ready */
  ErrorStatus HSEStartUpStatus = RCC_WaitForHSEStartUp();
  if (HSEStartUpStatus != SUCCESS) {
    /* block if something went wrong */
    while(1) {}
  }
  else {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);
    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);
    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, STM32_PLL_MULT);
    /* Enable PLL */
    RCC_PLLCmd(ENABLE);
    /* Wait till PLL is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08) {}
  }
#else  /* HSE_TYPE_EXT_CLK */
#warning Using normal system clock setup
  SystemInit();
#endif /* HSE_TYPE_EXT_CLK */
   /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

#ifdef STM32_FORCE_ALL_CLOCK_ON
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
                         RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
#endif


}
Beispiel #2
0
/* Set STM32 to 72 MHz. */
void clock_setup(void)
{
    rcc_clock_setup_in_hse_12mhz_out_72mhz();

    /* Enable GPIOC clock. */
    rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
    rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
    rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);

}
/* Set STM32 to 72 MHz. */
static void clock_setup(void)
{
	rcc_clock_setup_in_hse_12mhz_out_72mhz();

	/* Enable GPIOA, GPIOB, GPIOC, and AFIO clocks. */
	rcc_periph_clock_enable(RCC_GPIOA);
	rcc_periph_clock_enable(RCC_GPIOB);
	rcc_periph_clock_enable(RCC_GPIOC);
	rcc_periph_clock_enable(RCC_AFIO);
}
Beispiel #4
0
int main(void)
{
	rcc_clock_setup_in_hse_12mhz_out_72mhz();
	gpio_setup();
	can_setup();
	systick_setup();

	while (1); /* Halt. */

	return 0;
}
Beispiel #5
0
void mcu_arch_init(void) {
#if EXT_CLK == 8000000
#pragma message "Using 8MHz external clock to PLL it to 72MHz."
  rcc_clock_setup_in_hse_8mhz_out_72mhz();
#elif EXT_CLK == 12000000
#pragma message "Using 12MHz external clock to PLL it to 72MHz."
  rcc_clock_setup_in_hse_12mhz_out_72mhz();
#else
#error EXT_CLK is either set to an unsupported frequency or not defined at all. Please check!
#endif
}
int main(void)
{
	u8 sop_code[] = {
		0x03, 0xE7, 0x6E, 0x8A, 0xEF, 0xBD, 0xFE, 0xF8
	};
	u8 data_code[] = {
		0x88, 0x17, 0x13, 0x3B, 0x2D, 0xBF, 0x06, 0xD6
	};
	rcc_clock_setup_in_hse_12mhz_out_72mhz();

	// Initialize the modules
	led_init();
	timer_init();
	cdcacm_init();
	cyrf_init();

	// Register callbacks
	timer_dsm_register_callback(on_timer);
	cyrf_register_recv_callback(on_receive);
	cyrf_register_send_callback(on_send);

	// Config the cyrf RX mode, TX mode and framing
	cyrf_set_rx_cfg(CYRF_LNA | CYRF_FAST_TURN_EN); // Enable low noise amplifier and fast turn
	/*cyrf_set_tx_cfg(CYRF_DATA_CODE_LENGTH | CYRF_DATA_MODE_SDR | CYRF_PA_4); // Enable 64 chip codes, SDR mode and amplifier +4dBm
	cyrf_set_rx_override(CYRF_FRC_RXDR | CYRF_DIS_RXCRC); // Force receive data rate and disable receive CRC checker
	cyrf_set_tx_override(CYRF_DIS_TXCRC); // Disable the transmit CRC
	cyrf_set_framing_cfg(CYRF_SOP_LEN | 0xA); // Set SOP CODE to 64 chips and SOP Correlator Threshold to 0xA */
	cyrf_set_tx_cfg(CYRF_DATA_MODE_8DR | CYRF_PA_4); // Enable 32 chip codes, 8DR mode and amplifier +4dBm
	cyrf_set_rx_override(0x0); // Reset the rx override
	cyrf_set_tx_override(0x0); // Reset the tx override
	cyrf_set_framing_cfg(CYRF_SOP_EN | CYRF_SOP_LEN | CYRF_LEN_EN | 0xE); // Set SOP CODE enable, SOP CODE to 64 chips, Packet length enable, and SOP Correlator Threshold to 0xE

	// Set the channel
	cyrf_set_channel(0x61);

	// Set some other stuff
	cyrf_set_crc_seed(0x1A34);
	cyrf_set_sop_code(sop_code);
	cyrf_set_data_code(data_code);

	// Set the timer or start receive
#ifdef RECEIVER
	cyrf_start_recv();
#else
	timer_dsm_set(10);
#endif

	/* Main loop */
	while (1) {
		cdcacm_run();
	}

	return 0;
}
Beispiel #7
0
void mcu_arch_init(void)
{
#if LUFTBOOT
  PRINT_CONFIG_MSG("We are running luftboot, the interrupt vector is being relocated.")
#if defined STM32F4
  SCB_VTOR = 0x00004000;
#else
  SCB_VTOR = 0x00002000;
#endif
#endif
#if EXT_CLK == 8000000
#if defined(STM32F1)
  PRINT_CONFIG_MSG("Using 8MHz external clock to PLL it to 72MHz.")
  rcc_clock_setup_in_hse_8mhz_out_72mhz();
#elif defined(STM32F4)
  PRINT_CONFIG_MSG("Using 8MHz external clock to PLL it to 168MHz.")
  rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
#endif
#elif EXT_CLK == 12000000
#if defined(STM32F1)
  PRINT_CONFIG_MSG("Using 12MHz external clock to PLL it to 72MHz.")
  rcc_clock_setup_in_hse_12mhz_out_72mhz();
#elif defined(STM32F4)
  PRINT_CONFIG_MSG("Using 12MHz external clock to PLL it to 168MHz.")
  rcc_clock_setup_hse_3v3(&rcc_hse_12mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
#endif
#elif EXT_CLK == 16000000
#if defined(STM32F4)
  PRINT_CONFIG_MSG("Using 16MHz external clock to PLL it to 168MHz.")
  rcc_clock_setup_hse_3v3(&rcc_hse_16mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
#endif
#elif EXT_CLK == 24000000
#if defined(STM32F4)
  PRINT_CONFIG_MSG("Using 24MHz external clock to PLL it to 168MHz.")
  rcc_clock_setup_hse_3v3(&rcc_hse_24mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
#elif defined(STM32F1)
  rcc_clock_setup_in_hse_24mhz_out_24mhz_pprz();
#endif
#elif EXT_CLK == 25000000
#if defined(STM32F4)
  PRINT_CONFIG_MSG("Using 25MHz external clock to PLL it to 168MHz.")
  rcc_clock_setup_hse_3v3(&rcc_hse_25mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
#endif
#else
#error EXT_CLK is either set to an unsupported frequency or not defined at all. Please check!
#endif

  /* Configure priority grouping 0 bits for pre-emption priority and 4 bits for sub-priority.
   * this was previously in i2c driver
   * FIXME is it really needed ?
   */
  scb_set_priority_grouping(SCB_AIRCR_PRIGROUP_NOGROUP_SUB16);

}
static void clock_setup(void)
{
	rcc_clock_setup_in_hse_12mhz_out_72mhz();

	/* Enable GPIOA clock (for LED GPIOs). */
	rcc_periph_clock_enable(RCC_GPIOA);

	/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
	rcc_periph_clock_enable(RCC_AFIO);
	rcc_periph_clock_enable(RCC_USART2);
}
static void clock_setup(void)
{
	rcc_clock_setup_in_hse_12mhz_out_72mhz();

	/* Enable GPIOA clock (for LED GPIOs). */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);

	/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
				    RCC_APB2ENR_AFIOEN);
	rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
}
int main(void)
{
	uint8_t channel_array[16];
	uint16_t temperature = 0;

	rcc_clock_setup_in_hse_12mhz_out_72mhz();
	gpio_setup();
	usart_setup();
	timer_setup();
	adc_setup();

	gpio_set(GPIOA, GPIO8);	                /* LED1 on */
	gpio_set(GPIOC, GPIO15);		/* LED2 on */

	/* Send a message on USART1. */
	usart_send_blocking(USART2, 's');
	usart_send_blocking(USART2, 't');
	usart_send_blocking(USART2, 'm');
	usart_send_blocking(USART2, '\r');
	usart_send_blocking(USART2, '\n');

	/* Select the channel we want to convert. 16=temperature_sensor. */
	channel_array[0] = 16;
	/* Set the injected sequence here, with number of channels */
	adc_set_injected_sequence(ADC1, 1, channel_array);

	/* Continously convert and poll the temperature ADC. */
	while (1) {
		/*
		 * Since the injected sampling is triggered by the timer, it gets
		 * updated automatically, we just need to periodically read out the value.
		 * It would be better to check if the JEOC bit is set, and clear it following
		 * so that you do not read the same value twice, especially for a slower
		 * sampling rate.
		 */

		temperature = adc_read_injected(ADC1,1); //get the result from ADC_JDR1 on ADC1 (only bottom 16bits)

		/*
		 * That's actually not the real temperature - you have to compute it
		 * as described in the datasheet.
		 */
		my_usart_print_int(USART2, temperature);

		gpio_toggle(GPIOA, GPIO8); /* LED2 on */

	}

	return 0;
}
Beispiel #11
0
/**
 * Initialize STM32 system specific subsystems.
 */
static void system_init(void)
{
	/* Initialize the microcontroller system. Initialize clocks. */

	/*RCC_HSEConfig(RCC_HSE_ON);
	RCC_WaitForHSEStartUp();
	RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_6);
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);*/

	//SystemInit();
	rcc_clock_setup_in_hse_12mhz_out_72mhz();
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
	rcc_set_ppre1(RCC_CFGR_PPRE1_HCLK_DIV2);
}
Beispiel #12
0
void mcu_arch_init(void) {
#if LUFTBOOT
PRINT_CONFIG_MSG("We are running luftboot, the interrupt vector is being relocated.")
  SCB_VTOR = 0x00002000;
#endif
#if EXT_CLK == 8000000
PRINT_CONFIG_MSG("Using 8MHz external clock to PLL it to 72MHz.")
  rcc_clock_setup_in_hse_8mhz_out_72mhz();
#elif EXT_CLK == 12000000
PRINT_CONFIG_MSG("Using 12MHz external clock to PLL it to 72MHz.")
  rcc_clock_setup_in_hse_12mhz_out_72mhz();
#else
#error EXT_CLK is either set to an unsupported frequency or not defined at all. Please check!
#endif
}
int main(void)
{
	u8 channel_array[16];

	rcc_clock_setup_in_hse_12mhz_out_72mhz();
	gpio_setup();
	usart_setup();
	timer_setup();
	irq_setup();
	adc_setup();

	gpio_set(GPIOA, GPIO8);	                /* LED1 on */
	gpio_set(GPIOC, GPIO15);		/* LED2 on */

	/* Send a message on USART1. */
	usart_send_blocking(USART2, 's');
	usart_send_blocking(USART2, 't');
	usart_send_blocking(USART2, 'm');
	usart_send_blocking(USART2, '\r');
	usart_send_blocking(USART2, '\n');

	/* Select the channel we want to convert. 16=temperature_sensor. */
	channel_array[0] = 16;
	/* Set the injected sequence here, with number of channels */
	adc_set_injected_sequence(ADC1, 1, channel_array);

	/* Continously convert and poll the temperature ADC. */
	while (1) {
		/*
		 * Since sampling is triggered by the timer and copying the value
		 * out of the data register is handled by the interrupt routine,
		 * we just need to print the value and toggle the LED. It may be useful
		 * to buffer the adc values in some cases.
		 */

		/*
		 * That's actually not the real temperature - you have to compute it
		 * as described in the datasheet.
		 */
		my_usart_print_int(USART2, temperature);

		gpio_toggle(GPIOA, GPIO8); /* LED2 on */

	}

	return 0;
}
Beispiel #14
0
static void clock_setup(void)
{
	rcc_clock_setup_in_hse_12mhz_out_72mhz();

	/* Enable GPIOA, GPIOB, GPIOC clock. */
	rcc_periph_clock_enable(RCC_GPIOA);
	rcc_periph_clock_enable(RCC_GPIOB);
	rcc_periph_clock_enable(RCC_GPIOC);

	/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
	rcc_periph_clock_enable(RCC_GPIOA);
	rcc_periph_clock_enable(RCC_AFIO);
	rcc_periph_clock_enable(RCC_USART2);

	/* Enable SPI1 Periph and gpio clocks */
	rcc_periph_clock_enable(RCC_SPI1);
}
int main(void)
{

	rcc_clock_setup_in_hse_12mhz_out_72mhz();
	gpio_setup();
	usart_setup();
	timer_setup();
	irq_setup();
	adc_setup();

	gpio_set(GPIOA, GPIO8);	                /* LED1 off */
	gpio_set(GPIOC, GPIO15);		/* LED5 off */

	/* Send a message on USART1. */
	usart_send_blocking(USART2, 's');
	usart_send_blocking(USART2, 't');
	usart_send_blocking(USART2, 'm');
	usart_send_blocking(USART2, '\r');
	usart_send_blocking(USART2, '\n');

	/* Moved the channel selection and sequence init to adc_setup() */

	/* Continously convert and poll the temperature ADC. */
	while (1) {
		/*
		 * Since sampling is triggered by the timer and copying the values
		 * out of the data registers is handled by the interrupt routine,
		 * we just need to print the values and toggle the LED. It may be useful
		 * to buffer the adc values in some cases.
		 */

		my_usart_print_int(USART2, temperature);
		usart_send_blocking(USART2, ' ');
		my_usart_print_int(USART2, v_refint);
		usart_send_blocking(USART2, ' ');
		my_usart_print_int(USART2, lisam_adc1);
		usart_send_blocking(USART2, ' ');
		my_usart_print_int(USART2, lisam_adc2);
		usart_send_blocking(USART2, '\r');

		gpio_toggle(GPIOA, GPIO8); /* LED2 on */

	}

	return 0;
}
static void clock_setup(void)
{
	rcc_clock_setup_in_hse_12mhz_out_72mhz();

	/* Enable GPIOA, GPIOB, GPIOC clock. */
	rcc_peripheral_enable_clock(&RCC_APB2ENR,
				    RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |
				    RCC_APB2ENR_IOPCEN);

	/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
				    RCC_APB2ENR_AFIOEN);

	/* Enable SPI1 Periph and gpio clocks */
	rcc_peripheral_enable_clock(&RCC_APB2ENR,
				    RCC_APB2ENR_SPI1EN);

}