cancel
Showing results for 
Search instead for 
Did you mean: 

Role of syscalls.c

Supreeth Anil
Associate

What is the role of syscalls.c file in GNU ARM(STM32 for instance) based projects? I found 2 ways of successfully building the project

1. Delete syscalls.c and include -specs=nosys.specs in the linker flags

2. Simply include syscalls.c

What is the fundamental difference between these two methods? What is the importance of system calls in a non-os environment like microcontroller? If it is used for implementing system level functions used by printf, scanf etc. then who is calling these function(because I am not using any of these functions in my code)? 

P.S - I am using System Workbench for STM32 & STM32F4Nucleo board for this particular example

5 REPLIES 5
Ozone
Lead

> If it is used for implementing system level functions used by printf, scanf etc. then who is calling these function(because I am not using any of these functions in my code)?

If you don't use it, remove it.

Often libraries from other operating systems (like Linux) are ported to MCUs, which presuppose CLib functions.

syscalls.c would be a place to implement missing functions.

JSILV.2
Senior

And where one output data will be sent using the standard function into syscalls.c ?

I mean, into CUBE IDE on Debug section.

Regards.

Depends on the plumbing you set up. The _write() notionally calls __io_putchar() in ST's model, and then typically uses this to output to a U(S)ART you've previously brought up, or using ITM_SendChar(), or both methods.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
JSILV.2
Senior

Dear DeLorean.

It means that this fuction is a kind of "unfinished fuction"? I mean, anyone should insert some code following __io_putchar()? Or this last macro will direct one char to any valid environment by default?

Regards.

Well it does happen by magic..

STM32Cube_FW_F4_V1.24.0\Projects\STM324xG_EVAL\Examples\UART\UART_Printf\Src\main.c

/* UART handler declaration */

UART_HandleTypeDef UartHandle;

/* Private function prototypes -----------------------------------------------*/

#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__ */

...

/**

 * @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 EVAL_COM1 and Loop until the end of transmission */

 HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF);

 return ch;

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..