2016-11-16 01:07 AM
Hi Forum,
I'm looking to implement USART3 on the stm32091, but get the following errorerror: #20: identifier ''USART3_4_IRQn'' is undefined.
when I compile at the following line. NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;It looks like USART3_4_IRQn is defined in stm32f0xx.h as is USART3_8_IRQn.This was previously a stm32f051 project which had been ported across.
The following code is the configuration for USART3.Any help greatly appreciated.Bobvoid Usart3Init(void)
{USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
// Enable GPIOA and DMA clock
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB , ENABLE);
// Enable USART3 APB clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
// Connect pin to Periph
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_1);
// Configure pins as AF pushpull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; // CTS pin
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
GPIO_Init(GPIOB, &GPIO_InitStructure); /// GPIO D
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ; // RTS pin
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// GPIO_WriteBit(GPIOA,GPIO_Pin_1, RESET);// LOW
// USARTx configured as follow:
//- BaudRate = 19200 baud
//- Word Length = 8 Bits
//- Stop Bit = 1 Stop Bit
//- Parity = No Parity
//- Hardware flow control disabled (RTS and CTS signals)
//- Receive and transmit enabled
// USART_DeInit(USART3);
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_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
// // Enable the COM2 Receive interrupt: this interrupt is generated when the // COM3 receive data register is not empty
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
// USART3 IRQ Channel configuration
NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
2016-11-16 03:08 AM
> error: #20: identifier ''USART3_4_IRQn'' is undefined.
If it is defined in a header, then you either don't include that header, or the identifier is misspelled. Isn't the definiton of that symbol enclosed in some preprocessor conditional (#if, #ifdef)? JW2016-11-16 04:41 AM
Header should be include as USART1 and USART2 are working OK and you are correct, it is enclosed in pre-processor conditional. When the target device is selected on the toolset, this should be automatically taken care of. Will have another look.
Bob2016-11-16 04:59 AM
The code you presented does not use symbols from the CMSIS header, only ''library'' symbols (is it SPL? I don't use that nor Cube so I have troubles distinguish them).
It may well be that that ''library'' includes the CMSIS header in some form; but it then may as well be that it's a header from a different directory than you thought. And, of course, the question of conditionals and defined symbols... You can use the pre-processor's facilities (if there are any available in your toolchain) to untangle these. JW2016-11-16 06:26 AM
Yes, it is SPL V1.5
Bob2016-11-16 07:00 AM
The STM32F091 has more USART, the IRQ Handler now handles sources of 3 thru 8 rather than just 3 thru 4
#ifdef STM32F091 NVIC_InitStructure.NVIC_IRQChannel = USART3_8_IRQn;#else NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;#endif#ifdef STM32F091void USART3_8_IRQHandler(void) // Handler for 3 thru 8#elsevoid USART3_4_IRQHandler(void) // Handler for 3 and 4#endif{...