STM32F3 hangs when using event listener
Posted: Mon Apr 15, 2013 9:48 pm
Hi all,
I've ported my project from the simulator to the STM32F3 discovery board. Since the simulator uses serial drivers, I used those rather than USARTs. I found that using event listeners on the serial ports causes Chibios to hang (but only if they are actually called). If I comment out the listener, the code runs happily. I stripped out all code from my project and finally ended up with this relatively simple test case:
This code will hang until you comment out the chEvtRegister() call under the comment starting with "HERE".
Also note that I'm calling the "ledblink" function from SYSTEM_TICK_EVENT_HOOK and when Chibios hangs, it also stops flashing.
Output on the serial port from above is this, after the second '1' Chibios hangs:
Any help would be much appreciated. Thanks in advance.
Cheers,
Vik
I've ported my project from the simulator to the STM32F3 discovery board. Since the simulator uses serial drivers, I used those rather than USARTs. I found that using event listeners on the serial ports causes Chibios to hang (but only if they are actually called). If I comment out the listener, the code runs happily. I stripped out all code from my project and finally ended up with this relatively simple test case:
Code: Select all
#include "ch.h"
#include "hal.h"
#define cputs(msg) chnWrite(&SD1, (unsigned char*) msg, sizeof(msg));
static EventListener sd1fel, sd2fel;
static VirtualTimer vt1;
int counter = 0;
/* this may be called from SYSTEM_TICK_EVENT_HOOK */
void ledblink(void)
{
static bool s = true;
if(s) {
palSetPad(GPIOE, GPIOE_LED8_ORANGE);
s = false;
} else {
palClearPad(GPIOE, GPIOE_LED8_ORANGE);
s = true;
}
}
static void ledoff(void *p) {
(void)p;
palClearPad(GPIOE, GPIOE_LED3_RED);
}
static void gpt2cb(GPTDriver *gptp) {
(void) gptp;
static bool s = true;
counter++;
if(s) {
palSetPad(GPIOE, GPIOE_LED5_ORANGE);
s = false;
} else {
palClearPad(GPIOE, GPIOE_LED5_ORANGE);
s = true;
}
}
static const GPTConfig gpt2cfg = {
1000, /* 1kHz timer clock.*/
gpt2cb /* Timer callback.*/
};
static void sd1_handler(eventid_t id)
{
flagsmask_t flags;
(void)id;
flags = chEvtGetAndClearFlags(&sd1fel);
cputs("1\r\n");
}
static void sd2_handler(eventid_t id) {
flagsmask_t flags;
(void)id;
cputs("2\r\n");
flags = chEvtGetAndClearFlags(&sd2fel);
}
static evhandler_t fhandlers[] = {
sd1_handler,
sd2_handler
};
int main(void) {
halInit();
chSysInit();
/* Init pins for serial ports 1 and 2 */
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); /* USART1 TX. */
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); /* USART1 RX. */
palSetPadMode(GPIOB, 3, PAL_MODE_ALTERNATE(7)); /* USART1 TX. */
palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(7)); /* USART1 RX. */
sdStart(&SD1, NULL);
sdStart(&SD2, NULL);
gptStart(&GPTD2, &gpt2cfg);
gptStartContinuous(&GPTD2, S2ST(1));
cputs("Adding handler for SD1\r\n");
// HERE: comment out the following line and the code will work
chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 0);
cputs("Adding handler for SD2\r\n");
chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2);
while(!chThdShouldTerminate()) {
palSetPad(GPIOE, GPIOE_LED3_RED);
chVTSet(&vt1, MS2ST(200), ledoff, NULL);
cputs("mainloop\r\n");
chEvtDispatch(fhandlers, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(1000)));
}
chEvtUnregister(chnGetEventSource(&SD1), &sd1fel);
chEvtUnregister(chnGetEventSource(&SD2), &sd2fel);
return 0;
}
This code will hang until you comment out the chEvtRegister() call under the comment starting with "HERE".
Also note that I'm calling the "ledblink" function from SYSTEM_TICK_EVENT_HOOK and when Chibios hangs, it also stops flashing.
Output on the serial port from above is this, after the second '1' Chibios hangs:
Code: Select all
Adding handler for SD1
Adding handler for SD2
mainloop
1
mainloop
1
Any help would be much appreciated. Thanks in advance.
Cheers,
Vik