overload printf uart

This commit is contained in:
Vasily Markov 2024-04-02 13:56:52 +03:00
parent dcc1e2161b
commit 6e640bed7c
4 changed files with 35 additions and 11 deletions

View File

@ -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_definitions(-DSTM32F439xx)
add_compile_definitions(HSE_VALUE=8000000)
add_definitions(-DHSE_VALUE=8000000)
include_directories(
${PROJECT_SOURCE_DIR}/bsp
@ -46,6 +46,8 @@ file(GLOB_RECURSE SOURCES
set(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/stm32_flash.ld)
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(-mcpu=${MCPU} -mthumb -mthumb-interwork)
add_link_options(-T ${LINKER_SCRIPT})

View File

@ -16,17 +16,8 @@ void loop() {
}
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) {
USART_SendData(USART2, sendData[sendDataCounter++ % 8]);
printf("Hello, world%.6f\r\n", 5.432);
loop();
};
}

View File

@ -10,6 +10,36 @@
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
#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) {
}
}

View File

@ -5,6 +5,7 @@
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
#include <stdio.h>
void board_init();