2018-12-06 10:03 AM
I'd like to be able to printf into IDE console during debug. I'm using Atollic 9.1, Nucleus F413 board with Segger debug programmed into onboard debug interface. I followed the instructions here:
Nothing happens when I printf: The debugger never hits a breakpoint in the modified _write in syscalls.
What am I doing wrong?
Thanks!
Best Regards, Dave
2018-12-07 08:33 AM
The map shows that _write is loaded from library and not syscalls as expected.
c:/program files (x86)/atollic/truestudio for stm32 9.1.0/armtools/bin/../lib/gcc/arm-atollic-eabi/6.3.1/../../../../arm-atollic-eabi/lib/armv7e-m/fpu\libnosys.a(write.o)
0x08004de8 _write
Yikes - Generated project (CubeMX) placed syscalls.c at root of project and it was not included in the project!
Isn't this a CubeMX bug?
Moving it to src directory tries to build it but I can't find the required CMSIS file core_cmX.h...
Anybody know where this is? Or is the Atollic application note referenced above out of date?
Thanks for any help here,
Best Regards, Dave
2018-12-07 08:43 AM
Those should be in the CMSIS directories for the HAL libraries, make sure you have the "Include Paths" set appropriately.
Perhaps it removes things where the call-trees don't go anywhere, via dead-code removal phase of linker?
In GNU/GCC more generally doesn't ST use __io_putchar() and have some code in syscalls/newlib to catch the other side?
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
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(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
2018-12-07 09:04 AM
Right, I was missing (in syscalls.c) the #include "stm32f413xx.h" // ITM_SendChar (includes core_cm4.h)
Fixing that allows build.
Unfortunately, now trying printf lands in the hard-fault handler.
Any idea what I did wrong?
2018-12-07 09:25 AM
>>Any idea what I did wrong?
Not really, identify the code that's faulting and work back the logic. Usually busted pointers, illegal memory access or alignment issues.
I'm not an Atollic users, when I use GNU/GCC I use make/makefiles. Professionally I typically use Keil, it's far less of a goat rodeo..
2018-12-07 10:35 AM
Its faulting within newlib; I guess I could go read the sources as I don't have a newlib built for debugging handy. Perhaps STM has also set up newlib incorrectly as here: http://www.nadler.com/embedded/newlibAndFreeRTOS.html
2018-12-07 10:44 AM
The SW4STM32 forks look innoxious
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
..
int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar( *ptr++ );
}
return len;
}
2018-12-07 11:57 AM
Well, this is an unfortunate time-sink:
I'm using AT 6.1, F413 Nuckeo board with Segger debug loaded into onboard debugger. Newlib 2.5 is included in STM distribution (htis project uses newlib-nano).
Anybody know how to get printf during debug to output to IDE console???
Thanks in advance for any explanation,
Best Regards, Dave
2018-12-07 12:11 PM
2018-12-07 12:17 PM
@Piranha - I don't know why you've provided this link? My test strings provide include newline, and in any case calling _write directly does not generate output in the IDE...