Interrupt Question

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

CTSchorsch
Posts: 2
Joined: Tue Nov 27, 2018 4:30 pm

Interrupt Question

Postby CTSchorsch » Tue Nov 27, 2018 4:40 pm

Dear Forum,

i'm new to ChiBios, i have to use it, because its the firmware of my VESC Motorcontroller :) I want to add a custom app (thread) to this firmware and wants to use a pin change interrupt. I tried to use some lines from the existing code as example, but its not running and the device reboots :) Maybe it is just a small mistake and if someone hast time to look on my code, i would appricate it.

some defines:

Code: Select all

//Trigger and Speed Hall Pins
#define HW_HALL_TRIGGER_GPIO            GPIOC
#define HW_HALL_TRIGGER_PIN             13
#define HW_HALL_ROTARY_A_GPIO           GPIOC
#define HW_HALL_ROTARY_A_PIN            14
#define HW_HALL_ROTARY_B_GPIO           GPIOC
#define HW_HALL_ROTARY_B_PIN            15
#define HW_HALL_ROTARY_A_EXTI_PORTSRC   EXTI_PortSourceGPIOC
#define HW_HALL_ROTARY_A_EXTI_PINSRC    EXTI_PinSource14
#define HW_HALL_ROTARY_A_EXTI_CH        EXTI15_10_IRQn
#define HW_HALL_ROTARY_A_EXTI_LINE      EXTI_Line14
#define HW_HALL_ROTARY_A_EXTI_ISR_VEC   EXTI15_10_IRQHandler


and the "custom app" with thread definition. at the moment the isr does nothing

Code: Select all

#include "ch.h" // ChibiOS
#include "hal.h" // ChibiOS HAL
#include "mc_interface.h" // Motor control functions
#include "hw.h" // Pin mapping on this hardware
#include "timeout.h" // To reset the timeout
#include "commands.h" //just for printf in terminal
#define AVAILABLE_POWERS 3

CH_IRQ_HANDLER(HW_HALL_ROTARY_A_EXTI_ISR_VEC) {
        if (EXTI_GetITStatus(HW_HALL_ROTARY_A_EXTI_LINE) != RESET) {
                commands_printf("Rotary A Interrupt fired");
                // Clear the EXTI line pending bit
                EXTI_ClearITPendingBit(HW_HALL_ROTARY_A_EXTI_LINE);
        }
}

static THD_FUNCTION(dpv_thread, arg);
static THD_WORKING_AREA(dpv_thread_wa, 2048); // 2kb stack for this thread

void app_dpv_init(void) {
        EXTI_InitTypeDef   EXTI_InitStructure;

        commands_printf("DPV App init");
        // Set the UART TX pin as an input with pulldown
        palSetPadMode(HW_HALL_TRIGGER_GPIO, HW_HALL_TRIGGER_PIN, PAL_MODE_INPUT_PULLUP);
        palSetPadMode(HW_HALL_ROTARY_A_GPIO, HW_HALL_ROTARY_B_PIN, PAL_MODE_INPUT_PULLUP);
        palSetPadMode(HW_HALL_ROTARY_B_GPIO, HW_HALL_ROTARY_B_PIN, PAL_MODE_INPUT_PULLUP);

        // Interrupt on HALL ROTARY A Pin
        // Connect EXTI Line to pin
        SYSCFG_EXTILineConfig(HW_HALL_ROTARY_A_EXTI_PORTSRC, HW_HALL_ROTARY_A_EXTI_PINSRC);

        // Configure EXTI Line
        EXTI_InitStructure.EXTI_Line = HW_HALL_ROTARY_A_EXTI_LINE;
        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;
        EXTI_Init(&EXTI_InitStructure);

        // Enable and set EXTI Line Interrupt to the highest priority
        nvicEnableVector(HW_HALL_ROTARY_A_EXTI_CH, 0);
        // Start the dv thread
        chThdCreateStatic(dpv_thread_wa, sizeof(dpv_thread_wa),
                NORMALPRIO, dpv_thread, NULL);
}

static THD_FUNCTION(dpv_thread, arg) {
        (void)arg;

        chRegSetThreadName("app_dpv");
        static bool need_to_change_power_in_future = false;
        static float power[AVAILABLE_POWERS] = {0.7, 1, 0.5};
        static int power_index = 0;
        static bool first=true;
       for(;;) {

                if ( ! palReadPad(HW_HALL_TRIGGER_GPIO, HW_HALL_TRIGGER_PIN)) {
                        if (first) {
                                commands_printf("Trigger: %f",power[power_index]);
                                first=false;
                        }
                        mc_interface_set_duty(power[power_index]);
                        need_to_change_power_in_future = true;
                } else {
                        first=true;
                        if(need_to_change_power_in_future){
                                need_to_change_power_in_future = false;
                                power_index=(power_index+1)%AVAILABLE_POWERS;
                        }
                        // If the button is not pressed, release the motor
                        mc_interface_release_motor();
                }

                // Run this loop at 100Hz
                chThdSleepMilliseconds(10);

                // Reset the timeout
                timeout_reset();
        }
}


Thanks in advance
Georg

CTSchorsch
Posts: 2
Joined: Tue Nov 27, 2018 4:30 pm

Re: Interrupt Question

Postby CTSchorsch » Tue Nov 27, 2018 4:54 pm

Please ignore the previous post. As often, after asking for help, the right idea just comes into the brain.

i had to move the ISR to another file (irq_handlers.c), now everything is working

Thanks, and sorry for disturbing

Regards
Georg

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Interrupt Question

Postby Giovanni » Tue Nov 27, 2018 6:25 pm

Hi,

Don't worry :)

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 45 guests