Atmel AVR » Historique » Version 28
Patrice Nadeau, 2025-08-10 08:41
1 | 1 | Patrice Nadeau | # Atmel AVR |
---|---|---|---|
2 | |||
3 | Particularités pour les microcontrôleurs 8 bits AVR d’Atmel. |
||
4 | |||
5 | 2 | Patrice Nadeau | ## Règles |
6 | 14 | Patrice Nadeau | 1. Macros définis dans le fichier `config.h` |
7 | 12 | Patrice Nadeau | 1. `F_CPU` : La fréquence utilisée par l’horloge (interne ou externe) du microcontrôleur, en Hz |
8 | 2 | Patrice Nadeau | |
9 | > Les « fuses » doivent correspondent à la bonne source de l’horloge. |
||
10 | 12 | Patrice Nadeau | 1. De nouveau type d’entier sont fournis avec la librairie `stdint.h`. L’utilisation de ces types DOIT être utilisé afin d’exprimer le nombre de bit d’un objet. |
11 | 2 | Patrice Nadeau | 1. Progmem : Pour mettre des variables en lecture seule dans la section FLASH au lieu de SRAM. |
12 | 15 | Patrice Nadeau | 1. Inclue la librairie `avr/pgmspace.h` |
13 | 12 | Patrice Nadeau | 1. Le nom de la variable DOIT être suivie de **_P** |
14 | 2 | Patrice Nadeau | 1. Utiliser les macros de la librairie pour accéder à ces variables |
15 | 17 | Patrice Nadeau | 1. Fonction `main` |
16 | 27 | Patrice Nadeau | > * [AVR035 : Efficient C Coding for AVR6](https://ww1.microchip.com/downloads/en/AppNotes/doc1497.pdf) |
17 | 26 | Patrice Nadeau | > <https://gcc.gnu.org/onlinedocs/gcc/AVR-Function-Attributes.html> |
18 | 27 | Patrice Nadeau | * Déclarer la fonction avec le type `void` et l’attribut `OS_main` |
19 | * Utiliser une boucle sans fin `for (;;)` |
||
20 | 12 | Patrice Nadeau | 1. Opérations atomiques (opérations ne devant pas être interrompus) |
21 | 2 | Patrice Nadeau | 1. Inclure la librairie `util/atomic.h` |
22 | 1 | Patrice Nadeau | 1. Insérer les instructions dans une section `ATOMIC_BLOCK` |
23 | 6. Interruptions |
||
24 | 12 | Patrice Nadeau | 1. TODO |
25 | 1 | Patrice Nadeau | |
26 | 12 | Patrice Nadeau | ## Exemple |
27 | 1 | Patrice Nadeau | ```c |
28 | 21 | Patrice Nadeau | #if !defined (__AVR_ATmega48__) || (__AVR_ATmega48P__) |
29 | #warning "Cette librairie n'as pas été testée sur cette famille de microcontrôleur." |
||
30 | 1 | Patrice Nadeau | #endif |
31 | |||
32 | 7 | Patrice Nadeau | #include <avr/io.h> |
33 | 1 | Patrice Nadeau | #include <avr/pgmspace.h> |
34 | 8 | Patrice Nadeau | #include <util/atomic.h> |
35 | |||
36 | 1 | Patrice Nadeau | ... |
37 | /** @brief Variable en FLASH */ |
||
38 | 23 | Patrice Nadeau | char my_string[] PROGMEM = "POWER"; |
39 | 8 | Patrice Nadeau | |
40 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { |
||
41 | ... |
||
42 | } |
||
43 | 1 | Patrice Nadeau | |
44 | |||
45 | /** |
||
46 | * @brief Never ending loop |
||
47 | */ |
||
48 | 25 | Patrice Nadeau | void main(void) __attribute__ ((OS_main)); |
49 | 1 | Patrice Nadeau | |
50 | /* main function definition */ |
||
51 | 28 | Patrice Nadeau | void main(void) |
52 | { |
||
53 | 1 | Patrice Nadeau | ... |
54 | 19 | Patrice Nadeau | /* Boucle sans fin */ |
55 | 1 | Patrice Nadeau | for (;;) { |
56 | }; |
||
57 | }; |
||
58 | ``` |
||
59 | 11 | Patrice Nadeau | |
60 | ## Justifications |
||
61 | 22 | Patrice Nadeau | * [Atmel AVR4027 : Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers](https://ww1.microchip.com/downloads/en/AppNotes/doc8453.pdf) |
62 | 27 | Patrice Nadeau | |
63 | 11 | Patrice Nadeau | * [Vérification du modèle de microcontrôleur via l’option -m de gcc](https://github.com/embecosm/avr-gcc/blob/avr-gcc-mainline/gcc/config/avr/avr-mcus.def) |