STM32L4 Sin mensaje UART

0

Durante los últimos 2 días he intentado que el controlador USART2 (patillas PD5 y amp; PD6) funcione en el descubrimiento STM32L476VG, que permite la comunicación UART a través del cable ST-LINK. Estoy usando las herramientas ARM GNU para compilar el proyecto en Ubuntu en una VM, usando ST-Flash para escribir en el flash de la pizarra. He generado un código de inicio de ejemplo utilizando el software STM32CubeMX y usándolo en mi propio código. El código se compila y enlaza con éxito, pero cada vez que me conecto al puerto COM utilizando TeraTerm en Windows (me aseguro de que la placa esté desconectada de Ubuntu), nunca veo ningún resultado. He intentado usar la función integrada HAL_UART_Transmit, y también he intentado usar mi propia función uart_putc para escribir mensajes.

Aquí está mi main.c:

#include "stm32l476xx.h"
#include "core_cm4.h"
#include "stm32l4xx_hal.h"
#include "stm32l4xx_hal_uart_ex.h"
#include "uart.h"

volatile int32_t TimeDelay;
void SysTick_Handler (void);
void Delay (uint32_t nTime);
UART_HandleTypeDef huart2;
static void USART_Init(void);
static void HAL_UART_InitStruct(void);

int main() {
    // initialize systick clock
    SysTick_Config(10000);  //10 ms reload period

    // initialize test led (PE8)
    RCC->AHB2ENR |= RCC_AHB2ENR_GPIOEEN; 
    GPIO_InitTypeDef GPIO_InitLED;

    GPIO_InitLED.Pin = GPIO_PIN_8;
    GPIO_InitLED.Mode = GPIO_MODE_OUTPUT_PP; //push-pull
    HAL_GPIO_Init(GPIOE, &GPIO_InitLED);    

    // initialize usart params  
    HAL_UART_InitStruct();
    USART_Init();

    while(1) {
        HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_8); //testing application load
        uart_putc(42, huart2.Instance);
        //HAL_UART_Transmit(&huart2, "msg\r\n", 5, 0xFFFF);
        Delay(100);     
    };

}

void SysTick_Handler (void) {
    if (TimeDelay > 0)
        TimeDelay--;
}

void Delay (uint32_t nTime) {
    TimeDelay = nTime;  // nTime specifies the delay time length
    while(TimeDelay != 0);  // busy wait
}

static void HAL_UART_InitStruct(void){
    GPIO_InitTypeDef GPIO_InitStruct;

    __HAL_RCC_USART2_CLK_ENABLE();
    GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
static void USART_Init(void)
{

    huart2.Instance = USART2;
    huart2.Init.BaudRate = 9600;
    huart2.Init.WordLength = UART_WORDLENGTH_7B;
    huart2.Init.StopBits = UART_STOPBITS_1;
    huart2.Init.Parity = UART_PARITY_NONE;
    huart2.Init.Mode = UART_MODE_TX_RX;
    huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart2.Init.OverSampling = UART_OVERSAMPLING_16;
    huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
    HAL_UART_Init(&huart2);    
}

void _Error_Handler(char *file, int line)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  while(1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
    /* infinite loop */
    /* use gdb to find out why we're here */
    while (1);
}

#endif

Aquí está mi función uart_putc en uart.c:

int uart_putc(int c, USART_TypeDef* USARTx){
    // check USARTx interrupt and status register, and TX empty flag
    while (!(USARTx->ISR & USART_FLAG_TXE));
    USARTx->TDR = (c & 0xff);
    return c;
}
    
pregunta akivjh

0 respuestas

Lea otras preguntas en las etiquetas