cancel
Showing results for 
Search instead for 
Did you mean: 

WL55CC print_f io redirect UART busy

bblouin
Associate III

I am trying to setup UART1 on WL55CC; using RTS;

#include <stdio.h>
 
#if defined (__ICCARM__) || defined (__ARMCC_VERSION)
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#elif defined(__GNUC__)
   /* With GCC, small printf (option LD Linker->Libraries->Small printf
   set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#endif /* __ICCARM__ || __ARMCC_VERSION */
 
HAL_GPIO_TogglePin(GPIOA, LED_Pin); // PORTA, PA9
	  HAL_Delay(500);
	  nLoop++;
	  printf("nLoop == %d \n\r", (int) nLoop);
 
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
 
  return ch;
}
 
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_RTS;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
 
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));

I might not be linking tiny printf, but I don't know where that is.

Please help 😎

1 REPLY 1
TDK
Guru

If you call HAL_UART_Transmit from multiple contexts, the ones that are called later will return HAL_BUSY if a call is already ongoing. It doesn't look like HAL_BUSY can be called due to RTS, but I could be wrong here.

You can implement your own buffer, disable interrupts during the call, or just ignore the lost bytes. It calls HAL_Delay, but I do not think disabling interrupts will prevent normal operation in this case.

If you feel a post has answered your question, please click "Accept as Solution".