overload printf uart
This commit is contained in:
parent
dcc1e2161b
commit
6e640bed7c
@ -21,7 +21,7 @@ add_compile_options(-mcpu=${MCPU} -mthumb -mthumb-interwork)
|
|||||||
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
|
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
|
||||||
|
|
||||||
add_definitions(-DSTM32F439xx)
|
add_definitions(-DSTM32F439xx)
|
||||||
add_compile_definitions(HSE_VALUE=8000000)
|
add_definitions(-DHSE_VALUE=8000000)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${PROJECT_SOURCE_DIR}/bsp
|
${PROJECT_SOURCE_DIR}/bsp
|
||||||
@ -46,6 +46,8 @@ file(GLOB_RECURSE SOURCES
|
|||||||
set(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/stm32_flash.ld)
|
set(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/stm32_flash.ld)
|
||||||
|
|
||||||
add_link_options(-specs=nosys.specs)
|
add_link_options(-specs=nosys.specs)
|
||||||
|
add_link_options(-specs=nano.specs)
|
||||||
|
add_link_options(-u _printf_float)
|
||||||
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
|
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
|
||||||
add_link_options(-mcpu=${MCPU} -mthumb -mthumb-interwork)
|
add_link_options(-mcpu=${MCPU} -mthumb -mthumb-interwork)
|
||||||
add_link_options(-T ${LINKER_SCRIPT})
|
add_link_options(-T ${LINKER_SCRIPT})
|
||||||
|
11
app/app.c
11
app/app.c
@ -16,17 +16,8 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void app() {
|
void app() {
|
||||||
volatile uint8_t sendData[8];
|
|
||||||
volatile uint8_t bytesToSend = 8;
|
|
||||||
// Счетчик отправленных байт
|
|
||||||
volatile uint8_t sendDataCounter = 0;
|
|
||||||
for (uint8_t i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
sendData[i] = i;
|
|
||||||
}
|
|
||||||
// USART_ITConfig(USART2, USART_IT_TC, ENABLE);
|
|
||||||
while(1) {
|
while(1) {
|
||||||
USART_SendData(USART2, sendData[sendDataCounter++ % 8]);
|
printf("Hello, world%.6f\r\n", 5.432);
|
||||||
loop();
|
loop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
30
bsp/bsp.c
30
bsp/bsp.c
@ -10,6 +10,36 @@
|
|||||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||||
#define PLL_Q 7
|
#define PLL_Q 7
|
||||||
|
|
||||||
|
// #ifdef __GNUC__
|
||||||
|
// #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
||||||
|
// #else
|
||||||
|
// #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
|
||||||
|
// #endif /* __GNUC__ */
|
||||||
|
|
||||||
|
// PUTCHAR_PROTOTYPE
|
||||||
|
// {
|
||||||
|
// for(uint8_t i = 0; i < len; ++i) {
|
||||||
|
// USART_SendData(USART2, ptr[i]);
|
||||||
|
// }
|
||||||
|
// return ch;
|
||||||
|
// }
|
||||||
|
|
||||||
|
int _write(int fd, char* ptr, int len) {
|
||||||
|
int i= 0;
|
||||||
|
while(i < len) {
|
||||||
|
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Ждем, пока буфер передатчика не освободится
|
||||||
|
USART_SendData(USART2, *ptr++); // Отправляем символ
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART_SendString(const char* str) {
|
||||||
|
while (*str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user