diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 1d62fa6..c5d7835 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -138,7 +138,7 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ header file. */ /* USER CODE BEGIN 1 */ #include "snprintf.h" -#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); PRINTF("configASSERT "__FILE__":%d\r\n",__LINE__); for( ;; );} +#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); PRINTF("FreeRTOS assert @ %s:%d\r\n", __FILE__, __LINE__); for( ;; );} /* USER CODE END 1 */ /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 77d75cc..a1f5c4d 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -16,10 +16,6 @@ * ****************************************************************************** */ -// this is a hack needed for CLion - placed here so cubemx does not overwrite it -#ifndef USE_FULL_LL_DRIVER -#define USE_FULL_LL_DRIVER 1 -#endif /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ diff --git a/Core/Src/app_main.c b/Core/Src/app_main.c index 73786af..c7d180e 100644 --- a/Core/Src/app_main.c +++ b/Core/Src/app_main.c @@ -33,13 +33,13 @@ static void redraw_display() { char tmp[100]; - PRINTF(tmp, "T=%d°C", (int) s_app.oven_temp); + SPRINTF(tmp, "T=%d°C", (int) s_app.oven_temp); fb_text(3, 3, tmp, FONT_5X7, 1); - PRINTF(tmp, "Cil=%d°C", s_app.set_temp); + SPRINTF(tmp, "Cil=%d°C", s_app.set_temp); fb_text(3, 11, tmp, FONT_5X7, 1); - PRINTF(tmp, "Stav=%s", s_app.run ? "ZAP" : "VYP"); + SPRINTF(tmp, "Stav=%s", s_app.run ? "ZAP" : "VYP"); fb_text(3, 19, tmp, FONT_5X7, 1); if (s_app.run) { @@ -141,6 +141,8 @@ void app_task_main(void *argument) uint32_t now = osKernelGetTickCount(); if (any_change || (now - last_redraw > pdMS_TO_TICKS(500))) { + PUTS("Cycle\r\n"); + PRINTF("test printf\r\n"); last_redraw = now; redraw_display(); any_change = false; diff --git a/Core/Src/uart_stdout.c b/Core/Src/uart_stdout.c new file mode 100644 index 0000000..dba7b67 --- /dev/null +++ b/Core/Src/uart_stdout.c @@ -0,0 +1,52 @@ +/** + * TODO file description + */ + +#include +#include "uart_stdout.h" +#include "FreeRTOS.h" +#include "main.h" + +#define USE_CRITICAL 0 + +void stdout_putchar(char c) { +#if USE_CRITICAL + portENTER_CRITICAL(); +#endif + while (!LL_USART_IsActiveFlag_TXE(USART_DEBUG)) {} + LL_USART_TransmitData8(USART_DEBUG, c); + while (!LL_USART_IsActiveFlag_TC(USART_DEBUG)) {} +#if USE_CRITICAL + portEXIT_CRITICAL(); +#endif +} + +void stdout_write(const char *pcBuffer, const size_t iLength) { +#if USE_CRITICAL + portENTER_CRITICAL(); +#endif + while (!LL_USART_IsActiveFlag_TXE(USART_DEBUG)) {} + int cnt = (int) iLength; + while (cnt-- > 0) { + char c = *pcBuffer++; + LL_USART_TransmitData8(USART_DEBUG, c); + while (!LL_USART_IsActiveFlag_TC(USART_DEBUG)) {} + } +#if USE_CRITICAL + portEXIT_CRITICAL(); +#endif +} + +void stdout_puts(const char *pcBuffer) { + stdout_write(pcBuffer, strlen(pcBuffer)); +} + +/** + * @brief Retargets the C library printf function to the USART. + * @param None + * @retval None + */ +int _write(int fd, const char *pcBuffer, const int iLength) { + stdout_write(pcBuffer, iLength); + return iLength; +} diff --git a/Core/Src/uart_stdout.h b/Core/Src/uart_stdout.h new file mode 100644 index 0000000..9e6af06 --- /dev/null +++ b/Core/Src/uart_stdout.h @@ -0,0 +1,8 @@ +/** + * TODO file description + */ + +#ifndef BLUEPILLTROUBA_UART_STDOUT_H +#define BLUEPILLTROUBA_UART_STDOUT_H + +#endif //BLUEPILLTROUBA_UART_STDOUT_H diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 3194fea..1b06fd3 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -21,9 +21,6 @@ #include "usart.h" /* USER CODE BEGIN 0 */ -#include -#include -#include "main.h" /* USER CODE END 0 */ /* USART1 init function */ @@ -76,32 +73,6 @@ void MX_USART1_UART_Init(void) } -/* USER CODE BEGIN 1 */ -void stdout_write(const char *pcBuffer, const size_t iLength) { - int cnt = (int) iLength; - while (cnt-- > 0) { - while (!LL_USART_IsActiveFlag_TXE(USART_DEBUG)) {} - LL_USART_TransmitData8(USART_DEBUG, *pcBuffer++); - } -} - -void stdout_puts(const char *pcBuffer) { - stdout_write(pcBuffer, strlen(pcBuffer)); -} - -void stdout_putchar(char c) { - while (!LL_USART_IsActiveFlag_TXE(USART_DEBUG)) {} - LL_USART_TransmitData8(USART_DEBUG, c); -} - -/** - * @brief Retargets the C library printf function to the USART. - * @param None - * @retval None - */ -int _write(int fd, const char *pcBuffer, const int iLength) { - stdout_write(pcBuffer, iLength); - return iLength; -} +/* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/Lib/snprintf/snprintf.c b/Lib/snprintf/snprintf.c index d924fc5..fdf59c9 100644 --- a/Lib/snprintf/snprintf.c +++ b/Lib/snprintf/snprintf.c @@ -831,11 +831,13 @@ int vasprintf(char **ptr, const char *format, va_list ap) { int ret; + va_list ap_copy; + va_copy(ap_copy, ap); ret = vsnprintf((char *) NULL, 0, format, ap); if (ret + 1 <= 1) { return ret; } /* pts: bit of old unsigned trick... */ if (NULL == (*ptr = (char *) my_malloc(ret + 1))) { return -1; } - ret = vsnprintf(*ptr, ret + 1, format, ap); + ret = vsnprintf(*ptr, ret + 1, format, ap_copy); return ret; } diff --git a/Lib/snprintf/snprintf.h b/Lib/snprintf/snprintf.h index 365df00..fdd7c85 100644 --- a/Lib/snprintf/snprintf.h +++ b/Lib/snprintf/snprintf.h @@ -26,6 +26,11 @@ int fixup_vprintf(const char *format, va_list ap); #define PRINTF(...) fixup_printf(__VA_ARGS__) #define VPRINTF(...) fixup_vprintf(__VA_ARGS__) +// for debug +//#include +//#define PRINTF(...) printf(__VA_ARGS__) +//#define SPRINTF(...) sprintf(__VA_ARGS__) + // extern extern void stdout_puts(const char *s); diff --git a/Makefile b/Makefile index 05e738f..4e950c1 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ Core/Src/app_temp.c \ Core/Src/app_knob.c \ Core/Src/app_buzzer.c \ Core/Src/app_heater.c \ +Core/Src/uart_stdout.c \ Core/Src/stm32f1xx_it.c \ Core/Src/system_stm32f1xx.c \ Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ diff --git a/STM32F103C8Tx_FLASH.ld b/STM32F103C8Tx_FLASH.ld index e35e3ea..3850058 100644 --- a/STM32F103C8Tx_FLASH.ld +++ b/STM32F103C8Tx_FLASH.ld @@ -62,8 +62,8 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 48K -EEPROM_EMU (rx) : ORIGIN = ORIGIN(FLASH) + LENGTH(FLASH), LENGTH = 16K +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 56K +EEPROM_EMU (rx) : ORIGIN = ORIGIN(FLASH) + LENGTH(FLASH), LENGTH = 8K } /* Define output sections */ @@ -135,7 +135,7 @@ SECTIONS _sidata = LOADADDR(.data); /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : + .data : { . = ALIGN(4); _sdata = .; /* create a global symbol at data start */ @@ -146,7 +146,7 @@ SECTIONS _edata = .; /* define a global symbol at data end */ } >RAM AT> FLASH - + /* Uninitialized data section */ . = ALIGN(4); .bss : @@ -174,7 +174,7 @@ SECTIONS . = ALIGN(8); } >RAM - + /* Remove information from the standard libraries */ /DISCARD/ :