Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


You are viewing a reply to re-directing usart to printf  

re-directing usart to printf

Oooh, I know this one.

The 401 chip has 3 USARTS. ST, when laying out the Nucleo boards does not include a serial port connector. Therefore the choice as to
which USART should be connected to printf was never made, and was never included in the BSP.

Printf, when called, calls a bunch of other routines to get the work done. It eventually boils down to a call to _write that you can find in your
source directory in a file called syscalls.c. The _write routine itterates through the buffer that is passed to it, pulling out characters one at
a time and sending them to a routine called _ _ i o _ p u t c h a r (to show you that there are two underscores before the name).
If you click on the call to _ _io_putchar and hit F3, eclipse will send you to the declaration of the routine. It is somewhere but
there isn’t much point in looking for it, it is empty. It does nothing. It gets called and immediatly returns. The call may even get
optimized out.

But wait, if you look at the declaration, you will notice that it is a “weak” subroutine. This is something that was brought in with C99 that
tells the compiler/linker that this routine, that is declared weak, use it unless there is another one with the same name that isn’t
declared weak, in which case, use the other one instead.

You will find these weak declarations all over the HAL. These are routines that are place holders for ones that you may have to write.

So, what you need to do is provide your own _ _io_putchar routine for the printf chain to call. I suggest this:

void __io_putchar(uint8_t ch) {
	/**
	 * \brief		__io_putchar - A routine to transmit a single character out the serial port
	 * \return		void
	 * \param[in]	ch - uint8_t the character to transmit
	 * \author		andreichichak
	 * \date		Oct 16, 2015
	 * \details		This routine assumes that we will be using UART2. A timeout value of 1ms (4th parameter)
	 * 				gives a retry if the transmit buffer is full when back to back characters are transmitted,
	 * 				avoiding dropping characters.
	 */

	HAL_UART_Transmit(&huart2, &ch, 1, 1);
}


Put this at the bottom of main.c and printf will start working.

To use getc or gets, you have to write a _ _io_getchar routine. I’ll leave that to the student as an exercise.

Andrei from The Great White North (as seen on the embedded.fm podcast)





Fixed the code sections but still can’t stop the editor from bolding __io_putchar.