cancel
Showing results for 
Search instead for 
Did you mean: 

USART3_4_IRQn undefined

stenasc
Senior
Posted on November 16, 2016 at 10:07

Hi Forum,

I'm looking to implement USART3 on the stm32091, but get the following error

 error:  #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.

Bob

void 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);

   }

5 REPLIES 5
Posted on November 16, 2016 at 12:08

> 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)?

JW

stenasc
Senior
Posted on November 16, 2016 at 13:41

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.

Bob

Posted on November 16, 2016 at 13:59

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.

JW

stenasc
Senior
Posted on November 16, 2016 at 15:26

Yes, it is SPL V1.5

Bob

Posted on November 16, 2016 at 16:00

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 STM32F091

void USART3_8_IRQHandler(void) // Handler for 3 thru 8

#else

void USART3_4_IRQHandler(void) // Handler for 3 and 4

#endif

{

...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..