(STM32L476RG) Flag setting (osThreadFlagsSet) crashes microcontroller when executed in an Interrupt (GPIO EXTI) - interrupt

I am currently learning CMSIS-RTOS v2 and I have an issue that is bugging me and I can't find the answer I need.
I am using the STM32L476-Disco board and the joystick center button as an interrupt. I have a very simple Interrupt callback for my center joystick interrupt :
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
//osEventFlagsSet(evt_id,0x0001);
HAL_GPIO_TogglePin(LD5_GPIO_Port,LD5_Pin);
osThreadFlagsSet(ThId_Led_Blink,0x0001);
}
When I call osThreadFlagsSet, the microcontroller freezes and nothing else happen. This is why I've put the HAL_GPIO_TogglePin : to see if the mcu was still responding or not.
I know that my interrupt resets correctly because when I only put my pin toggle, I can toggle the Led correctly.
ThId_Led_Blink is a ThreadId
osThreadId ThId_Led_Blink;
I've checked that the ID is set correctly in my debugger and it is (it's not null).
As you can see, I've tried with osEvenFlagsSet and I have the same result.
When I check the CMSIS_RTOS v2 documentation, it does specify that osThreadFlagsSet can be called from an ISR, but I am not sure if I need to do something else in that case for the Flags to be set correctly and resolve the issue when the ISR is hanging.
Thanks for your help

So after frustrating hours of searching, I finally fixed my issue.
As described in this website : https://www.freertos.org/RTOS-Cortex-M3-M4.html, for STM32 microprocessor, you need to set the NVIC Group Priority to 4. If you look on freeRTOS, they are talking about putting this line in your code :
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
However, the STM32 has it's own library for the NVIC and the correct function to set the priority group is :
HAL_NVIC_SetPriorityGrouping(4);
Why go with the same name when you can change everything?
So make sure to call this function before your kernel initialization if you are using nested interrupts with FreeRTOS/CMSIS RTOS.
Also, make sure that your nested interrupt priority is in the range of configured interrupt priority for your FreeRTOS, otherwise, the osThreadFlagsSet function will fail automatically.

Related

How to create my own unique interrupt signal and interrupt handler in EFR32FG14

I have an EFR32FG14 evaluation board with the example shown in the end.
where it get triggered by an odd number of pins getting pressed.
I want to change this example (in code) so i get the interrupt be triggered by a single pin ,not odd or even.
I have looked inside the example and i see there two lines
NVIC_EnableIRQ(GPIO_ODD_IRQn);
GPIO_ODD_IRQn = 18, /*!< 16+18 EFR32 GPIO_ODD Interrupt */
Inside the GPIO_ODD_IRQHandle event handler called we have
GPIO_IntClear(0xAAAA);
i want to enable interrupt only for PF7(not even or odd) and write an event handler for it.
Is it possile?Thanks.
datasheet:
https://www.silabs.com/documents/public/data-sheets/efr32fg14-datasheet.pdf
user guide:
https://www.silabs.com/documents/public/user-guides/ug318-brd4257b-user-guide.pdf
code example link:
https://github.com/SiliconLabs/peripheral_examples/blob/master/series1/gpio/switch_led_interrupt/src/main_s1.c
I have learned the interrupt system,and ran close example to what i want shown in the post.
The interrupt numbers are fixed when the silicon chip is manufactured. You can't change them.
To have some action taken on PF7 only you could try to use the odd numbered pin interrupt, and then in the handler check which pin was signalled. If it wasn't PF7, then do nothing.

STM32CubeIDE stuck on SysTick_Handler

I created a new STM32CubeIDE project for the STM32F030CC mcu. I added a GPIO output port on PA8 to enable/disable an LED. Now I tried to delay the toggle by calling HAL_Delay. But my problem is, that the interrupt SysTick_Handler does not get called.
I am a bit stuck since I found no working solution. Do I need to set up the systick interrupt myself? Or has someone a sample project which works with the STM32F030CC?
i used STM32Cube for stm32f103, and set like your config and it worked correctly
there isn't need to set up the systick interrupt yourself
did you debug your code?
if this lines occur
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000U);
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0U);
your systick should start with 1ms clock
these code are in HAL_InitTick(TICK_INT_PRIORITY); and it call by HAL_Init();

GPIO interrupt for MSP430f2274

i am working on a project in msp430f2274 microcontroller. In my project i am trying to read an reed switch which is being connected to a GPIO pin at P2.3. Normally the pin will remain HIGH as it is being connected to pull up from the hardware. when once the switch is pressed/activated a LOW will come and it will trigger the Hardware. till here it is working fine. but now i want to read the other interrupt also, when it goes back to high. I have tried the interrupt type from low - high to high -low in ISR but still no efffect. please help.
i have added ISR from the code
static char x=0;
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1IES^=BIT2;
P1OUT^=(BIT0); // enrer the rest code for detection of door open or close.
P1IFG &= ~BIT2;
//P1IES&=~BIT2;
__bis_SR_register_on_exit(GIE+LPM0_bits); // Enter LPM3 on ISR exit
}
Just an idea, sry if this doesn't help.
You could use a timer that starts with the button click and triggers an interrupt when the button is released.

