Skip to main content
Graduate
August 2, 2024
Question

Not worth it, STM products are garbage.

  • August 2, 2024
  • 3 replies
  • 2030 views

H

    This topic has been closed for replies.

    3 replies

    Super User
    August 3, 2024

    Is the LED off if you comment out BSP_ledOn()? Your code only turns the LED on, not off. If it's on to begin with, pressing the button won't do anything.

     

    Need to set port C in EXTI_EXTICRx register.

    in the interrupt, you should check for and clear the EXTI flag for pin 13 in EXTI_FPR1, and only turn on the LED if it's set. Don't need to do anything with NVIC functions or register.

     

    bymAuthor
    Graduate
    August 3, 2024

    Thank you TDK, I should've clarified, the interrupt is always on,  when I set a breakpoint at the interrupt, it breaks all the time, hence the LED is always on.

    I added code for FPR1 to clear that bit and the LED now blinks very fast that it is barely on, looks like d flicker.

    I haven't figured out how to use EXTI_EXTICRx yet. Looks aweful convoluted and will take more time.

     

    Thank you again.

     

     

    Super User
    August 4, 2024

    The RM is a little confusing, but I think it's all written correctly.

    > I need help with figuring out what x and m are and what exactly is nb_ioport?

    For the EXTICR4 register, x=4. m = 4 * (x - 1) per the manual, so m=12 for this register.

    nb_ioport is the pin number. It's 13 for PC3.

     

    EXTICR1 configures pins 0-3, EXTICR2 configures pins 4-7, etc, so EXTICR4 configures pins 12-15.

    x=4 in EXTICR4, so m = 4 * (x - 1) = 12, so you want to configure the EXTIm+1 register, which is bits 8-15. Write a 0x2 there.

     

    EXTI_EXTICR1_EXTI0_0 is bit 0 of the EXTI_EXTICR1_EXTI0 field, and so on. This is the standard convention with all the CMSIS register defines.

     

    Does that help?

    Super User
    August 4, 2024

    See the highlighted regions. (EXTIm+1 is on the next page, same idea though.)

    TDK_0-1722800579724.png

     

    bymAuthor
    Graduate
    August 4, 2024

    How was that supposed to be helpful? What is m and what is x? I already copied and posted the manual gibrish. 

    This post has been edited as it wasn't following the ST Community guidelines.

     

     

    Super User
    August 4, 2024

    This code is for PA8 on a C011:

    void EXTI4_15_IRQHandler(void) {
     if(EXTI->FPR1 & EXTI_FPR1_FPIF8) {
     // do something
     EXTI->FPR1 |= EXTI_FPR1_FPIF8; // clear pending bit
     }
    }
    
    // make PA8 EXTI interrupt
    void init_EXTI() {
    
     RCC->IOPENR |= RCC_IOPENR_GPIOAEN; // enable peripheral clock
     (void)RCC->IOPENR; // read back to make sure that clock is on
     GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODE8_Msk) | (0 << GPIO_MODER_MODE8_Pos); // input mode
    
     EXTI->FTSR1 |= EXTI_FTSR1_FT8; // enable falling edge of Px8 (x=any port), we use it for PA8 
     EXTI->EXTICR[3] |= 0 << EXTI_EXTICR3_EXTI8_Pos; // set port to A for PA8
    
     EXTI->IMR1 |= EXTI_IMR1_IM8; // EXTI CPU wakeup with interrupt mask register
     //EXTI->EMR1 |= EXTI_EMR1_EM8; // EXTI CPU wakeup with event mask register
    
     NVIC_EnableIRQ(EXTI4_15_IRQn);
    }

     

    What you have found (12.5.6 EXTI external interrupt) plus Table 47. EXTI controller register register map and reset values explains it. Yes, each 8-bit block in a EXTI_EXTICRx is a bitmap of the enableds ports.

    hth

    KnarfB

    Super User
    August 4, 2024

    > Doesn't that mean that x1 is for bit 0-7 

    No, these are the GPIO port selection bits.