IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

Simple Clignotement Led avec interruptions sur nucléo F072RB avec STCubeIde


Sujet :

C

  1. #1
    Membre averti
    Homme Profil pro
    A la retraite...
    Inscrit en
    Janvier 2012
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : A la retraite...
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2012
    Messages : 49
    Par défaut Simple Clignotement Led avec interruptions sur nucléo F072RB avec STCubeIde
    Bonjour à tous,

    J'essai de bidouiller avec STCubeIde pour faire clignoter la led intégrée sur PA5 avec les interruptions. Lorsque je complile le programme , j'ai une erreur de déclaration du TIMER 2;

    Voilà le code et en dessous le rapport d'erreur... j'ai beau fouiller , je ne sais pas pourquoi ? C'est la ligne soulignée qui pose problème...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    #include "main.h"
    
    // Variables globales
    volatile uint8_t led_state = 0;
    
    TIM_HandleTypeDef htim2;
    
    
    void SystemClock_Config(void);
    static void MX_GPIO_Init(void);
    static void MX_TIM2_Init(void);
    
    int main(void)
    {
    
        HAL_TIM_Base_Start_IT(&htim2);
    
        HAL_Init();
      SystemClock_Config();
      MX_GPIO_Init();
      MX_TIM2_Init();
    
      // Démarrage du timer en mode interruption
    
      while (1)
      {
        // Boucle principale vide, tout est géré par les interruptions
      }
    }
    
    void SystemClock_Config(void)
    {
      // Configuration de l'horloge système
      // Générée par STM32CubeMX
    }
    
    static void MX_GPIO_Init(void)
    {
      GPIO_InitTypeDef GPIO_InitStruct = {0};
    
      // Activation des horloges GPIO
      __HAL_RCC_GPIOA_CLK_ENABLE();
    
      // Configuration de PA5 en sortie pour la LED
      GPIO_InitStruct.Pin = GPIO_PIN_5;
      GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
    }
    
    static void MX_TIM2_Init(void)
    {
      TIM_ClockConfigTypeDef sClockSourceConfig = {0};
      TIM_MasterConfigTypeDef sMasterConfig = {0};
    
      htim2.Instance = TIM2;
      htim2.Init.Prescaler = 7999;
      htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
      htim2.Init.Period = 9999;
      htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
      htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
      if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
      {
        Error_Handler();
      }
      sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
      if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
      {
        Error_Handler();
      }
      sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
      sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
      if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
      {
        Error_Handler();
      }
    }
    
    // Gestionnaire d'interruption du timer
    void TIM2_IRQHandler(void)
    {
      HAL_TIM_IRQHandler(&htim2);
    }
    
    void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
    {
      if (htim->Instance == TIM2)
      {
        // Inversion de l'état de la LED
        led_state = !led_state;
        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, led_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
      }
    }

    RAPPORT D'ERREUR

    Code Shell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    11:33:02 **** Incremental Build of configuration Debug for project led_clignot_1s_interrupt ****
    make -j6 all 
    arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F072xB -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/main.o"
    arm-none-eabi-gcc "../Core/Src/stm32f0xx_it.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F072xB -c -I../Core/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc -I../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/stm32f0xx_it.d" -MT"Core/Src/stm32f0xx_it.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Core/Src/stm32f0xx_it.o"
    ../Core/Src/main.c:6:1: error: unknown type name 'TIM_HandleTypeDef'; did you mean 'I2C_HandleTypeDef'?
        6 | TIM_HandleTypeDef htim2;
          | ^~~~~~~~~~~~~~~~~
          | I2C_HandleTypeDef
    ../Core/Src/stm32f0xx_it.c: In function 'TIM2_IRQHandler':
    ../Core/Src/stm32f0xx_it.c:28:5: warning: implicit declaration of function 'HAL_TIM_IRQHandler'; did you mean 'HAL_DMA_IRQHandler'? [-Wimplicit-function-declaration]
       28 |     HAL_TIM_IRQHandler(&htim2);
          |     ^~~~~~~~~~~~~~~~~~
          |     HAL_DMA_IRQHandler
    ../Core/Src/stm32f0xx_it.c:28:25: error: 'htim2' undeclared (first use in this function)
       28 |     HAL_TIM_IRQHandler(&htim2);
          |                         ^~~~~
    ../Core/Src/stm32f0xx_it.c:28:25: note: each undeclared identifier is reported only once for each function it appears in
    make: *** [Core/Src/subdir.mk:34: Core/Src/stm32f0xx_it.o] Error 1
    make: *** Waiting for unfinished jobs....
    ../Core/Src/main.c: In function 'main':
    ../Core/Src/main.c:16:9: warning: implicit declaration of function 'HAL_TIM_Base_Start_IT'; did you mean 'HAL_DMA_Start_IT'? [-Wimplicit-function-declaration]
       16 |         HAL_TIM_Base_Start_IT(&htim2);
          |         ^~~~~~~~~~~~~~~~~~~~~
          |         HAL_DMA_Start_IT
    ../Core/Src/main.c: In function 'MX_TIM2_Init':
    ../Core/Src/main.c:54:3: error: unknown type name 'TIM_ClockConfigTypeDef'; did you mean 'EXTI_ConfigTypeDef'?
       54 |   TIM_ClockConfigTypeDef sClockSourceConfig = {0};
          |   ^~~~~~~~~~~~~~~~~~~~~~
          |   EXTI_ConfigTypeDef
    ../Core/Src/main.c:55:3: error: unknown type name 'TIM_MasterConfigTypeDef'
       55 |   TIM_MasterConfigTypeDef sMasterConfig = {0};
          |   ^~~~~~~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:57:8: error: request for member 'Instance' in something not a structure or union
       57 |   htim2.Instance = TIM2;
          |        ^
    ../Core/Src/main.c:58:8: error: request for member 'Init' in something not a structure or union
       58 |   htim2.Init.Prescaler = 7999;
          |        ^
    ../Core/Src/main.c:59:8: error: request for member 'Init' in something not a structure or union
       59 |   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
          |        ^
    ../Core/Src/main.c:59:28: error: 'TIM_COUNTERMODE_UP' undeclared (first use in this function)
       59 |   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
          |                            ^~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:59:28: note: each undeclared identifier is reported only once for each function it appears in
    ../Core/Src/main.c:60:8: error: request for member 'Init' in something not a structure or union
       60 |   htim2.Init.Period = 9999;
          |        ^
    ../Core/Src/main.c:61:8: error: request for member 'Init' in something not a structure or union
       61 |   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
          |        ^
    ../Core/Src/main.c:61:30: error: 'TIM_CLOCKDIVISION_DIV1' undeclared (first use in this function)
       61 |   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
          |                              ^~~~~~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:62:8: error: request for member 'Init' in something not a structure or union
       62 |   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
          |        ^
    ../Core/Src/main.c:62:34: error: 'TIM_AUTORELOAD_PRELOAD_DISABLE' undeclared (first use in this function)
       62 |   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
          |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:63:7: warning: implicit declaration of function 'HAL_TIM_Base_Init' [-Wimplicit-function-declaration]
       63 |   if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
          |       ^~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:67:21: error: request for member 'ClockSource' in something not a structure or union
       67 |   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
          |                     ^
    ../Core/Src/main.c:67:36: error: 'TIM_CLOCKSOURCE_INTERNAL' undeclared (first use in this function)
       67 |   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
          |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:68:7: warning: implicit declaration of function 'HAL_TIM_ConfigClockSource' [-Wimplicit-function-declaration]
       68 |   if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
          |       ^~~~~~~~~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:72:16: error: request for member 'MasterOutputTrigger' in something not a structure or union
       72 |   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
          |                ^
    ../Core/Src/main.c:72:39: error: 'TIM_TRGO_RESET' undeclared (first use in this function)
       72 |   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
          |                                       ^~~~~~~~~~~~~~
    ../Core/Src/main.c:73:16: error: request for member 'MasterSlaveMode' in something not a structure or union
       73 |   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
          |                ^
    ../Core/Src/main.c:73:35: error: 'TIM_MASTERSLAVEMODE_DISABLE' undeclared (first use in this function)
       73 |   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
          |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../Core/Src/main.c:74:7: warning: implicit declaration of function 'HAL_TIMEx_MasterConfigSynchronization'; did you mean 'HAL_TIM_SlaveConfigSynchronization'? [-Wimplicit-function-declaration]
       74 |   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
          |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |       HAL_TIM_SlaveConfigSynchronization
    ../Core/Src/main.c: In function 'TIM2_IRQHandler':
    ../Core/Src/main.c:83:3: warning: implicit declaration of function 'HAL_TIM_IRQHandler'; did you mean 'HAL_DMA_IRQHandler'? [-Wimplicit-function-declaration]
       83 |   HAL_TIM_IRQHandler(&htim2);
          |   ^~~~~~~~~~~~~~~~~~
          |   HAL_DMA_IRQHandler
    ../Core/Src/main.c: At top level:
    ../Core/Src/main.c:86:36: error: unknown type name 'TIM_HandleTypeDef'; did you mean 'I2C_HandleTypeDef'?
       86 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
          |                                    ^~~~~~~~~~~~~~~~~
          |                                    I2C_HandleTypeDef
    make: *** [Core/Src/subdir.mk:34: Core/Src/main.o] Error 1
    "make -j6 all" terminated with exit code 2. Build might be incomplete.
     
    11:33:03 Build Failed. 23 errors, 6 warnings. (took 995ms)

  2. #2
    Modérateur
    Avatar de Obsidian
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Septembre 2007
    Messages
    7 442
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2007
    Messages : 7 442
    Par défaut
    Cela a l'air d'être une erreur courante :

    https://community.st.com/t5/stm32cub...2c/td-p/226053

    Sans connaître la plateforme, je t'aurais d'abord suggéré d'ajouter le bon header, donc ici peut-être stm32h7xx_hal.h si main.h ne le fait pas lui-même. Mais le message en lien ci-dessus met le doigt dessus : il y a un flag sous forme de macro #define à passer pour que le sous-ensemble concerné de l'API soit inclus.

    Seems like the timer was not active when you generated the CubeMX code and you added it afterwards.
    Donc soit tu ajoutes #define HAL_TIM_MODULE_ENABLED en tout début de programme, soit tu regénères proprement ton projet avec CubeMX en sélectionnant les bonnes options.

  3. #3
    Membre averti
    Homme Profil pro
    A la retraite...
    Inscrit en
    Janvier 2012
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : A la retraite...
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2012
    Messages : 49
    Par défaut
    Bonjour,

    Merci pour votre réponse et je suis désolé pour le temps de retour.

    Effectivement en reprenant la configuration dans Stcube, il n'y a plus d'erreur et ça fonctionne.

    Il n'y a rien de plus frustrant que de tenter de faire fonctionner un "truc" de base et de ne pas y arriver ... J'étais curieux de voir le fonctionement de StCubeIde. C'est vrai que c'est pas mal fait mais il faut déjà avoir de bonnes bases en C et C++ pour titiller les registres et le reste..

    Mais merci du retour...

    Georges

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Clignotement LEDs avec millis
    Par dabigben dans le forum Arduino
    Réponses: 2
    Dernier message: 03/05/2024, 09h50
  2. [Python 3.X] Ouverture d'une simple fenêtre Tkinter avec Pyzo sur Mac
    Par Leila_A dans le forum Tkinter
    Réponses: 4
    Dernier message: 13/02/2015, 07h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo