2023-08-06 12:42 PM
I need help with USART LOGGER _ON enabling. How to enable logger to send serial data via usart?
I have in logger.h - #define LOGGER_ON 1, also in logger.c
#if (USE_LOGGER == LOGGER_ON)
.....
#endif /* #if USE_LOGGER == LOGGER_ON */
and platform.h
How to "USE_LOGGER" flag set to 1 (enabling logger) in main.c, where to put USE_LOGGER = LOGGER_ON? Is it enabled via Cube_MX?
Solved! Go to Solution.
2023-08-07 01:59 AM
In this case, if you have the complete project, from where these files were obtained: there is a function in STM32CubeIDE that "Opens the declaration" (keyboard shortcut: CTRL+Mouse click on the word). Or you can also click once on the word to select it and press the F3 key.
But if you don't have the complete project, you can put the declarations in any file that this file has access to, maybe in the file itself, or in main.h for example.
#define USE_LOGGER 1
#define LOGGER_ON 1
2023-08-06 05:23 PM
On STM32F407VGT6 I use these routines in the main.c file:
#include <stdio.h>
/* USER CODE BEGIN 4 */
int __io_putchar(int ch) {
uint8_t c[1];
c[0] = ch & 0x00FF;
HAL_UART_Transmit(&huart1, &*c, 1, 10);
return ch;
}
int _write(int file, char *ptr, int len) {
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++) {
__io_putchar(*ptr++);
}
return len;
}
And these routines in the main.h file:
/**/
#ifndef UsrLog
#define UsrLog(...) do { \
printf(__VA_ARGS__); \
printf("\n"); \
} while (0)
#endif
/* USER CODE END EM */
To send a message:
UsrLog("Battery: error; tick: %lu", HAL_GetTick());
I don't know if it can help in your case, but I found these videos about advanced debugging:
https://youtube.com/playlist?list=PLnMKNibPkDnEDEsV7IBXNvg7oNn3MfRd6
2023-08-07 01:09 AM - edited 2023-08-07 01:24 AM
Thanks for your tip (it will be useful to me), but I have problem with enabling logger to send a message via this function, when program reaches this function, USE _LOGGER is 0 (LOGGER_OFF) instead of 1 (LOGGER_ON), so routine just jump to Return0 without message send (code below is also highlighted in IDE like inactive).
uint8_t logUsartTx(uint8_t *data, uint16_t dataLen)
{
if(pLogUsart == 0)
return ERR_INVALID_HANDLE;
#if (USE_LOGGER == LOGGER_ON)
{
return HAL_UART_Transmit(pLogUsart, data, dataLen, USART_TIMEOUT);
}
#else
{
return 0;
}
#endif
}
2023-08-07 01:59 AM
In this case, if you have the complete project, from where these files were obtained: there is a function in STM32CubeIDE that "Opens the declaration" (keyboard shortcut: CTRL+Mouse click on the word). Or you can also click once on the word to select it and press the F3 key.
But if you don't have the complete project, you can put the declarations in any file that this file has access to, maybe in the file itself, or in main.h for example.
#define USE_LOGGER 1
#define LOGGER_ON 1
2023-08-10 03:31 AM
Thanks, your tip help me to find out that USE_LOGGER wasn't never defined :thumbs_up: