Skip to content

Print::printf on SerialUSB #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tretgo opened this issue Jan 8, 2020 · 2 comments · Fixed by #867
Closed

Print::printf on SerialUSB #862

Tretgo opened this issue Jan 8, 2020 · 2 comments · Fixed by #867
Labels
enhancement New feature or request

Comments

@Tretgo
Copy link

Tretgo commented Jan 8, 2020

Preconditions:
OS: Win10
Arduino 1.8.10
STM32 1.8.0
BluePill F103
HID Bootloader
USB CDC Serial

USB Serial output is not working when setting
HAL_UART_MODULE_ONLY
HAL_UART_MODULE_ENABLED
in build_opt.h

Target: LIN Serial implementeation on UART1 and USB Serial for debugging

Root cause:

extern "C" {
__attribute__((weak))
int _write(int file, char *ptr, int len)
{
#if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
switch (file) {
case STDOUT_FILENO:
case STDERR_FILENO:
uart_debug_write((uint8_t *)ptr, (uint32_t)len);
break;
case STDIN_FILENO:
break;
default:
((class Print *)file)->write((uint8_t *)ptr, len);
break;
}
#else
(void)file;
(void)ptr;
#endif
return len;
}

Function write in Print.cpp gets disabled when setting UART into HAL mode.
But only uart_debug should be disabled.

Working bugfix:

extern "C"
{
  __attribute__((weak)) int _write(int file, char *ptr, int len)
  {
#if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
    switch (file)
    {
    case STDOUT_FILENO:
    case STDERR_FILENO:
      uart_debug_write((uint8_t *)ptr, (uint32_t)len);
      break;
    case STDIN_FILENO:
      break;
    default:
      ((class Print *)file)->write((uint8_t *)ptr, len);
      break;
    }
#else
    if (file != STDERR_FILENO)
      ((class Print *)file)->write((uint8_t *)ptr, len);
#endif
    return len;
  }
}
@fpistm
Copy link
Member

fpistm commented Jan 9, 2020

Hi @Tretgo
I guess this is when you use printf() with SerialUSB ?

@fpistm fpistm added the waiting feedback Further information is required label Jan 10, 2020
@Tretgo
Copy link
Author

Tretgo commented Jan 12, 2020

Hi,
just checked.
println() works, but printf() does not.

@fpistm fpistm added enhancement New feature or request and removed waiting feedback Further information is required labels Jan 13, 2020
@fpistm fpistm changed the title USB Serial not working with HAL UART Print::printf on SerialUSB Jan 13, 2020
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 13, 2020
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jan 13, 2020
Before it was only linked to U(S)ART while Print is a
Base class.

Fixes stm32duino#862

Signed-off-by: Frederic Pillon <[email protected]>
fpistm added a commit that referenced this issue Jan 15, 2020
Before it was only linked to U(S)ART while Print is a
Base class.

Fixes #862

Signed-off-by: Frederic Pillon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants