Skip to main content
Associate III
April 30, 2024
Solved

Problem adding USART3 functionality to LwIP_HTTP_Server_Netconn_RTOS demo

  • April 30, 2024
  • 8 replies
  • 1896 views

Hi,

 

I'm having troubles to add USART communication to the LwIP_HTTP_Server_Netconn_RTOS demo from ST. I need to add communications using USART1 & USART3 to the example but have been stuck with HAL_UART_Transmit() returning 3. I came up with a little example to show the issue I'm facing:

Can someone help out?

I want to use pins PD8 for Tx and PD9 for Rx (STM32F439ZI) but have not found where this would be set and I suspect that PB10 & PB11 are being used by mistake (and may conflict with ETH_MII_RX & ETH_MII_TX).

Thanks!

int uart_test(void)
{
int rv = OK;
char cmd[ZABER_STR_LEN]={0};
enum zaber_dev dev = ZAB_BOTH;

huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; // No hardware flow control
huart3.Init.Mode = UART_MODE_TX_RX; // Full-duplex mode
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
if (dev==ZAB_BOTH)
sprintf(cmd, "/%s\n", ZABER_CMD_HOME);
else
sprintf(cmd, "/%d %s\n", dev, ZABER_CMD_HOME);

rv = HAL_UART_Transmit(&huart3, (uint8_t*)cmd, strlen(cmd), 1000);
return rv;
}

int main(void)
{
HAL_Init();
SystemClock_Config();
uart_test();

 

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    Ok, so there's a stm32xyz_hal_msp.c file where it should enable clocks, and pins, associating the correct AF settings, etc.

    /**
     * @brief UART MSP Initialization
     * This function configures the hardware resources used in this example:
     * - Peripheral's clock enable
     * - Peripheral's GPIO Configuration
     * @PAram huart: UART handle pointer
     * @retval None
     */
    void HAL_UART_MspInit(UART_HandleTypeDef *huart)
    {
     GPIO_InitTypeDef GPIO_InitStruct = {0};
    
     if (huart == USARTx)// identify the one being configured/initialized
     {
     /*##-1- Enable peripherals and GPIO Clocks #################################*/
     /* Enable GPIO TX/RX clock */
     USARTx_TX_GPIO_CLK_ENABLE();
     USARTx_RX_GPIO_CLK_ENABLE();
    
     /* Enable USARTx clock */
     USARTx_CLK_ENABLE();
    
     /*##-2- Configure peripheral GPIO ##########################################*/
     /* UART TX GPIO pin configuration */
     GPIO_InitStruct.Pin = USARTx_TX_PIN;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_PULLUP;
     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
     GPIO_InitStruct.Alternate = USARTx_TX_AF;
    
     HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
    
     /* UART RX GPIO pin configuration */
     GPIO_InitStruct.Pin = USARTx_RX_PIN;
     GPIO_InitStruct.Alternate = USARTx_RX_AF;
    
     HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
     }
    }

    8 replies

    Tesla DeLorean
    Guru
    April 30, 2024

    HAL_TIMEOUT = 0x03U

    Are you sure the clock is enabled, show the MSP code initializing the UART clocks and GPIOs

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mƎALLEm
    ST Technical Moderator
    April 30, 2024

    Hello,

    Most probably USART clock is not enabled.

    To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
    debugAuthor
    Associate III
    April 30, 2024

    That was my first suspicion, too but my SystemClock_Config() sets up the divider for APB1 (which is routed to USART3), i.e. I suspect the problem is somewhere else:

    static void SystemClock_Config(void)
    {
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
    RCC_OscInitTypeDef RCC_OscInitStruct;

    /* Enable Power Control clock */
    __HAL_RCC_PWR_CLK_ENABLE();

    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

    /* Enable HSE Oscillator and activate PLL with HSE as source */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLM = 4;//8;
    RCC_OscInitStruct.PLL.PLLN = 168;//360;
    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
    RCC_OscInitStruct.PLL.PLLQ = 4;//7;
    if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    {
    while(1) {};
    }
    /*
    if(HAL_PWREx_EnableOverDrive() != HAL_OK)
    {
    while(1) {};
    }*/

    /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
    clocks dividers */
    RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
    if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
    {
    while(1) {};
    }
    }

     

     

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    April 30, 2024

    Ok, so there's a stm32xyz_hal_msp.c file where it should enable clocks, and pins, associating the correct AF settings, etc.

    /**
     * @brief UART MSP Initialization
     * This function configures the hardware resources used in this example:
     * - Peripheral's clock enable
     * - Peripheral's GPIO Configuration
     * @PAram huart: UART handle pointer
     * @retval None
     */
    void HAL_UART_MspInit(UART_HandleTypeDef *huart)
    {
     GPIO_InitTypeDef GPIO_InitStruct = {0};
    
     if (huart == USARTx)// identify the one being configured/initialized
     {
     /*##-1- Enable peripherals and GPIO Clocks #################################*/
     /* Enable GPIO TX/RX clock */
     USARTx_TX_GPIO_CLK_ENABLE();
     USARTx_RX_GPIO_CLK_ENABLE();
    
     /* Enable USARTx clock */
     USARTx_CLK_ENABLE();
    
     /*##-2- Configure peripheral GPIO ##########################################*/
     /* UART TX GPIO pin configuration */
     GPIO_InitStruct.Pin = USARTx_TX_PIN;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_PULLUP;
     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
     GPIO_InitStruct.Alternate = USARTx_TX_AF;
    
     HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
    
     /* UART RX GPIO pin configuration */
     GPIO_InitStruct.Pin = USARTx_RX_PIN;
     GPIO_InitStruct.Alternate = USARTx_RX_AF;
    
     HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
     }
    }
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..