AnsweredAssumed Answered

STM32F400 USART NVIC_Configuration

Question asked by duarte.andre on Mar 25, 2014
Latest reply on Aug 14, 2014 by duarte.andre
Hi,

Im trying to setup the interrupt engine for an usart without success (MCBSTM32F400 v1.1 board)
The code throws an "HardFault_Handler" exception, executing NVIC_Init(&NVIC_InitStructure).
Without initializing the NVIC the USART works well.

I tried with Keil.STM32F4xx_DFP 2.0.0 and Keil.STM32F4xx_DFP 1.0.6
Im using Keil V5. Im having problems in finding the NVIC structure so ive put the \\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.0.0\Device\StdPeriph_Driver\src\misc.c file in the source files folder.
Also defined the USE_STDPERIPH_DRIVER STM32F4XX in the preprocessor symbols, compiled without issues.

The same code works on the STM32F429-DISCOVERY board (with the interrupt engine) !

##############################################################################################################
##############################################################################################################
##############################################################################################################
volatile char StringLoop[1] = "a";


//
//
//
void RCC_Configuration(void)
{
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);                                      // USART 3 clock enable
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);                                       // GPIOC clock enable
}


//
//
//
void GPIO_Configuration(void)
{
    GPIO_InitTypeDef    GPIO_InitStructure;


    GPIO_StructInit(&GPIO_InitStructure);


    GPIO_InitStructure.GPIO_Pin                     = GPIO_Pin_10 | GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode                    = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType                   = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd                    = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed                   = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);   
    
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);                                  // Connect USART pins to AF ; USART3_TX
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);                                  // Connect USART pins to AF ; USART3_RX   
}


//
//
//
void USART3_Configuration(void)
{
    USART_InitTypeDef   USART_InitStructure;
    
    USART_InitStructure.USART_BaudRate              = 115200;
    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_Rx | USART_Mode_Tx;


    USART_Init(USART3, &USART_InitStructure);   


    USART_ITConfig(USART3, USART_IT_TXE, ENABLE);  
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);                                              // enable the USART1 receive interrupt             


    USART_Cmd(USART3, ENABLE);
}


//
//
//
void NVIC_Configuration(void)
{
    NVIC_InitTypeDef    NVIC_InitStructure;


    NVIC_InitStructure.NVIC_IRQChannel                        = USART3_IRQn;                      // we want to configure the USART3 interrupts
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority      = 0;                              // this sets the priority group of the USART3 interrupts
     NVIC_InitStructure.NVIC_IRQChannelSubPriority             = 0;                                  // this sets the subpriority inside the group
     NVIC_InitStructure.NVIC_IRQChannelCmd                     = ENABLE;                               // the USART3 interrupts are globally enabled
     NVIC_Init(&NVIC_InitStructure);                                                                       // the properties are passed to the NVIC_Init function which takes care of the low level stuff        
}


//
// This is the interrupt request handler (IRQ) for ALL USART3 interrupts
//
void USART3_IRQHandler(void)
{
    if (USART_GetITStatus(USART3, USART_IT_TXE) != RESET)                                       // Transmit the string in a loop
    {
        USART_SendData(USART3, StringLoop[0]);
    }


    if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)                                       // Received characters modify string
    {
        StringLoop[0] = USART_ReceiveData(USART3);
    }
}


//
//
//
int main (void) 
{
    RCC_Configuration();
    GPIO_Configuration();
    NVIC_Configuration();   
    USART3_Configuration();


    /*
    while(1)
    {
        uint16_t Data;
  
        while(USART_GetITStatus(USART3, USART_IT_RXNE) == RESET);                               // Wait for Char
        Data = USART_ReceiveData(USART3);                                                       // Collect Char
        while(USART_GetITStatus(USART3, USART_IT_TXE) == RESET);                                // Wait for Empty
        USART_SendData(USART3, Data);                                                           // Echo Char
        osDelay(1);
    }
    */
    
    while(1);
}





Outcomes