Hallo,
bin gerade dabei mich mit dem STM32F4 Discovery Board anzufreunden.
Stehe jetzt vor einem Problem, bei dem ich nicht unbedingt weiter weiß.
Und zwar will ich sobald der USER-Button gedrückt wird, eine LED toggeln
lassen und einen Zahl inkrementieren und diese via USB-Schnittstelle
ausgeben. Alles soll über einen IRQHandler laufen. (Im Beispiel ist der
Code für die USB-Kommunikation nicht enthalten. Die hab ich aus dem
ST-Beispielprogramm genommen und ist auch funktionstüchtig).
1 | #include "ch.h"
|
2 | #include "hal.h"
|
3 | #include "test.h"
|
4 |
|
5 | #define ARM_MATH_CM4
|
6 | #include "arm_math.h"
|
7 |
|
8 | #include "irqconf.h"
|
9 | #include "usbcfg.h"
|
10 |
|
11 | // Code für USB-Kommunikation nicht enthalten
|
12 |
|
13 | // Declare & initialize IRQ counter
|
14 | static uint32_t irq_cnt = 0;
|
15 |
|
16 | // IRQ function
|
17 | void EXTI0_IRQHandler(void) {
|
18 | palSetPad(GPIOD,GPIOD_LED3);
|
19 | /* Make sure that interrupt flag is set.
|
20 | ((uint32_t)0x00001) equals EXTI Line 0*/
|
21 | if ((EXTI->PR & (uint32_t)0x00000001) != (uint32_t)RESET){
|
22 | palTogglePad(GPIOD,GPIOD_LED5);
|
23 | // Do the actual work
|
24 | irq_cnt++;
|
25 | // Clear interrupt flag for EXTI0
|
26 | EXTI->PR |= EXTI_PR_PR0;
|
27 | }
|
28 | }
|
29 |
|
30 | int main(void) {
|
31 |
|
32 | halInit();
|
33 | chSysInit();
|
34 |
|
35 | palSetPadMode(GPIOA, GPIOA_BUTTON, PAL_MODE_INPUT);
|
36 | irq_init();
|
37 |
|
38 | while (true) {
|
39 | chprintf((BaseSequentialStream *)&SDU1,"IRQcounter: %u \r\n", IRQcounter);
|
40 | }
|
41 | chThdSleepMilliseconds(500);
|
42 | }
|
43 | }
|
In irq_conf.c ist folgender Code enthalten:
1 | #include "ch.h"
|
2 | #include "hal.h"
|
3 |
|
4 | void irq_init(void)
|
5 | {
|
6 | // IO port A clock enable
|
7 | RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
|
8 | // System configuration controller clock enable
|
9 | RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
10 |
|
11 | // Enable IRQ for ext. signals, line EXTI0_IRQn. Enables the handling for the
|
12 | // given interrupt request (IRQ#)
|
13 | NVIC_EnableIRQ(EXTI0_IRQn);
|
14 |
|
15 | // Clear EXTI0 bit field
|
16 | SYSCFG->EXTICR[0] &= ~(SYSCFG_EXTICR1_EXTI0);
|
17 | // EXTI x configuration. Select PA to make IRQ EXTI0
|
18 | SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PA;
|
19 |
|
20 | // Rising trigger event configuration bit of line A
|
21 | EXTI->RTSR |= EXTI_RTSR_TR0;
|
22 |
|
23 | // Enable interrupt on EXTI0
|
24 | EXTI->IMR |= EXTI_IMR_MR0;
|
25 |
|
26 | // EXTI->SWIER |= EXTI_SWIER_SWIER0;
|
27 |
|
28 | //END OF IRQ STUFF
|
29 | }
|
In irq_conf.h:
1 | #ifndef IRQ_H
|
2 | #define IRQ_H
|
3 |
|
4 | void irq_init(void);
|
5 |
|
6 | #endif /* IRQ_H */
|
Zum Problem: Sobald ich den USER-Button drücke, "hängt" sich die
USB-Kommunikation auf (IRQcounter: wird nicht mehr ausgegeben). Zudem
wird die IRQ Funktion nicht aufgefrufen (sonst würde LED3 leuchten).
Auch wenn ich einen Software-Interrupt generiere, passiert genau das
selbe wie beim Hardware-Interrupt über den USER-Button. Vielleicht kann
mir jemand weiterhelfen. Bin über jede Hilfe dankbar. Ich versuche alles
ohne die stm32f4xx libraries zu lösen.
Lg Gabriel