2015-12-15 01:46 AM
Hi all,
trying to retarget printf on stm32f407 discovery with cubemx generated code isn't working. Inside main.c i've put:/**
* @brief Retargets the C library printf function to the USART. * @param None * @retval None */ int fputc(int ch, FILE *f){ /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ HAL_UART_Transmit(&huart6,(uint8_t*)&ch,1,1);// 1 tick waiting (1ms) enough for 87us/byte at 115200 return ch; }HAL_UART_Transmit
works without problem on it's own, printf doesn't output. Could anyone help please?2015-12-15 02:03 AM
2015-12-15 04:56 AM
Thanks for hint!
I did the same and it works. Here is the code for others: int _write( int file, char *ptr, int len ){ int i; for(i = 0 ; i < len ; i++){ HAL_UART_Transmit(&huart6,(uint8_t*)&ptr[i],1,10); } char ch='\r'; HAL_UART_Transmit(&huart6,(uint8_t*)&ch,1,10); }2016-06-08 10:07 AM
Hello all,
I am trying to get the UART output (send some character strings over UART via USB CDC class). My code is based upon CubeF0 codebase and HAL and USB_Device CDC class.USBD_HandleTypeDef USBD_Device;extern UART_HandleTypeDef UartHandle;void main(void){ uint8_t ch = 'a'; HAL_Init(); SystemClock_Config(); /* Init Device Library */ USBD_Init(&USBD_Device, &VCP_Desc, 0); /* Add Supported Class */ USBD_RegisterClass(&USBD_Device, &USBD_CDC); /* Add CDC Interface Class */ USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops); /* Start Device Process */ USBD_Start(&USBD_Device); while (1) { status = HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 10); }}However, nothing comes out on the Hyper-terminal connected on Windows. The HAL_Transmit_UART is going through but I fear that somehow the UART transmit data struct is not connected to the USB CDC class buffer and/or some DMA issue. I don't want to use DMA but not sure how to just be in polling mode and if the UART (huart->Instance->TDR) in stmf0xx_hal_uart.c is really giving the character to the CDC.I think that USB CDC class transmits a packet in the USBD_CDC_TransmitPacket() function where it calls USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer, hcdc->TxLength);Do I instead need to use HAL_UART_Transmit_IT() to transmit in interrupt mode for USB to recognize that data is pending? Otherwise I don't see how the HAL_UART_Transmit() connects to USB CDC. The _IT() version seems to connect via the UserTxBuffer[].Any pointers in making progress will help me. Thanks.