I have problem with interrupt, I am using mbed API with simplest example but once the interrupt should be triggered it hangs MCU, couldn’t find the problm. same happens when I use HAL Gpio interrupt,
here is the code
/* mbed Microcontroller Library
* Copyright (c) 2023 ARM Limited
* SPDX-License-Identifier: Apache-2.0
DigitalOut led(G_LED, 1);
Relay rel1(Relay1), rel2(Relay2);
//DirectADC adc1(DC_ADC1, 4);
//DirectADC adc2(DC_ADC2, 4);
#define debug_printf TraceVSPI::printf
debug_printf("Trace Init Done -- \r\n");
debug_printf("time pass -- \r\n");
what exactly is this?
I am asking because all methods like - printf, getc/s, putc/s, wrire, read and so on are covered by
Mutex in whole MbedOS and Mutex can not be called in ISR. You need to set a bool flag and proces it in main loop or take the code out from ISR context via EventQueue
Also some info about your target will be handy.
Please try to use mbed_error_printf(…) instead of printf(…) in interrupt context.
Such like as:
/* Call mbed_error_printf(…) instead of printf(…) in interrupt context */
mbed_error_printf(“Called in ISR\r\n”);
/* Call printf(...) or mbed_error_printf(...) in thread context at least once before the mbed_error_printf(...) call in interrupt context */
mbed_error_printf("Called in main\r\n");
That’s my class for printf and other stuff, turns out that was problem, I removed that function from interrupt callback and everything works just fine. maybe it was taking some time there and had trouble with interrupt handler.
Definitely the printf is function that take a lot, but in Mbed also trigger Mbed OS crash when is called from ISR because of Mutex.