LPC17xx sleep modes and software reset error when invoked in interrupt

I have a problem with both the sleepmodes and NVIC_reset(), aka software reset.
The problem is present on two totally distinct boards, both with a LPC1769 uC.
If I enter the sleepmode within main() or another function, except an interrupt routine, the sleep mode is working perfecly. The uC wakes also with an external interrupt on EINT0. The reset function does its job also well in the main function.
But when a sleepmode or reset request is invoked inside an interrupt routine trouble starts. The sleep mode lookes to be entered but the uC does not wake up anymore.
E.g. enter a sleep mode with EINT1 and wake with EINT0:
void EINT0_IRQHandler(void)
{
EXTI_ClearEXTIFlag(0);
}
void EINT1_IRQHandler(void)
{
EXTI_ClearEXTIFlag(1);
CLKPWR_Sleep();
}
Anybody a clue why this does not work properly?
Have you checked your interrupt priorities?
34.3.5.2.1 Wakeup from WFI or sleep-on-exit
Normally, the processor wakes up only when it detects an exception with sufficient priority
to cause exception entry.

What's the modern equivalent of GetNextEvent in Cocoa?

I'm porting an archaic C++/Carbon program to Obj-C and Cocoa. The current version uses asynchronous usb reads and GetNextEvent to read the data.
When I try to compile this in Objective C, GetNextEvent isn't found because it's in the Carbon framework.
Searching Apple support yields nothing of use.
EDIT TO ADD:
Ok, so what I'm trying to do is run a document scanner through USB. I have set up the USBDeviceInterface and the USBInterfaceInterface (who came up with THAT name???) and I call (*usbInterfaceInterface)->WritePipeTO() to ask the scanner to scan. I believe this works. AT least the flatbed light moves across the page...
Then I try to use *(usbInterfaceInterface))->ReadPipeAsyncTO() to read data. I give this function a callback function, USBDoneProc().
The general structure is:
StartScan()
WaitForScan()
StartScan() calls the WritePipeTO and the ReadPipeAsyncTO
WaitForScan() has this:
while (deviceActive) {
EventRecord event;
GetNextEvent(0,&event);
if (gDataPtr != saveDataPtr) { // more data up the timeout
timeoutTicks = TickCount() + 60 * 60;
saveDataPtr = gDataPtr;
}
if (TickCount() > timeoutTicks) {
deviceActive = false;
}
}
Meanwhile, USBDoneProc incrementing gDataPtr to be the end of the data that we've read so far. It gets called several times during the asynchronous read, called automatically by the callback, as far as I can tell.
If I cake out the GetNextEvent() call in the WORKING code the USBDoneProc doesn't get called until the asynchronous readpipe timesout.
So it looks to me that I need something to give control back to the event handler so that the USBRead interrupts can actually interrupt and make the USBDoneProcget called...
Does that make any sense?
thanks.
I suppose the nearest thing to a Cocoa equivalent would be -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]. But bear in mind that GetNextEvent is archaic even for Carbon. The preferred way of handing events is the "don't call us, we'll call you" scheme, where the app calls NSApplicationMain or RunApplicationEventLoop and events are dispatched to you.
EDIT to add: Does you app have a normal event loop? If so, maybe WaitForScan could start a Carbon timer and return to the event loop. Each time the timer fires, do what you did in the WaitForScan loop.
there is a USB hidapi that works for mac on windows.
http://www.signal11.us/oss/hidapi/
may this could be of help to you?
It works fine (I can list the connected USB devices and connect/write/read to a device);
however, if i USB device is connected/disconnected during the runtime of the application, I don't see the new connected/disconnected devices.
See: https://github.com/signal11/hidapi/issues/14
If I add the following code to hidapi, then hidapi detects the new USB devices.
#include <Carbon/Carbon.h>
void check_apple_events() {
printf("check_apple_events\n");
RgnHandle cursorRgn = NULL;
Boolean gotEvent=TRUE;
EventRecord event;
while (gotEvent) {
gotEvent = WaitNextEvent(everyEvent, &event, 0L, cursorRgn);
}
}
I need to compile this on OSX10.5 because it uses Carbon instead of Cocoa.
I am currently looking how to transform this to Cocoa.
you are also trying to move your code to cocoa, right?
let me know if you find out; I'll post it here if I get it.
regards,
David
Have you considered throwing the whole thing out and using Image Kit's new-in-10.6 scanner support instead? Even if it's custom, writing a TWAIN driver for it might be easier (and is certainly better) than trying to twist Cocoa into a GetNextEvent shape.