Skip to content

Instantly share code, notes, and snippets.

@mofosyne
Last active January 8, 2022 17:25
Show Gist options
  • Save mofosyne/59f3fd7911b74cfcc993a85f3744364b to your computer and use it in GitHub Desktop.
Save mofosyne/59f3fd7911b74cfcc993a85f3744364b to your computer and use it in GitHub Desktop.
// This allows you to easily monitor change to registers that you care about
#define PRINTREG(X, MSG) printf("%15s = %08lX : %s\r\n", (char*) #X, (long unsigned) X, (char*) MSG);
#define PRINTREG_MON(X, MSG) \
{\
static int count = 0;\
static long unsigned prev = 0;\
if (!count) \
{ printf("%4d: %40s = %08lX : %s", (int) count, (char*) #X, (long unsigned) X, (char*) MSG); count++;}\
else if (prev != X) \
{ printf("%4d: %40s = (%08lX --> %08lX) : %s", (int) count, (char*) #X, (long unsigned) prev, (long unsigned) X, (char*) MSG); count++;}\
prev = X;\
}
@mofosyne
Copy link
Author

mofosyne commented Jan 8, 2020

  BOOTLOADER_PRINTREG_MON( stm32bl_gHuart->Instance->TDR     , "USART Transmit Data register");
  BOOTLOADER_PRINTREG_MON( stm32bl_gHuart->Instance->PRESC   , "USART clock Prescaler register");
  BOOTLOADER_PRINTREG_MON( HAL_UART_GetState(stm32bl_gHuart) , stm32bl_uart_state_to_str(HAL_UART_GetState(stm32bl_gHuart)));
  BOOTLOADER_PRINTREG_MON( stm32bl_gHuart->ErrorCode       , stm32bl_uart_error_to_str(stm32bl_gHuart->ErrorCode));
T:    0:        HAL_UART_GetState(stm32bl_gHuart) = 00000020 : Ready
T:    0:                stm32bl_gHuart->ErrorCode = 00000000 : No error
T:    1:            stm32bl_gHuart->Instance->ISR = (006000F8 --> 006000D8) : USART Interrupt and status register
T:    1:            stm32bl_gHuart->Instance->TDR = (00000079 --> 00000000) : USART Transmit Data register

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment