How can I display debug message in interrupt routine?
Hello,
I use stm32l412b / FreeRTOS.
I use below function to display dubug message.
The MCU is halted and a watchdog reset occurs when the function below is called in interrupt routie.
It works normally if not in interrupt
Would you let me know what is wrong?
Is there a way to display a debug message within an interrupt, even if it's not in the function below?
thanks.
*******************************************************
int uart_debug_send(const char * fmt, ...)
{
va_list ap;
int rvalue;
int retry = UART_RETRY;
uint16_t queue_len = UART_QUEUE_SIZE;
uint16_t item_num = 0;
uint8_t* temp_arry;
int is_isr = __get_IPSR();
int re_err = 0;
UBaseType_t uxSavedInterruptStatus;
// if (is_isr)
// return 0;
while (switching_lock_it_safe(uart_lock,UART_BUSY_WAIT_TIME) < 0)
{
if (retry <= 0)
return -1;
else
{
if(!is_isr)
vTaskDelay(1);
retry--;
}
}
if (!is_isr)
{
taskENTER_CRITICAL();
temp_arry = pvPortMalloc(sizeof(uint8_t) * UART_TX_BUF_LEN);
taskEXIT_CRITICAL();
}
else
{
uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
temp_arry = pvPortMalloc(sizeof(uint8_t) * UART_TX_BUF_LEN);
taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
}
if(temp_arry <= 0)
{
switching_unlock_it_safe(uart_lock);
return -1;
}
va_start(ap, fmt);
rvalue = vsnprintf((char *) temp_arry,UART_TX_BUF_LEN, fmt, ap);
va_end(ap);
if(rvalue >= UART_TX_BUF_LEN)
rvalue = UART_TX_BUF_LEN;
do {
queue_len = UART_QUEUE_SIZE;
item_num = circ_buf_get_length(g_uart_queue);
queue_len -= item_num;
if( queue_len >= rvalue) {
if(is_isr)
re_err = circ_buf_put_fromISR(g_uart_queue, temp_arry, rvalue);
else
re_err = circ_buf_put(g_uart_queue, temp_arry, rvalue);
if (re_err == 0) {
vPortFree(temp_arry);
switching_unlock_it_safe(uart_lock);
xTimerStart(g_uart_timer, 0);
return 0;
}
}
else
{
// TODO.
// Should check the uart TXE intr.
//
if(item_num > UART_TX_BUF_LEN) item_num = UART_TX_BUF_LEN;
if(is_isr)
re_err = circ_buf_pop_fromISR(g_uart_queue, g_uart->txb, item_num);
else
re_err = circ_buf_pop(g_uart_queue, g_uart->txb, item_num);
g_uart_dev.send(g_uart, item_num);
if(!is_isr)
vTaskDelay(1);
continue;
}
}while (queue_len < rvalue);
vPortFree(temp_arry);
switching_unlock_it_safe(uart_lock);
xTimerStart(g_uart_timer, 0);
return -1;
}
