ussserrr / stm32pio

Automate managing of STM32CubeMX + PlatformIO projects
https://pypi.org/project/stm32pio
Other
230 stars 24 forks source link

Can't use overriden `__io_putchar` / `printf` #120

Closed kosma-hyzoe closed 8 months ago

kosma-hyzoe commented 8 months ago

First and foremost, thanks for contributing to a project like this. I'm very happy it exists.

Description

I'm following a course for STM32 Nucleo L476RG. The course instructs me to override __io_putchar to be able to use printf like so:

int __io_putchar(int ch)
{
    if (ch == '\n') {
        uint8_t cr = '\r';
        HAL_UART_Transmit(&huart2, &cr, 1, HAL_MAX_DELAY);
    }

    HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
    return 1;
}

I got it to work several times already using STM32Cube IDE (obviously I don't like it, which is why I'm here) with a blank project, default settings and this definition only. On a setup using stm32pio, this does not work. The HAL_UART_Transmit function works fine.

NOTE: I am not able to choose the "Other toolchain" option that I get warnings about. If I understand correctly, it might be that my relatively new board does not support it.

What I tried already

More details

Debian 12 Python 3.11.2

My stm32pio.ini file:

[app]
platformio_cmd = platformio
cubemx_cmd = /usr/local/STMicroelectronics/STM32Cube/STM32CubeMX/STM32CubeMX
java_cmd = None

[project]
cubemx_script_content = config load ${ioc_file_absolute_path}
    generate code ${project_dir_absolute_path}
    exit
platformio_ini_patch_content = [platformio]
    include_dir = Inc
    src_dir = Src
board = nucleo_l476rg
ioc_file = forbot-stm32-l4.ioc
cleanup_ignore = forbot-stm32-l4.ioc
cleanup_use_git = False
inspect_ioc = True
last_error = 

My project tree (after "Full Clean"):

.
├── forbot-stm32-l4.ioc
├── Inc
│  ├── gpio.h
│  ├── main.h
│  ├── stm32l4xx_hal_conf.h
│  ├── stm32l4xx_it.h
│  └── usart.h
├── lib
│  └── README
├── platformio.ini
├── Src
│  ├── gpio.c
│  ├── main.c
│  ├── stm32l4xx_hal_msp.c
│  ├── stm32l4xx_it.c
│  └── usart.c
├── stm32pio.ini
└── test
   └── README
kosma-hyzoe commented 8 months ago

Fixed this by adding the _write function which normally gets defined in syscalls.c, which is missing in a stm32pio project. Leaving this be in case someone comes across a similar issue...