2025-03-27 7:30 PM - edited 2025-03-27 7:36 PM
I am experiencing an issue with my STM32-based project. All interrupt handlers never invoked, including the SysTick handler and USART1_IRQ_Handler. I try to resolve the problem. here is my trying...
1. Vector Table Offset Register (VTOR) Configuration:
I have explicitly set SCB->VTOR = 0x08000000 to ensure the vector table points to the correct memory address. Despite this, the issue persists.
2. SysTick Initialization:
The HAL_InitTick function successfully initializes the SysTick, returning HAL_OK.
3. Global Interrupts:
I have attempted disabling and re-enabling global interrupts using __disable_irq() and __enable_irq() before initialized, but this had no effect.
4. Real-Time Operating System (RTOS):
No RTOS is being used in this project. The setup involves minimal configuration, primarily focusing on clock settings, which have been verified to function correctly.
5. SysTick Control and Status Register:
The CTRL register's 16th bit is set to 1, indicating that the SysTick counter is enabled. However, the SysTick handler is still not being called.
6. Debugger Behavior:
The debugger indicates that the SysTick handler's address is at 0x08000854. Despite this, breakpoints within the handler are never hit, suggesting it is not being invoked.
7. HAL_GetTick Function:
As a result of that, HAL_GetTick function(uwTick) return always zero.
8. SysTick Handler Priority:
The priority of the SysTick handler has been set to 0, the highest priority.
9. UART Interrupts:
After enabling UART and observing that the RXNEIE and RXNE bits are set to 1, the UART interrupt handler is also not being called.
10. Debugger:
Debugger set rcc->cfgr. As that result, the clock configuration of rcc cfgr set incorrectly. So i cleared cfgr register of rcc, RCC->CFGR = 0x00, before HAL_RCC_OscConfig has invoked.
11. code:
#define printr(fmt, ...) printf("[\x1b[31m%s\x1b[0m]" fmt "\r\n", __FUNCTION__, ##__VA_ARGS__)
#define printm(fmt, ...) printf(fmt "\r", ##__VA_ARGS__)
char uart_recv_buf[1024] = {0, };
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(&huart1 == huart)
{
HAL_UART_Receive_IT(huart, (void *)uart_recv_buf, sizeof(uart_recv_buf));
printm("%s", uart_recv_buf);
}
}
void uart_init()
{
HAL_UART_Receive_IT(&huart1, (void *)uart_recv_buf, sizeof(uart_recv_buf));
}
int _write(int file, char *ptr, int len)
{
(void) file;
HAL_UART_Transmit(&huart1, (void*) ptr, len, 10);
return len;
}
/*
uint32_t HAL_GetTick(void) {
if ((SysTick->CTRL >> 16) == 1) //1ms
{
uwTick++;
}
return uwTick;
}
*/
/*
void HAL_Delay(uint32_t Delay) {
uint32_t tickstart = HAL_GetTick();
uint32_t wait = Delay;*/
/* Add a freq to guarantee minimum wait */
/*if (wait < HAL_MAX_DELAY)
{
wait += (uint32_t) (uwTickFreq);
}
while ((HAL_GetTick() - tickstart) < wait){}
uwTick = 0;
}*/
/*
void HAL_IncTick(void) {
return;
}*/
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void uart_printf(char *fmt, ...)
{
char uart_send_buffer[1024] = {0, };
va_list va;
va_start(va, fmt);
vsnprintf(uart_send_buffer, sizeof(uart_send_buffer), fmt, va);
HAL_UART_Transmit(&huart1, (uint8_t *)uart_send_buffer, strlen(uart_send_buffer), 10);
va_end(va);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
SystemInit();
RCC->CFGR = 0x00;
/* 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_USART1_UART_Init();
/* USER CODE BEGIN 2 */
//__disable_irq();
//__enable_irq();
uart_init();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_4);
printr("uart send data");
HAL_Delay(500);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Given these observations, I suspect that the inability to write to the option bytes and the potential misconfiguration of the vector table are contributing factors. The failure of both SysTick and UART interrupts suggests a broader issue with interrupt handling in the system.
I would appreciate any insights or suggestions from the community to help diagnose and resolve this problem.
Solved! Go to Solution.
2025-03-28 3:27 AM
After connecting the debugger, even though the RXNEIE bit is set to 1 and the RE bit is set to 1, the rx callback function does not execute.
However, when the debugger is disconnected and the elf file is written via Cube Programmer UART, the callback function works correctly.
No additional code was added. I have confirmed that the value of uwTick is normal as well. Perhaps my stlink is broken...
2025-03-28 2:41 AM
I don't see you enabling the interrupts:
HAL_NVIC_SetPriority( MY_UART_IRQn, MY_UART_NVIC_PRIORITY, MY_UART_NVIC_SUBPRIO );
HAL_NVIC_EnableIRQ ( MY_UART_IRQn );
If you've implemented _write you shouldn't also need to implement your own printf
2025-03-28 3:02 AM
I don't use Cube, to put this upfront.
But check your map file, and verify your interrupt handlers are actually linked in.
Many handlers have a default '__weak' handler implementations, often in the startup code.
2025-03-28 3:22 AM
After disconnecting the debugger and writing the elf file via UART, the issue was resolved.
It seems that due to a debugger problem, trash data—such as that in RCC->CFGR—is getting into the system during reset.
Now everything is working properly; the RXNE bit is set to 1, and I have confirmed that the rx complete callback function is being executed.
2025-03-28 3:27 AM
After connecting the debugger, even though the RXNEIE bit is set to 1 and the RE bit is set to 1, the rx callback function does not execute.
However, when the debugger is disconnected and the elf file is written via Cube Programmer UART, the callback function works correctly.
No additional code was added. I have confirmed that the value of uwTick is normal as well. Perhaps my stlink is broken...