Blue Pill: Application crashing debugger; unable to reset in the debugger.
What would cause an application to crash the debugger and not be able to reset in the debugger, without exiting the debugger?
I am just about finished with my application I have been working on for a few months.
The processor is a STM32G051K8T and I have upgraded to STMCubeIDE 1.10.1 and am using the ST-LINK V2 (Blue pill) with my custom board.
All of a sudden it is hanging up in the main program.
At first it hung up in the middle of a sprintf() statement.
The statement was
char buf[120];
sprintf(buf,"Calibration Factor: %lu\r\n",ADC1->CALFACT); // dies on this statement
print_debug_str("Hello World\r\n");
char buf[120] was originally char buf[40] but I made it longer in the unlikely case it was overrunning the buffer. Made no difference.
I changed "ADC1-CALFACT" to "16l" or "(uint32_t) 16" made no difference. it just hung on that command.
Since I new sprintf probably used the heap, I went into STM32G051K8TX.ld to maje the minimum heap 0x300 from 0x200. And it made no difference.
My first thought was it is happening at a certain memory location. So I put 100 __NOP(); statements before the code that had the sprintf() in it. Did not matter, it still hung up on the sprintf()
I commented out the sprintf() statement and changed the print_debug_str(buf); to
print_debug_str("Hello World\r\n"); and it hung up in the print_debug str() routine.
void print_debug_str(void * s)
{
static uint8_t db[256];
volatile uint32_t i = 0;
volatile uint32_t j;
uint16_t len = strlen(s);
while (UART1Busy) i++;
memmove(db,s,len);
UART1Busy = true;
for (j=0;j<2500;j++) i++; // now stopping here
HAL_UART_Transmit_DMA(&huart1,db,len);
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
UART1Busy = false;
UNUSED(huart);
}That made me wonder if it was not memory based but time based.
So I put the 100 __NOP(); in a for loop;
{
uint16_t i;
for (i=0;i<30000;i++)
{
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 20
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 40
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 60
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 80
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 100
}
}Now it stops in this code before the sprintf() statement.
I am now guessing it is a time issue. It happens at a certain time.
I have never setup the watchdog timer and I do use three timers (TIM2, TIM3, TIM14) later in the program. So just incase they are now not working like they used to, I decided to comment them out, which caused a warning about the routines not being called.
Here is the current version of the code. Until it breaks:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_I2C1_Init();
//MX_TIM2_Init();
//MX_TIM3_Init();
//MX_TIM14_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
/* Initialize interrupts */
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
/*
ENCODER_POWER_OFF; // Make sure encoder is off so it can start correctly.
print_debug_str("Encoder Power Off\r\n");
TASK_PIN_L;
TP2_L;
DIO2_L;
DIO3_L;
DIO4_L;
if (isDebug(DEBUG_verify_memory_structures))
{
verify_memory_structures();
}
*/
__NOP();
{
uint16_t i;
for (i=0;i<30000;i++)
{
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 20
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 40
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 60
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 80
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); // 100
}
}
//ADC_init();
__NOP();
if (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
{
print_debug_str("Did not calibrate right!\r\n\r\n");
}
else
{
char buf[120];
sprintf(buf,"Calibration Factor: %lu\r\n",ADC1->CALFACT); // dies on this statement
//sprintf(buf,"Calibration Factor: %lu\r\n",(uint32_t) 0xA5A5A5A5); // dies on this statement
print_debug_str(buf);
}Maybe I need to explain what happens.
I run the debugger to the __NOP(); on line 55 where I have a break point, I also have a break point at the __NOP(); on line 69. When I tell it to Resume after the first breakpoint, it never returns and breaks at line 69.
Suspend does not appear to really work. It goes off and resume turns on, but I cannot examine variables. When I try to look at i it says "Error: Multiple errors reported.\ Failed to execute MI command: -var-create - * i Error message from debugger back end: -var-create: unable to create variable object\ Unable to create variable object"
trying the reset button the resume button goes out, and the suspend button lights up, but it does not go back to the beginning of main() like normal,
As a result, I have to use the Terminate button to leave the debugger, then Run -> Debug to get back into the debugger.
I upgraded to STM32CubeIDE 1.10.1 recently. Is this one of those known problems for ST in this version?
Did version 1.10.1 turn on something like the watchdog timer by default?
Any suggestions how to get past this? This has been working everyday for the past 2-3 months.
I have attached the whole main.c code so you can see how the peripherals were setup before this code was executed.
I am at a loss as to what happened. This was working. Could have something happened to the processor? I do not want to swap processors if I do not need to.
Thanks,
Kip
