DISCO L476 USART 3 not working

Sysprogs forums Forums VisualGDB DISCO L476 USART 3 not working

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12736
    rotemse
    Participant

    I designed a board based on the Disco L476. I used MBED with the L476 board as the chosen platform and the program worked well.

    I wanted to move to VisualGDB and so I ported the project and everything worked. Then I tried to check USART3.

    At first when I declared the TX RX pins (PD_8, PD_9 in my design) I got an error “pinmap not found for peripheral”  in the COM port window. So I searched for pin configurations, and indeed these two pins were missing in the PinMap PinMap_UART_RX[] and PinMap PinMap_UART_TX[] declarations in “”PeripheralPins.c”.

    So I added these lines:

    {PD_8, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},     //added to PinMap PinMap_UART_TX[]

    and

    {PD_9, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},   //added to PinMap PinMap_UART_RX[]

     

    Now I don’t get the “pinmap not found for peripheral” message anymore, but I also don’t receive any serial data for this port (I can’t see any data received). I checked with an external logic analyzer that the receive pin indeed receives data.

    Here is my declaration:

    GPS_Serial.baud(9600);
    GPS_Serial.format(8, SerialBase::None, 1);
    GPS_Serial.attach(&GPSCallback);

    void GPSCallback()
    {
    e = GPS_Serial.getc();
    pc.putc(e);
    }

     

    Could it be that the USART3 can’t register itself to receive interrupts?

     

    Thanks

    #12738
    support
    Keymaster

    Hi,

    Generally in order for a USART to work, you need to ensure the following:

    • The peripheral clock for this USART is enabled
    • The corresponding pins are configured to work as USART
    • You configure the peripheral correctly (e.g. set the baud rate) and write the correct data registers

    We have a detailed tutorial showing how to use STM32 UART here: https://visualgdb.com/tutorials/arm/stm32/uart/hal/

    Generally we would advise first sorting this out on a regular non-MBED project and then stepping through the mbed source code to ensure that it does the same initialization/configuration steps as your non-mbed project (hardware register window can help double-check that the necessary parts got initialized).

    #12740
    rotemse
    Participant

    all the other UARTS are working well with the same MBED code running in VisualGDB.

    I didn’t change anything…

     

    #12744
    support
    Keymaster

    Hi,

    We understand you didn’t change anything, however sometimes the problems are caused by unexpected combinations of small changes or incompatible settings that are hard to predict. We advise following the diagnostic steps in the previous post to resolve this.

    #12776
    rotemse
    Participant

    Hi

    I tried the example from the URL, but I still can’t receive any serial data. Transmitting serial data works well.

    I am using interrupts.

    Here is my code.

    #ifdef __cplusplus
     extern "C"
     #endif
     void SysTick_Handler(void)
     {
     HAL_IncTick();
     HAL_SYSTICK_IRQHandler();
     }
    
    static UART_HandleTypeDef s_UARTHandle = UART_HandleTypeDef();
    
    void initRS485()
     {
     HAL_Init();
    
    __USART3_CLK_ENABLE();
     __GPIOC_CLK_ENABLE();
    
    GPIO_InitTypeDef GPIO_InitStructure;
    
    GPIO_InitStructure.Pin = GPIO_PIN_10;
     GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStructure.Alternate = GPIO_AF7_USART3;
     GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
     GPIO_InitStructure.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    GPIO_InitStructure.Pin = GPIO_PIN_11;
     GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    s_UARTHandle.Instance        = USART3;
     s_UARTHandle.Init.BaudRate   = 115200;
     s_UARTHandle.Init.WordLength = UART_WORDLENGTH_8B;
     s_UARTHandle.Init.StopBits   = UART_STOPBITS_1;
     s_UARTHandle.Init.Parity     = UART_PARITY_NONE;
     s_UARTHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
     s_UARTHandle.Init.Mode       = UART_MODE_TX_RX;
    
    if (HAL_UART_Init(&s_UARTHandle) != HAL_OK)
     pc.printf("error\r\n");
     HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
     HAL_NVIC_EnableIRQ(USART3_IRQn);
    
    }
    
    void USART3_IRQHandler()
     {
     HAL_UART_IRQHandler(&s_UARTHandle);
     }
     void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
     {
     if (huart->Instance == USART3)
     {
     // Your buffer is full with your data process it here or set a flag
     pc.printf("%d",buffer3);
     }
     }
    
    
    
    
    int main(void)
     {
    
    initRS485();
     for (;;)
     {
     HAL_UART_Receive_IT(&s_UARTHandle, (uint8_t *)buffer3, sizeof(buffer3));
    
    //some coder here
    
    }
    
    }
    • This reply was modified 6 years, 5 months ago by support. Reason: formatting
    #12778
    support
    Keymaster

    Hi,

    You might be missing extern “C” around your interrupt handler. Please also note that our support is limited to issues related to VisualGDB. For general programming problems and troubleshooting issues with your code please use other resources like StackOverflow to get help from other community members.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.