94 lines
2.1 KiB
C
94 lines
2.1 KiB
C
/**
|
|
******************************************************************************
|
|
* @file syscalls.c
|
|
* @author Suroy Wrote with Auto-generated by STM32CubeIDE
|
|
* @url https://suroy.cn
|
|
* @brief STM32CubeIDE Minimal System calls file
|
|
*
|
|
* For more information about which c-functions
|
|
* need which of these lowlevel functions
|
|
* please consult the Newlib libc-manual
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2020-2022 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
#ifdef defined (__GNUC__)
|
|
/* Includes */
|
|
#include "Bsp.h"
|
|
|
|
|
|
/* Variables */
|
|
extern int __io_putchar(int ch) __attribute__((weak));
|
|
extern int __io_getchar(void) __attribute__((weak));
|
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
|
{
|
|
(void)file;
|
|
int DataIdx;
|
|
|
|
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|
{
|
|
*ptr++ = __io_getchar();
|
|
}
|
|
|
|
return len;
|
|
}
|
|
|
|
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
|
{
|
|
(void)file;
|
|
int DataIdx;
|
|
|
|
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|
{
|
|
__io_putchar(*ptr++);
|
|
}
|
|
return len;
|
|
}
|
|
|
|
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
|
#define GETCHAR_PROTOTYPE int __io_getchar(void)
|
|
|
|
/**
|
|
* 函数功能: 重定向 c库函数 printf到 DEBUG_USARTx
|
|
* 输入参数: 无
|
|
* 返 回 值: 无
|
|
* 说 明:无
|
|
*/
|
|
PUTCHAR_PROTOTYPE
|
|
{
|
|
UsartSendChar(TTY_COM, ch); //阻塞式无限等待
|
|
return ch;
|
|
}
|
|
|
|
|
|
/**
|
|
* 函数功能: 重定向 c库函数 getchar,scanf到 DEBUG_USARTx
|
|
* 输入参数: 无
|
|
* 返 回 值: 无
|
|
* 说 明:无
|
|
*/
|
|
GETCHAR_PROTOTYPE
|
|
{
|
|
uint8_t ch = 0;
|
|
ch = UsartReceiveChar(TTY_COM);
|
|
|
|
return ch;
|
|
}
|
|
|
|
#endif
|
|
|
|
|