Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

STM32F4 - Interrupt-i

[es] :: Elektronika :: Mikrokontroleri :: STM32F4 - Interrupt-i

[ Pregleda: 2743 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

zivadin_despot
Živadin Despotović
Novi Sad

Član broj: 175438
Poruke: 704
*.dynamic.isp.telekom.rs.



+5 Profil

icon STM32F4 - Interrupt-i19.03.2012. u 16:05 - pre 147 meseci
Interesuje me sintaksa za prekidnu funkciju..
Za pic-eve u uC-u izgleda:

Code:

void interrutp(){
  if(flag){
  ...
  }
}


gde je "flag" falg bit koji se setuje za odredjeni interupt. Kako bi ovo izgledalo u atollic-u?
Nasao sam nesto ovog tipa:

Code:

void prekid (void)__attribute__((interrupt("EXTI")));


ali u ovoj funkciji ne mogu nista raditi, pa predpostavljam da se ovim dodeljuje da je funkcija prekid() funkcija u koju ce program skociti kada se desi bilo koji prekid EXTI, a u njoj proveramav flag-ove, jel?

Pozdrav
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: STM32F4 - Interrupt-i19.03.2012. u 21:24 - pre 147 meseci
prilicno sam u guzvi tako da evo copy/paste bitnog dela STM-ovog primera + po neki komentar od mene.. malo detaljnije sutra


konfiguracija
Code:

//dakle ova funkcija kao sto pise konfigurise EXTI interrapt 
void EXTILine0_Config(void)
{
  //GPIO struktura nam treba da bi konfigurisali PA0 pin
  GPIO_InitTypeDef   GPIO_InitStructure;

  //NVIC struktura sluzi za siljenje vektora prekida
  NVIC_InitTypeDef   NVIC_InitStructure;
  
  // EXTI definise EXTERNAL INTERRUPT
  EXTI_InitTypeDef   EXTI_InitStructure;

  //dakle ovde kresnemo PORTA modul, tj damo mu clock
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  //ovde kresnemo syscfk modul, tj damo mu klok, 
  //syscfg modul obradjuje external interrupt
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  
  //ovo je valjda jasno, dakle definisemo PA0 kao input
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  //ovde vezujemo PA0 na EXTI Line0
  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

  /* Configure EXTI Line0 */ //konfiguracija EXTI-a
  EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  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 Line0 Interrupt to the lowest priority */
  //postavljanje prioriteta ovog interapta
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}



i samo hendlanje interapta
Code:

void EXTI0_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  {
    // ovde uradi nesto
    
    /* Clear the EXTI line 0 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line0);
  }
}


Bitno:
Code:

          External interrupt/event lines are mapped as following:
            1- All available GPIO pins are connected to the 16 external 
               interrupt/event lines from EXTI0 to EXTI15.
            2- EXTI line 16 is connected to the PVD Output
            3- EXTI line 17 is connected to the RTC Alarm event
            4- EXTI line 18 is connected to the USB OTG FS Wakeup from suspend event
            5- EXTI line 19 is connected to the Ethernet Wakeup event
            6- EXTI line 20 is connected to the USB OTG HS (configured in FS) Wakeup event 
            7- EXTI line 21 is connected to the RTC Tamper and Time Stamp events
            8- EXTI line 22 is connected to the RTC Wakeup event
        
            
          In order to use an I/O pin as an external interrupt source, follow steps below:
            1- Configure the I/O in input mode using GPIO_Init()
            2- Select the input source pin for the EXTI line using SYSCFG_EXTILineConfig()
            3- Select the mode(interrupt, event) and configure the trigger 
               selection (Rising, falling or both) using EXTI_Init()
            4- Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init()
   
  @note  SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
         registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);          



E sad, znam da ima dosta pitanja, veliki broj odgovora je ovde: http://www.embedds.com/stm32-interrupts-and-programming-with-gcc/

(slicna/ista je prica i za M4)
Citat:

ARM Cortex-M3 microcontrollers may have up to 256 interrupts sources. First 15 interrupt sources are called system exceptions. These exceptions rise within Cortex core like reset, NMI, hard fault and error, debug and SystTick timer interrupt. In the exception table they start from address 0×00000004 and are numbered from 1 to 15. There is no 0 number exception (FYI – the very top of exception table address is used to store starting point of stack pointer)



inace, pitanje "zasto se fnkcija zove bas tako", fora je sto biblioteka odradi sve oko setovanja vektora tako da postoji stm32f4xx_it.c u kome su prazne funkcije za sve interapte i onda samo unutra ubacis svoj kod ...


 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: STM32F4 - Interrupt-i19.03.2012. u 21:37 - pre 147 meseci
btw ako pogledas startup_stm32f4xx.s nacices u startu definisanu vektor listu za sve interapte

Code:

/******************************************************************************
*
* The minimal vector table for a Cortex M3. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.

*******************************************************************************/
   .section  .isr_vector,"a",%progbits
  .type  g_pfnVectors, %object
  .size  g_pfnVectors, .-g_pfnVectors
    
    
g_pfnVectors:
  .word  _estack
  .word  Reset_Handler
  .word  NMI_Handler
  .word  HardFault_Handler
  .word  MemManage_Handler
  .word  BusFault_Handler
  .word  UsageFault_Handler
  .word  0
  .word  0
  .word  0
  .word  0
  .word  SVC_Handler
  .word  DebugMon_Handler
  .word  0
  .word  PendSV_Handler
  .word  SysTick_Handler
  
  /* External Interrupts */
  .word     WWDG_IRQHandler                   /* Window WatchDog              */                                        
  .word     PVD_IRQHandler                    /* PVD through EXTI Line detection */                        
  .word     TAMP_STAMP_IRQHandler             /* Tamper and TimeStamps through the EXTI line */            
  .word     RTC_WKUP_IRQHandler               /* RTC Wakeup through the EXTI line */                      
  .word     FLASH_IRQHandler                  /* FLASH                        */                                          
  .word     RCC_IRQHandler                    /* RCC                          */                                            
  .word     EXTI0_IRQHandler                  /* EXTI Line0                   */                        
  .word     EXTI1_IRQHandler                  /* EXTI Line1                   */                          
  .word     EXTI2_IRQHandler                  /* EXTI Line2                   */                          
  .word     EXTI3_IRQHandler                  /* EXTI Line3                   */                          
  .word     EXTI4_IRQHandler                  /* EXTI Line4                   */                          
  .word     DMA1_Stream0_IRQHandler           /* DMA1 Stream 0                */                  
  .word     DMA1_Stream1_IRQHandler           /* DMA1 Stream 1                */                   
  .word     DMA1_Stream2_IRQHandler           /* DMA1 Stream 2                */                   
  .word     DMA1_Stream3_IRQHandler           /* DMA1 Stream 3                */                   
  .word     DMA1_Stream4_IRQHandler           /* DMA1 Stream 4                */                   
  .word     DMA1_Stream5_IRQHandler           /* DMA1 Stream 5                */                   
  .word     DMA1_Stream6_IRQHandler           /* DMA1 Stream 6                */                   
  .word     ADC_IRQHandler                    /* ADC1, ADC2 and ADC3s         */                   
  .word     CAN1_TX_IRQHandler                /* CAN1 TX                      */                         
  .word     CAN1_RX0_IRQHandler               /* CAN1 RX0                     */                          
  .word     CAN1_RX1_IRQHandler               /* CAN1 RX1                     */                          
  .word     CAN1_SCE_IRQHandler               /* CAN1 SCE                     */                          
  .word     EXTI9_5_IRQHandler                /* External Line[9:5]s          */                          
  .word     TIM1_BRK_TIM9_IRQHandler          /* TIM1 Break and TIM9          */         
  .word     TIM1_UP_TIM10_IRQHandler          /* TIM1 Update and TIM10        */         
  .word     TIM1_TRG_COM_TIM11_IRQHandler     /* TIM1 Trigger and Commutation and TIM11 */
  .word     TIM1_CC_IRQHandler                /* TIM1 Capture Compare         */                          
  .word     TIM2_IRQHandler                   /* TIM2                         */                   
  .word     TIM3_IRQHandler                   /* TIM3                         */                   
  .word     TIM4_IRQHandler                   /* TIM4                         */                   
  .word     I2C1_EV_IRQHandler                /* I2C1 Event                   */                          
  .word     I2C1_ER_IRQHandler                /* I2C1 Error                   */                          
  .word     I2C2_EV_IRQHandler                /* I2C2 Event                   */                          
  .word     I2C2_ER_IRQHandler                /* I2C2 Error                   */                            
  .word     SPI1_IRQHandler                   /* SPI1                         */                   
  .word     SPI2_IRQHandler                   /* SPI2                         */                   
  .word     USART1_IRQHandler                 /* USART1                       */                   
  .word     USART2_IRQHandler                 /* USART2                       */                   
  .word     USART3_IRQHandler                 /* USART3                       */                   
  .word     EXTI15_10_IRQHandler              /* External Line[15:10]s        */                          
  .word     RTC_Alarm_IRQHandler              /* RTC Alarm (A and B) through EXTI Line */                 
  .word     OTG_FS_WKUP_IRQHandler            /* USB OTG FS Wakeup through EXTI line */                       
  .word     TIM8_BRK_TIM12_IRQHandler         /* TIM8 Break and TIM12         */         
  .word     TIM8_UP_TIM13_IRQHandler          /* TIM8 Update and TIM13        */         
  .word     TIM8_TRG_COM_TIM14_IRQHandler     /* TIM8 Trigger and Commutation and TIM14 */
  .word     TIM8_CC_IRQHandler                /* TIM8 Capture Compare         */                          
  .word     DMA1_Stream7_IRQHandler           /* DMA1 Stream7                 */                          
  .word     FSMC_IRQHandler                   /* FSMC                         */                   
  .word     SDIO_IRQHandler                   /* SDIO                         */                   
  .word     TIM5_IRQHandler                   /* TIM5                         */                   
  .word     SPI3_IRQHandler                   /* SPI3                         */                   
  .word     UART4_IRQHandler                  /* UART4                        */                   
  .word     UART5_IRQHandler                  /* UART5                        */                   
  .word     TIM6_DAC_IRQHandler               /* TIM6 and DAC1&2 underrun errors */                   
  .word     TIM7_IRQHandler                   /* TIM7                         */
  .word     DMA2_Stream0_IRQHandler           /* DMA2 Stream 0                */                   
  .word     DMA2_Stream1_IRQHandler           /* DMA2 Stream 1                */                   
  .word     DMA2_Stream2_IRQHandler           /* DMA2 Stream 2                */                   
  .word     DMA2_Stream3_IRQHandler           /* DMA2 Stream 3                */                   
  .word     DMA2_Stream4_IRQHandler           /* DMA2 Stream 4                */                   
  .word     ETH_IRQHandler                    /* Ethernet                     */                   
  .word     ETH_WKUP_IRQHandler               /* Ethernet Wakeup through EXTI line */                     
  .word     CAN2_TX_IRQHandler                /* CAN2 TX                      */                          
  .word     CAN2_RX0_IRQHandler               /* CAN2 RX0                     */                          
  .word     CAN2_RX1_IRQHandler               /* CAN2 RX1                     */                          
  .word     CAN2_SCE_IRQHandler               /* CAN2 SCE                     */                          
  .word     OTG_FS_IRQHandler                 /* USB OTG FS                   */                   
  .word     DMA2_Stream5_IRQHandler           /* DMA2 Stream 5                */                   
  .word     DMA2_Stream6_IRQHandler           /* DMA2 Stream 6                */                   
  .word     DMA2_Stream7_IRQHandler           /* DMA2 Stream 7                */                   
  .word     USART6_IRQHandler                 /* USART6                       */                    
  .word     I2C3_EV_IRQHandler                /* I2C3 event                   */                          
  .word     I2C3_ER_IRQHandler                /* I2C3 error                   */                          
  .word     OTG_HS_EP1_OUT_IRQHandler         /* USB OTG HS End Point 1 Out   */                   
  .word     OTG_HS_EP1_IN_IRQHandler          /* USB OTG HS End Point 1 In    */                   
  .word     OTG_HS_WKUP_IRQHandler            /* USB OTG HS Wakeup through EXTI */                         
  .word     OTG_HS_IRQHandler                 /* USB OTG HS                   */                   
  .word     DCMI_IRQHandler                   /* DCMI                         */                   
  .word     CRYP_IRQHandler                   /* CRYP crypto                  */                   
  .word     HASH_RNG_IRQHandler               /* Hash and Rng                 */
  .word     FPU_IRQHandler                    /* FPU  */


 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: STM32F4 - Interrupt-i19.03.2012. u 21:42 - pre 147 meseci
btw iako pise u komentaru "cortex m3" - ovo je tabela za cortex m4 (nije da se nesto znacajno razlikuje :D )
 
Odgovor na temu

zivadin_despot
Živadin Despotović
Novi Sad

Član broj: 175438
Poruke: 704
*.dynamic.isp.telekom.rs.



+5 Profil

icon Re: STM32F4 - Interrupt-i19.03.2012. u 21:57 - pre 147 meseci
Evo uspeo sam... Sad sam video poruku, a snasao sam se pomocu coocox-a...:D
Tamo otvorio projekat sa stm32f1 serijom i ukljucio exti biblioteku...super je sto imaju primer dobro komentarisan, pa sam odande pokupio...
Tvojim komentarima sam shvatio kako nesto radi i to je to... Kako budem dalje radio, javljam se sa pitanjima:D
evo i koda koji mi radi

Code:

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_syscfg.h"
#include "misc.h"

unsigned char flag;

int main()
{

        RCC->CR=0x01010000; //ukljucen HSE i PLL
        RCC->PLLCFGR=0x00030000; //PLL je 8
        RCC->AHB1ENR=0x00000009; //ukljucen takt na portu D i A

        flag=1;

        GPIOD->MODER=0x55555555; //sci su izlazni
        GPIOD->OTYPER=0x00000000; //svi su push-pull
        GPIOD->OSPEEDR=0x00000000; //port sa jezgro mkomunicira na 2MHz (low speed)
        GPIOD->PUPDR=0x00000000; //imaju pull-down no pull up
        GPIOD->ODR=0xFFFF; //pripremljeno stanje porta D
        GPIOD->BSRRH=0xFFFF; //ugasen port D

        GPIO_InitTypeDef port;
        port.GPIO_Mode=GPIO_Mode_IN;
        port.GPIO_OType=GPIO_OType_PP;
        port.GPIO_Pin=GPIO_PinSource0;
        port.GPIO_PuPd=GPIO_PuPd_NOPULL;
        port.GPIO_Speed=GPIO_Speed_25MHz;
        GPIO_Init(GPIOA,&port);

        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);

        EXTI_InitTypeDef interapt;
        interapt.EXTI_Line=EXTI_Line0;
        interapt.EXTI_Mode = EXTI_Mode_Interrupt;
        interapt.EXTI_Trigger =EXTI_Trigger_Rising;
        interapt.EXTI_LineCmd = ENABLE;
        EXTI_Init(&interapt);

        NVIC_InitTypeDef Nvic;
        Nvic.NVIC_IRQChannel = EXTI0_IRQn ; //interapt sa linije 0
        Nvic.NVIC_IRQChannelPreemptionPriority = 0x0F;
        Nvic.NVIC_IRQChannelSubPriority = 0x0F;
        Nvic.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&Nvic);

    while(1)
    {

    }
}

