本文整理汇总了C++中HAL_RCC_GetPCLK2Freq函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_RCC_GetPCLK2Freq函数的具体用法?C++ HAL_RCC_GetPCLK2Freq怎么用?C++ HAL_RCC_GetPCLK2Freq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_RCC_GetPCLK2Freq函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: set_baud_rate
static void set_baud_rate(USART_TypeDef *usart, int baud)
{
if (usart->CR1 & USART_CR1_OVER8) {
if (usart == USART1 || usart == USART6) {
usart->BRR = __UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), baud);
} else {
usart->BRR = __UART_BRR_SAMPLING8(HAL_RCC_GetPCLK1Freq(), baud);
}
} else {
if (usart == USART1 || usart == USART6) {
usart->BRR = __UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), baud);
} else {
usart->BRR = __UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(), baud);
}
}
}
开发者ID:Ewardlei,项目名称:grbl_stm32f4,代码行数:16,代码来源:usart.c
示例2: IRDA_SetConfig
/**
* @brief Configures the IRDA peripheral.
* @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
* the configuration information for the specified IRDA module.
* @retval None
*/
static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
{
/* Check the parameters */
assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
assert_param(IS_IRDA_MODE(hirda->Init.Mode));
/*------- IRDA-associated USART registers setting : CR2 Configuration ------*/
/* Clear STOP[13:12] bits */
CLEAR_BIT(hirda->Instance->CR2, USART_CR2_STOP);
/*------- IRDA-associated USART registers setting : CR1 Configuration ------*/
/* Configure the USART Word Length, Parity and mode:
Set the M bits according to hirda->Init.WordLength value
Set PCE and PS bits according to hirda->Init.Parity value
Set TE and RE bits according to hirda->Init.Mode value */
MODIFY_REG(hirda->Instance->CR1,
((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE)),
(uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode);
/*------- IRDA-associated USART registers setting : CR3 Configuration ------*/
/* Clear CTSE and RTSE bits */
CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
/*------- IRDA-associated USART registers setting : BRR Configuration ------*/
if(hirda->Instance == USART1)
{
hirda->Instance->BRR = IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate);
}
else
{
hirda->Instance->BRR = IRDA_BRR(HAL_RCC_GetPCLK1Freq(), hirda->Init.BaudRate);
}
}
开发者ID:EverSince,项目名称:STM32-AD7156,代码行数:41,代码来源:stm32l1xx_hal_irda.c
示例3: spi_get_clock_freq
/*
* Only the frequency is managed in the family specific part
* the rest of SPI management is common to all STM32 families
*/
int spi_get_clock_freq(spi_t *obj) {
struct spi_s *spiobj = SPI_S(obj);
int spi_hz = 0;
/* Get source clock depending on SPI instance */
switch ((int)spiobj->spi) {
case SPI_1:
#if defined SPI4_BASE
case SPI_4:
#endif
#if defined SPI5_BASE
case SPI_5:
#endif
#if defined SPI6_BASE
case SPI_6:
#endif
/* SPI_1, SPI_4, SPI_5 and SPI_6. Source CLK is PCKL2 */
spi_hz = HAL_RCC_GetPCLK2Freq();
break;
case SPI_2:
#if defined SPI3_BASE
case SPI_3:
#endif
/* SPI_2 and SPI_3. Source CLK is PCKL1 */
spi_hz = HAL_RCC_GetPCLK1Freq();
break;
default:
error("CLK: SPI instance not set");
break;
}
return spi_hz;
}
开发者ID:Archcady,项目名称:mbed-os,代码行数:36,代码来源:spi_api.c
示例4: HAL_TIM_IC_CaptureCallback
/**
* @brief Conversion complete callback in non blocking mode
* @param htim: TIM handle
* @retval None
*/
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
{
if(uhCaptureIndex == 0)
{
/* Get the 1st Input Capture value */
uwIC2Value1 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
uhCaptureIndex = 1;
}
else if(uhCaptureIndex == 1)
{
/* Get the 2nd Input Capture value */
uwIC2Value2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
/* Capture computation */
if (uwIC2Value2 > uwIC2Value1)
{
uwDiffCapture = (uwIC2Value2 - uwIC2Value1);
}
else /* (uwIC2Value2 <= uwIC2Value1) */
{
uwDiffCapture = ((0xFFFF - uwIC2Value1) + uwIC2Value2);
}
/* Frequency computation: for this example TIMx (TIM1) is clocked by
2xAPB2Clk */
uwFrequency = (2*HAL_RCC_GetPCLK2Freq()) / uwDiffCapture;
uhCaptureIndex = 0;
}
}
}
开发者ID:451506709,项目名称:automated_machine,代码行数:37,代码来源:main.c
示例5: uart_get_baudrate
uint32_t uart_get_baudrate(pyb_uart_obj_t *self) {
uint32_t uart_clk = 0;
#if defined(STM32F0)
uart_clk = HAL_RCC_GetPCLK1Freq();
#elif defined(STM32F7)
switch ((RCC->DCKCFGR2 >> ((self->uart_id - 1) * 2)) & 3) {
case 0:
if (self->uart_id == 1 || self->uart_id == 6) {
uart_clk = HAL_RCC_GetPCLK2Freq();
} else {
uart_clk = HAL_RCC_GetPCLK1Freq();
}
break;
case 1:
uart_clk = HAL_RCC_GetSysClockFreq();
break;
case 2:
uart_clk = HSI_VALUE;
break;
case 3:
uart_clk = LSE_VALUE;
break;
}
#elif defined(STM32H7)
uint32_t csel;
if (self->uart_id == 1 || self->uart_id == 6) {
csel = RCC->D2CCIP2R >> 3;
} else {
开发者ID:pfalcon,项目名称:micropython,代码行数:29,代码来源:uart.c
示例6: spi_frequency
void spi_frequency(spi_t *obj, int hz)
{
int spi_hz = 0;
uint8_t prescaler_rank = 0;
/* Get source clock depending on SPI instance */
switch ((int)obj->spi) {
case SPI_1:
/* SPI_1. Source CLK is PCKL2 */
spi_hz = HAL_RCC_GetPCLK2Freq();
break;
case SPI_2:
/* SPI_2. Source CLK is PCKL1 */
spi_hz = HAL_RCC_GetPCLK1Freq();
break;
default:
error("SPI instance not set");
}
/* Define pre-scaler in order to get highest available frequency below requested frequency */
while ((spi_hz > hz) && (prescaler_rank < sizeof(baudrate_prescaler_table)/sizeof(baudrate_prescaler_table[0]))){
spi_hz = spi_hz / 2;
prescaler_rank++;
}
if (prescaler_rank <= sizeof(baudrate_prescaler_table)/sizeof(baudrate_prescaler_table[0])) {
obj->br_presc = baudrate_prescaler_table[prescaler_rank-1];
} else {
error("Couldn't setup requested SPI frequency");
}
init_spi(obj);
}
开发者ID:AlessandroA,项目名称:mbed,代码行数:33,代码来源:spi_api.c
示例7: initTimers
void initTimers()
{
TIM_HandleTypeDef TIM_Handle;
// 10 kHz timer.
#if defined STM32F1
__TIM8_CLK_ENABLE();
TIM_Handle.Instance = TIM8;
TIM_Handle.Init.Prescaler = (uint16_t)(HAL_RCC_GetPCLK2Freq() / 10000) - 1;
#elif defined STM32F2
__TIM4_CLK_ENABLE();
TIM_Handle.Instance = TIM4;
TIM_Handle.Init.Prescaler = (uint16_t)(HAL_RCC_GetPCLK2Freq() / 100000) - 1;
#elif defined STM32F4
__TIM3_CLK_ENABLE();
TIM_Handle.Instance = TIM3;
// TIM3 Clocked from SYSCLK = 168 MHz
TIM_Handle.Init.Prescaler = (uint16_t)(HAL_RCC_GetSysClockFreq() / 10000) - 1;
#endif
// 1 Hz blinking
TIM_Handle.Init.Period = 10000;
TIM_Handle.Init.ClockDivision = 0;
TIM_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
HAL_TIM_Base_Init(&TIM_Handle);
HAL_TIM_PWM_Init(&TIM_Handle);
TIM_OC_InitTypeDef TIM_OCConfig;
TIM_OCConfig.OCMode = TIM_OCMODE_PWM1;
// 5000 / 10000 = 50% duty cycle.
TIM_OCConfig.Pulse = 4999;
TIM_OCConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
TIM_OCConfig.OCFastMode = TIM_OCFAST_DISABLE;
#if defined STM32F1
HAL_TIM_PWM_ConfigChannel(&TIM_Handle, &TIM_OCConfig, TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&TIM_Handle, TIM_CHANNEL_3);
#elif defined STM32F2
HAL_TIM_PWM_ConfigChannel(&TIM_Handle, &TIM_OCConfig, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&TIM_Handle, TIM_CHANNEL_1);
#elif defined STM32F4
HAL_TIM_PWM_ConfigChannel(&TIM_Handle, &TIM_OCConfig, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&TIM_Handle, TIM_CHANNEL_1);
#endif
}
开发者ID:Displacer,项目名称:stm32-cmake,代码行数:46,代码来源:main.c
示例8: pyb_freq
/// \function freq()
/// Return a tuple of clock frequencies: (SYSCLK, HCLK, PCLK1, PCLK2).
// TODO should also be able to set frequency via this function
STATIC mp_obj_t pyb_freq(void) {
mp_obj_t tuple[4] = {
mp_obj_new_int(HAL_RCC_GetSysClockFreq()),
mp_obj_new_int(HAL_RCC_GetHCLKFreq()),
mp_obj_new_int(HAL_RCC_GetPCLK1Freq()),
mp_obj_new_int(HAL_RCC_GetPCLK2Freq()),
};
return mp_obj_new_tuple(4, tuple);
}
开发者ID:patrickhpunkt,项目名称:micropython,代码行数:12,代码来源:modpyb.c
示例9: IRDA_SetConfig
/**
* @brief Configure the IRDA peripheral
* @param hirda: irda handle
* @retval None
*/
static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
{
uint32_t tmpreg = 0x00000000;
IRDA_ClockSourceTypeDef clocksource = IRDA_CLOCKSOURCE_UNDEFINED;
HAL_StatusTypeDef ret = HAL_OK;
/* Check the communication parameters */
assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode));
assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler));
assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode));
/*-------------------------- USART CR1 Configuration -----------------------*/
/* Configure the IRDA Word Length, Parity and transfer Mode:
Set the M bits according to hirda->Init.WordLength value
Set PCE and PS bits according to hirda->Init.Parity value
Set TE and RE bits according to hirda->Init.Mode value */
tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ;
MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg);
/*-------------------------- USART CR3 Configuration -----------------------*/
MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode);
/*-------------------------- USART GTPR Configuration ----------------------*/
MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
/*-------------------------- USART BRR Configuration -----------------------*/
__HAL_IRDA_GETCLOCKSOURCE(hirda, clocksource);
switch (clocksource)
{
case IRDA_CLOCKSOURCE_PCLK1:
hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hirda->Init.BaudRate);
break;
case IRDA_CLOCKSOURCE_PCLK2:
hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK2Freq() / hirda->Init.BaudRate);
break;
case IRDA_CLOCKSOURCE_HSI:
hirda->Instance->BRR = (uint16_t)(HSI_VALUE / hirda->Init.BaudRate);
break;
case IRDA_CLOCKSOURCE_SYSCLK:
hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hirda->Init.BaudRate);
break;
case IRDA_CLOCKSOURCE_LSE:
hirda->Instance->BRR = (uint16_t)(LSE_VALUE / hirda->Init.BaudRate);
break;
case IRDA_CLOCKSOURCE_UNDEFINED:
default:
ret = HAL_ERROR;
break;
}
return ret;
}
开发者ID:ramonnr,项目名称:STM32F303-watchdog-demo,代码行数:61,代码来源:stm32f3xx_hal_irda.c
示例10: py_cpufreq_get_current_frequencies
mp_obj_t py_cpufreq_get_current_frequencies()
{
mp_obj_t tuple[4] = {
mp_obj_new_int(cpufreq_get_cpuclk() / (1000000)),
mp_obj_new_int(HAL_RCC_GetHCLKFreq() / (1000000)),
mp_obj_new_int(HAL_RCC_GetPCLK1Freq() / (1000000)),
mp_obj_new_int(HAL_RCC_GetPCLK2Freq() / (1000000)),
};
return mp_obj_new_tuple(4, tuple);
}
开发者ID:openmv,项目名称:openmv,代码行数:10,代码来源:py_cpufreq.c
示例11: SMARTCARD_SetConfig
/**
* @brief Configures the SMARTCARD peripheral.
* @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
* the configuration information for the specified SMARTCARD module.
* @retval None
*/
static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc)
{
/* Check the parameters */
assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity));
assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase));
assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit));
assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate));
assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength));
assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits));
assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity));
assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode));
assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
/* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */
CLEAR_BIT(hsc->Instance->CR1, (uint32_t)(USART_CR1_TE | USART_CR1_RE));
/*-------------------------- SMARTCARD CR2 Configuration ------------------------*/
/* Clear CLKEN, CPOL, CPHA and LBCL bits */
/* Configure the SMARTCARD Clock, CPOL, CPHA and LastBit -----------------------*/
/* Set CPOL bit according to hsc->Init.CLKPolarity value */
/* Set CPHA bit according to hsc->Init.CLKPhase value */
/* Set LBCL bit according to hsc->Init.CLKLastBit value */
MODIFY_REG(hsc->Instance->CR2,
((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL)),
((uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity | hsc->Init.CLKPhase| hsc->Init.CLKLastBit)) );
/* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
MODIFY_REG(hsc->Instance->CR2, USART_CR2_STOP,(uint32_t)(hsc->Init.StopBits));
/*-------------------------- SMARTCARD CR1 Configuration -----------------------*/
/* Clear M, PCE, PS, TE and RE bits */
/* Configure the SMARTCARD Word Length, Parity and mode:
Set the M bits according to hsc->Init.WordLength value
Set PCE and PS bits according to hsc->Init.Parity value
Set TE and RE bits according to hsc->Init.Mode value */
MODIFY_REG(hsc->Instance->CR1,
((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE)),
((uint32_t)(hsc->Init.WordLength | hsc->Init.Parity | hsc->Init.Mode)) );
/*-------------------------- USART CR3 Configuration -----------------------*/
/* Clear CTSE and RTSE bits */
CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
/*-------------------------- USART BRR Configuration -----------------------*/
if(hsc->Instance == USART1)
{
hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate);
}
else
{
hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate);
}
}
开发者ID:1deus,项目名称:tmk_keyboard,代码行数:61,代码来源:stm32l1xx_hal_smartcard.c
示例12: spi_getClkFreqInst
/**
* @brief return clock freq of an SPI instance
* @param spi_inst : SPI instance
* @retval clock freq of the instance else SystemCoreClock
*/
uint32_t spi_getClkFreqInst(SPI_TypeDef * spi_inst)
{
uint32_t spi_freq = SystemCoreClock;
#ifdef STM32F0xx
UNUSED(spi_inst);
/* SPIx source CLK is PCKL1 */
spi_freq = HAL_RCC_GetPCLK1Freq();
#else
if(spi_inst != NP) {
/* Get source clock depending on SPI instance */
switch ((uint32_t)spi_inst) {
#if defined(SPI1_BASE) || defined(SPI4_BASE) || defined(SPI5_BASE) || defined(SPI16_BASE)
/* Some STM32's (eg. STM32F302x8) have no SPI1, but do have SPI2/3. */
#if defined SPI1_BASE
case (uint32_t)SPI1:
#endif
#if defined SPI4_BASE
case (uint32_t)SPI4:
#endif
#if defined SPI5_BASE
case (uint32_t)SPI5:
#endif
#if defined SPI6_BASE
case (uint32_t)SPI6:
#endif
/* SPI1, SPI4, SPI5 and SPI6. Source CLK is PCKL2 */
spi_freq = HAL_RCC_GetPCLK2Freq();
break;
#endif /* SPI[1456]_BASE */
#if defined(SPI2_BASE) || defined (SPI3_BASE)
#if defined SPI2_BASE
case (uint32_t)SPI2:
#endif
#if defined SPI3_BASE
case (uint32_t)SPI3:
#endif
/* SPI_2 and SPI_3. Source CLK is PCKL1 */
spi_freq = HAL_RCC_GetPCLK1Freq();
break;
#endif
default:
printf("CLK: SPI instance not set");
break;
}
}
#endif
return spi_freq;
}
开发者ID:amassou2017,项目名称:Arduino_Core_STM32,代码行数:55,代码来源:spi_com.c
示例13: timer_init
int timer_init(hacs_timer_t tim, hacs_timer_mode_t mode)
{
uint32_t clock_freq;
uint32_t presc;
TIM_HandleTypeDef *htim = &tim_handles[tim];
TIM_TypeDef *inst = hacs_tim_instances[tim];
tim_overflow_cb[tim] = NULL;
// First, find the appropriate prescaler to achieve microsecond resolution
if (inst == TIM1 || inst == TIM10 || inst == TIM11) {
// For stm32f411, these 3 timers are on the APB2 bus
clock_freq = HAL_RCC_GetPCLK2Freq();
} else {
clock_freq = HAL_RCC_GetPCLK1Freq();
}
presc = clock_freq / TIMER_RESOLUTION_FREQ;
// Setup timer base
htim->Instance = inst;
htim->Init.Prescaler = presc;
htim->Init.CounterMode = TIM_COUNTERMODE_UP;
htim->Init.Period = 0;
htim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim->Init.RepetitionCounter = 0;
HAL_TIM_Base_Init(htim);
if (mode == HACS_TIMER_MODE_PWM) {
TIM_OC_InitTypeDef sConfigOC;
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
// NOTE: Assume there are 4 PWM channels on each timer, and that all of them are used.
HAL_TIM_PWM_ConfigChannel(htim, &sConfigOC, TIM_CHANNEL_1);
HAL_TIM_PWM_ConfigChannel(htim, &sConfigOC, TIM_CHANNEL_2);
HAL_TIM_PWM_ConfigChannel(htim, &sConfigOC, TIM_CHANNEL_3);
HAL_TIM_PWM_ConfigChannel(htim, &sConfigOC, TIM_CHANNEL_4);
}
return HACS_NO_ERROR;
}
开发者ID:gzwsc2007,项目名称:Hobby_Airplane_Control_System,代码行数:47,代码来源:hacs_timer.c
示例14: HAL_InitTick
/**
* @brief This function configures the TIM1 as a time base source.
* The time source is configured to have 1ms time base with a dedicated
* Tick interrupt priority.
* @note This function is called automatically at the beginning of program after
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
* @param TickPriority: Tick interrupt priorty.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock = 0;
uint32_t uwPrescalerValue = 0;
uint32_t pFLatency;
/*Configure the TIM1 IRQ priority */
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, TickPriority ,0);
/* Enable the TIM1 global Interrupt */
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
/* Enable TIM1 clock */
__HAL_RCC_TIM1_CLK_ENABLE();
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* Compute TIM1 clock */
uwTimclock = HAL_RCC_GetPCLK2Freq();
/* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000) - 1);
/* Initialize TIM1 */
htim1.Instance = TIM1;
/* Initialize TIMx peripheral as follow:
+ Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base.
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
+ ClockDivision = 0
+ Counter direction = Up
*/
htim1.Init.Period = (1000000 / 1000) - 1;
htim1.Init.Prescaler = uwPrescalerValue;
htim1.Init.ClockDivision = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_Base_Init(&htim1) == HAL_OK)
{
/* Start the TIM time Base generation in interrupt mode */
return HAL_TIM_Base_Start_IT(&htim1);
}
/* Return function status */
return HAL_ERROR;
}
开发者ID:tgack,项目名称:gnubio,代码行数:56,代码来源:stm32f3xx_hal_timebase_TIM.c
示例15: IRDA_SetConfig
/**
* @brief Configures the IRDA peripheral.
* @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
* the configuration information for the specified IRDA module.
* @retval None
*/
static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
{
uint32_t tmpreg = 0x00;
/* Check the parameters */
assert_param(IS_IRDA_INSTANCE(hirda->Instance));
assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
assert_param(IS_IRDA_MODE(hirda->Init.Mode));
/*-------------------------- IRDA CR2 Configuration ------------------------*/
/* Clear STOP[13:12] bits */
hirda->Instance->CR2 &= (uint32_t)~((uint32_t)USART_CR2_STOP);
/*-------------------------- USART CR1 Configuration -----------------------*/
tmpreg = hirda->Instance->CR1;
/* Clear M, PCE, PS, TE and RE bits */
tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
USART_CR1_RE));
/* Configure the USART Word Length, Parity and mode:
Set the M bits according to hirda->Init.WordLength value
Set PCE and PS bits according to hirda->Init.Parity value
Set TE and RE bits according to hirda->Init.Mode value */
tmpreg |= (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode;
/* Write to USART CR1 */
hirda->Instance->CR1 = (uint32_t)tmpreg;
/*-------------------------- USART CR3 Configuration -----------------------*/
/* Clear CTSE and RTSE bits */
hirda->Instance->CR3 &= (uint32_t)~((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE));
/*-------------------------- USART BRR Configuration -----------------------*/
if((hirda->Instance == USART1) || (hirda->Instance == USART6))
{
hirda->Instance->BRR = __IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate);
}
else
{
hirda->Instance->BRR = __IRDA_BRR(HAL_RCC_GetPCLK1Freq(), hirda->Init.BaudRate);
}
}
开发者ID:12019,项目名称:openmv,代码行数:51,代码来源:stm32f4xx_hal_irda.c
示例16: stm32_spi_resolve_prescaler
static int
stm32_spi_resolve_prescaler(uint8_t spi_num, uint32_t baudrate, uint32_t *prescaler)
{
uint32_t candidate_br;
uint32_t apbfreq;
int i;
/* SPIx {1,4,5,6} use PCLK2 on the STM32F4/F7, otherwise use PCKL1.
* The numbers in the switch below are offset by 1, because the HALs index
* SPI ports from 0.
*/
switch (spi_num) {
case 0:
case 3:
case 4:
case 5:
apbfreq = HAL_RCC_GetPCLK2Freq();
break;
default:
apbfreq = HAL_RCC_GetPCLK1Freq();
break;
}
if (baudrate == 0) {
*prescaler = 0;
return 0;
}
/* Calculate best-fit prescaler: divide the clock by each subsequent
* prescaler until we reach the highest prescaler that generates at
* _most_ the baudrate.
*/
*prescaler = SPI_BAUDRATEPRESCALER_256;
for (i = 0; i < 8; i++) {
candidate_br = apbfreq >> (i + 1);
if (candidate_br <= baudrate) {
*prescaler = i << SPI_CR1_BR_Pos;
break;
}
}
return (0);
}
开发者ID:bgiori,项目名称:incubator-mynewt-core,代码行数:43,代码来源:hal_spi.c
示例17: TM_SPI_GetPrescalerFromMaxFrequency
uint16_t TM_SPI_GetPrescalerFromMaxFrequency(SPI_TypeDef* SPIx, uint32_t MAX_SPI_Frequency) {
uint32_t APB_Frequency;
uint8_t i;
/* Prevent false input */
if (MAX_SPI_Frequency == 0) {
return SPI_BAUDRATEPRESCALER_256;
}
/* Calculate max SPI clock */
if (0
#ifdef SPI1
|| SPIx == SPI1
#endif
#ifdef SPI4
|| SPIx == SPI4
#endif
#ifdef SPI5
|| SPIx == SPI5
#endif
#ifdef SPI6
|| SPIx == SPI6
#endif
) {
APB_Frequency = HAL_RCC_GetPCLK2Freq();
} else {
APB_Frequency = HAL_RCC_GetPCLK1Freq();
}
/* Calculate prescaler value */
/* Bits 5:3 in CR1 SPI registers are prescalers */
/* 000 = 2, 001 = 4, 002 = 8, ..., 111 = 256 */
for (i = 0; i < 8; i++) {
if (APB_Frequency / (1 << (i + 1)) <= MAX_SPI_Frequency) {
/* Bits for BP are 5:3 in CR1 register */
return (i << 3);
}
}
/* Use max prescaler possible */
return SPI_BAUDRATEPRESCALER_256;
}
开发者ID:EduardoG26,项目名称:stm32fxxx_hal_libraries,代码行数:42,代码来源:tm_stm32_spi.c
示例18: pyb_timer_init_helper
STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
mp_arg_val_t vals[PYB_TIMER_INIT_NUM_ARGS];
mp_arg_parse_all(n_args, args, kw_args, PYB_TIMER_INIT_NUM_ARGS, pyb_timer_init_args, vals);
// set the TIM configuration values
TIM_Base_InitTypeDef *init = &self->tim.Init;
if (vals[0].u_int != 0xffffffff) {
// set prescaler and period from frequency
if (vals[0].u_int == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "can't have 0 frequency"));
}
// work out TIM's clock source
uint tim_clock;
if (self->tim_id == 1 || (8 <= self->tim_id && self->tim_id <= 11)) {
// TIM{1,8,9,10,11} are on APB2
tim_clock = HAL_RCC_GetPCLK2Freq();
} else {
// TIM{2,3,4,5,6,7,12,13,14} are on APB1
tim_clock = HAL_RCC_GetPCLK1Freq();
}
// Compute the prescaler value so TIM triggers at freq-Hz
// On STM32F405/407/415/417 there are 2 cases for how the clock freq is set.
// If the APB prescaler is 1, then the timer clock is equal to its respective
// APB clock. Otherwise (APB prescaler > 1) the timer clock is twice its
// respective APB clock. See DM00031020 Rev 4, page 115.
uint32_t period = MAX(1, 2 * tim_clock / vals[0].u_int);
uint32_t prescaler = 1;
while (period > TIMER_CNT_MASK(self)) {
period >>= 1;
prescaler <<= 1;
}
init->Prescaler = prescaler - 1;
init->Period = period - 1;
} else if (vals[1].u_int != 0xffffffff && vals[2].u_int != 0xffffffff) {
开发者ID:andrecurvello,项目名称:micropython,代码行数:39,代码来源:timer.c
示例19: MyUARTSetConfig
/** @brief: set registers acc to info in huart
* @details: used in HAL_UART3Debug_Init, private
****************************************************************/
static void MyUARTSetConfig(UART_HandleTypeDef * huart) {
uint32_t tmpreg = 0x00;
/* Check the parameters */
assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
assert_param(IS_UART_PARITY(huart->Init.Parity));
assert_param(IS_UART_MODE(huart->Init.Mode));
/*------- UART-associated USART registers setting : CR2 Configuration ------*/
/* Configure the UART Stop Bits: Set STOP[13:12] bits according
* to huart->Init.StopBits value */
MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits);
/*------- UART-associated USART registers setting : CR1 Configuration ------*/
/* Configure the UART Word Length, Parity and mode:
Set the M bits according to huart->Init.WordLength value
Set PCE and PS bits according to huart->Init.Parity value
Set TE and RE bits according to huart->Init.Mode value */
tmpreg = (uint32_t) huart->Init.WordLength | huart->Init.Parity
| huart->Init.Mode;
MODIFY_REG(huart->Instance->CR1,
(uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE),
tmpreg);
/*------- UART-associated USART registers setting : CR3 Configuration ------*/
/* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */
MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE),
huart->Init.HwFlowCtl);
/*------- UART-associated USART registers setting : BRR Configuration ------*/
if ((huart->Instance == USART1)) {
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(),
huart->Init.BaudRate);
} else {
huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(),
huart->Init.BaudRate);
}
}
开发者ID:glocklueng,项目名称:myLib,代码行数:42,代码来源:cUartPort.c
示例20: extclk_config
static void extclk_config(int frequency)
{
/* TCLK (PCLK2 * 2) */
int tclk = HAL_RCC_GetPCLK2Freq() * 2;
/* SYSCLK/TCLK = No prescaler */
int prescaler = (uint16_t) (HAL_RCC_GetSysClockFreq()/ tclk) - 1;
/* Period should be even */
int period = (tclk / frequency)-1;
/* Timer base configuration */
TIMHandle.Instance = DCMI_TIM;
TIMHandle.Init.Period = period;
TIMHandle.Init.Prescaler = prescaler;
TIMHandle.Init.ClockDivision = 0;
TIMHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
/* Timer channel configuration */
TIM_OC_InitTypeDef TIMOCHandle;
TIMOCHandle.Pulse = period/2;
TIMOCHandle.OCMode = TIM_OCMODE_PWM1;
TIMOCHandle.OCPolarity = TIM_OCPOLARITY_HIGH;
TIMOCHandle.OCFastMode = TIM_OCFAST_DISABLE;
TIMOCHandle.OCIdleState = TIM_OCIDLESTATE_RESET;
if (HAL_TIM_PWM_Init(&TIMHandle) != HAL_OK) {
/* Initialization Error */
BREAK();
}
if (HAL_TIM_PWM_ConfigChannel(&TIMHandle, &TIMOCHandle, DCMI_TIM_CHANNEL) != HAL_OK) {
BREAK();
}
if (HAL_TIM_PWM_Start(&TIMHandle, DCMI_TIM_CHANNEL) != HAL_OK) {
BREAK();
}
}
开发者ID:dhylands,项目名称:openmv,代码行数:38,代码来源:sensor.c
注:本文中的HAL_RCC_GetPCLK2Freq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论