使用
STM32L073RZ开发的过程中,有两个疑问请网友帮忙解答一下。谢谢!
1)在STM32L073上使用4个串口,不包括LPUART。配置USART4和5时,HAL库中定义了USART4_5_IRQn作为中断向量。是否会导致中断乱入,或者不可控。有没有网友同时使用过?如果有深入理解的朋友,能不能对原理做下解释。
/*!< Interrupt Number Defini
tion */
typedef enum
{
/****** Cortex-M0 Processor Exceptions Numbers ******************************************************/
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
HardFault_IRQn = -13, /*!< 3 Cortex-M0+ Hard Fault Interrupt */
SVC_IRQn = -5, /*!< 11 Cortex-M0+ SV Call Interrupt */
PendSV_IRQn = -2, /*!< 14 Cortex-M0+ Pend SV Interrupt */
SysTick_IRQn = -1, /*!< 15 Cortex-M0+ System Tick Interrupt */
/****** STM32L-0 specific Interrupt Numbers *********************************************************/
WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */
PVD_IRQn = 1, /*!< PVD through EXTI Line detect Interrupt */
RTC_IRQn = 2, /*!< RTC through EXTI Line Interrupt */
FLASH_IRQn = 3, /*!< FLASH Interrupt */
RCC_CRS_IRQn = 4, /*!< RCC and CRS Interrupts */
EXTI0_1_IRQn = 5, /*!< EXTI Line 0 and 1 Interrupts */
EXTI2_3_IRQn = 6, /*!< EXTI Line 2 and 3 Interrupts */
EXTI4_15_IRQn = 7, /*!< EXTI Line 4 to 15 Interrupts */
TSC_IRQn = 8, /*!< TSC Interrupt */
DMA1_Channel1_IRQn = 9, /*!< DMA1 Channel 1 Interrupt */
DMA1_Channel2_3_IRQn = 10, /*!< DMA1 Channel 2 and Channel 3 Interrupts */
DMA1_Channel4_5_6_7_IRQn = 11, /*!< DMA1 Channel 4, Channel 5, Channel 6 and Channel 7 Interrupts */
ADC1_COMP_IRQn = 12, /*!< ADC1, COMP1 and COMP2 Interrupts */
LPTIM1_IRQn = 13, /*!< LPTIM1 Interrupt */
USART4_5_IRQn = 14, /*!< USART4 and USART5 Interrupt */
TIM2_IRQn = 15, /*!< TIM2 Interrupt */
TIM3_IRQn = 16, /*!< TIM3 Interrupt */
TIM6_DAC_IRQn = 17, /*!< TIM6 and DAC Interrupts */
TIM7_IRQn = 18, /*!< TIM7 Interrupt */
TIM21_IRQn = 20, /*!< TIM21 Interrupt */
I2C3_IRQn = 21, /*!< I2C3 Interrupt */
TIM22_IRQn = 22, /*!< TIM22 Interrupt */
I2C1_IRQn = 23, /*!< I2C1 Interrupt */
I2C2_IRQn = 24, /*!< I2C2 Interrupt */
SPI1_IRQn = 25, /*!< SPI1 Interrupt */
SPI2_IRQn = 26, /*!< SPI2 Interrupt */
USART1_IRQn = 27, /*!< USART1 Interrupt */
USART2_IRQn = 28, /*!< USART2 Interrupt */
RNG_LPUART1_IRQn = 29, /*!< RNG and LPUART1 Interrupts */
LCD_IRQn = 30, /*!< LCD Interrupt */
USB_IRQn = 31, /*!< USB global Interrupt */
} IRQn_Type;
配置USART4的代码:
....
__HAL_RCC_USART4_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_USART4;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(
USART4_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(
USART4_5_IRQn);
.....
配置USART5的代码基本也类似。中断向量号IRQn也完全一样,这样USART4和5不会冲突吗?
2)配置USART2的GPIO的Alternate 时,有:
GPIO_InitStruct.Alternate =
GPIO_AF0_USART2;
也有:
GPIO_InitStruct.Alternate =
GPIO_AF4_USART2;
这里的
AF0和AF4只见存在怎样的差异,对
芯片实际有什么影响?
谢谢各位不吝指点!
看的不仔细。跳着看的。
本帖最后由 ataudio 于 2017-7-5 14:08 编辑
请教第二个问题,GPIO_AF0_USART2和GPIO_AF4_USART2这样的设置有什么区别呢?
现在查到了。根据参考手册,查找数据手册的ALternate function map可以找到说明。
多看数据手册和範例程式…很多問題自己都可解決
一周热门 更多>