2017-06-03 07:02 AM
Platform: STM32L4DISCO
IDE: SW4STM32
Hi,
I used CubeMx to configure the USART2 with the following parameter
I used Putty as the serial terminal with the COM3 wich is the COM port that I saw on my device manager.
I used the HAL command
HAL_UART_Transmit(&huart2, (uint8_t*)'Hello', 6, 10000);
But I don't see anything on the terminal. Is there something else I need to do before being able to send data to the terminal?
Thanks
#stm32-usart2 #stm32l4 Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-06-03 12:05 PM
you need to add syscalls.c to your Src directory. you should then see some output. If you want to print floating point values, you would need to remove nano.specs from your linker options.
________________ Attachments : syscalls.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HydX&d=%2Fa%2F0X0000000bAJ%2F83tKgt_nyOD2Z676aSc62KN_sHtDD4lsPvrQ1Yjc4V8&asPdf=false2017-06-03 04:33 PM
Hi,
I added syscalls.c to my Src directory, but I still don't have any response on my putty terminal. What is the point of this file? Is it supposed to print inside system workbench IDE console?
Thanks,
2017-06-03 06:15 PM
crap i forgot the other half of the equation is to reroute printf
you also need to add
♯ ifdef __GNUC__
/* With GCC, 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__ */to your private function prototypes, and add this to user code 4
PUTCHAR_PROTOTYPE
{ /* Place your implementation of fputc here */ /* e.g. write a character to the USART2 and Loop until the end of transmission */ HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);return ch;
}sorry about the incomplete info
2017-06-03 08:31 PM
This thing is the HAL_UART_Transmit function is not working and that is the root of my problem, so use printf that calls HAL_UART_Transmit won't work either.
2017-06-03 09:00 PM
you need to add syscalls.c to your project, and add the code i posted above to your main.c
that would redirect uart2 to vcp over usb
2017-06-04 07:25 AM
Hi,
I don't have the small printf option when I go to LD Linker->Libraries->. How can I get this option?
2017-06-04 12:22 PM
you dont need it to get printf to work.
2017-06-04 12:50 PM
here's a main.c for l476disco that outputs to vcp and cubemx-generated .ioc file
________________ Attachments : hello_world.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hyd3&d=%2Fa%2F0X0000000bAH%2FAt93PiCYlDq4DWP_fvzy7_0aajoyFp_IZWHmMlR4ww0&asPdf=falsemain.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HydI&d=%2Fa%2F0X0000000bAI%2FRPap5dRHMWUYEC4kwqn4p8aTKtZnYSfdOklPBPBb8v8&asPdf=false2017-06-04 03:17 PM
Hi,
The main.c you attached doesn't configure the USART2 Pin PA2 and PA3. Instead, it is the joystick that is configured. Did you generate this file with CubeMx? If so could you send me the project?
Thanks for your patience.