void EXTI0_IRQHandler()  //prekidna funkcija
{
    if(EXTI_GetFlagStatus(EXTI_Line0))
    {
        switch(flag)
        {
        case 1: GPIOD->BSRRL=0xFFFF; flag=2; break;
        case 2: GPIOD->BSRRH=0xFFFF; flag=1; break;
        }
        EXTI_ClearFlag(EXTI_Line0);
    }
}


pozdrav
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.31.24.217.adsl2.beograd.com.

Sajt: mysql.rs


+2377 Profil

icon Re: STM32F4 - Interrupt-i19.03.2012. u 22:01 - pre 147 meseci
coocox je majka, na zalost nikako da izadje ta verzija za M4 ... ocekuje se svaki dan :)
 
Odgovor na temu

zivadin_despot
Živadin Despotović
Novi Sad

Član broj: 175438
Poruke: 704
*.dynamic.isp.telekom.rs.



+5 Profil

icon Re: STM32F4 - Interrupt-i19.03.2012. u 23:51 - pre 147 meseci
Svidja mi se sto ima konkretne primere skoro za svaku biblioteku, i tacno vidis kako se primenjuje (odlican za pocetnike poput mene)...
Usput da pitam da li mozda postoji neki simulacioni software, poput Isis Proteusa, ali za ovaj nas? plasim se da je odgovor ne, al' ajde da pitam...:)
 
Odgovor na temu

bogdan.kecman
Bogdan Kecman
"specialist"
Oracle
srbistan

Član broj: 201406
Poruke: 15887
*.com
Via: [es] mailing liste

Sajt: mysql.rs


+2377 Profil

icon Re: STM32F4 - Interrupt-i20.03.2012. u 01:04 - pre 147 meseci
da + se lako dele primeri, na samom coocox-u ima 3-4 moja primera npr :D

sto se tice simulatora, ima nekoliko, naki su cak i open source, na zalost, nisu lepo upakovani kao proteus (a nijedan nisam ni probao da koristim)
 
Odgovor na temu

[es] :: Elektronika :: Mikrokontroleri :: STM32F4 - Interrupt-i

[ Pregleda: 2743 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.