USART2_IRQHandler firing only once
ekorre opened this issue · 1 comments
ekorre commented
Hello,
I fail to understand why I only get USART2_IRQHandler to only fire once. I follow a very simple example. PA2 and PA3 shorted together on a ch32v307 R1 EVK.
#include "ch32v30x_conf.h"
#include "debug.h"
#include <stdio.h>
#include <stdint.h>
void USART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USART2_IRQHandler(void)
{
static int cnt = 0;
printf("%d\r\n", cnt++);
}
void init_uart(void)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
USART_InitTypeDef USART_InitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* USART2 TX-->A.2 RX-->A.3 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART2, ENABLE);
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Delay_Init();
USART_Printf_Init(115200);
SystemCoreClockUpdate();
printf("SystemClk:%d\r\n", SystemCoreClock);
init_uart();
while(1) {
Delay_Ms(1000);
USART_SendData(USART2, 'x');
printf("%c\r\n", USART_ReceiveData(USART2));
};
return 0;
}
I am getting the following as output. I would expect the counter in the ISR to be printed and incremented, but I only get "0".
SystemClk:144000000
0
x
x
x
...
Any idea where my issue could be? Thanks in advance.
ekorre commented
Solved. It seems that the interrupt routine lacks mret.
See cnlohr/ch32v003fun#90 for details.