Modifications

Sauter à la navigation Sauter à la recherche
780 octets ajoutés ,  19 avril 2015 à 09:47
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{MicroPython-Hack-Prepare-NAV}}
 
{{MicroPython-Hack-Prepare-NAV}}
  −
{{traduction}}
      
== introduction ==
 
== introduction ==
{{bloc-etroit|text=Here you will learn how to write inline assembler in Micro Python.
+
{{bloc-etroit|text=Dans ce tutoriel, vous allez apprendre comment écrire de l'assembleur (''inline assembler'') en Micro Python.
   −
Note: this is an advanced tutorial, intended for those who already know a bit about microcontrollers and assembly language.
+
{{ambox|text=Il s'agit d'un tutoriel avancé destiné à ceux qui connaissent déjà un peu les microcontroleur et le langage assembleur.}}
   −
Micro Python includes an inline assembler. It allows you to write assembly routines as a Python function, and you can call them as you would a normal Python function.}}
+
Micro Python inclus un assembleur inline. Il vous permettra d'écrire des routines assembleur comme si c'était des fonctions micro python, et vous pouvez l'appeler comme si cela était des fonction Python normale.}}
    
== Retourner une valeur ==
 
== Retourner une valeur ==
{{bloc-etroit|text=Inline assembler functions are denoted by a special function decorator. Let’s start with the simplest example:
+
{{bloc-etroit|text=Les fonctions assembleur Inline sont annotées avec une fonction de décoration spéciale. Commençons par l'exemple le plus simple:
    
  <nowiki>@micropython.asm_thumb
 
  <nowiki>@micropython.asm_thumb
Ligne 17 : Ligne 15 :  
     movw(r0, 42)</nowiki>
 
     movw(r0, 42)</nowiki>
   −
You can enter this in a script or at the REPL. This function takes no arguments and returns the number 42. {{fname|r0}} is a register, and the value in this register when the function returns is the value that is returned. Micro Python always interprets the {{fname|r0}} as an integer, and converts it to an integer object for the caller.
+
Vous pouvez placer de code dans un script ou le taper sur une invite REPL. Cette fonction ne prend aucun argument et retourne le nombre 42. {{fname|r0}} est un registre, et la valeur dans ce registre lorsque la fonction se termine, est la valeur qui est retournée par la fonction.  
 +
 
 +
Micro Python interprète toujours {{fname|r0}} comme un entier (type {{fname|int}}) et converti cette valeur en objet {{fname|int}} (integer) pour la fonction appelante.
   −
If you run {{fname|print(fun())}} you will see it print out 42.}}
+
Si vous exécutez {{fname|print(fun())}} vous verrez apparaître la valeur 42.}}
    
== Accéder aux périphériques ==
 
== Accéder aux périphériques ==
For something a bit more complicated, let’s turn on an LED:
+
Pour un exemple un peu plus compliqué, essayons maintenant d'allumer une LED:
    
  <nowiki>@micropython.asm_thumb
 
  <nowiki>@micropython.asm_thumb
Ligne 30 : Ligne 30 :  
     strh(r1, [r0, stm.GPIO_BSRRL])</nowiki>
 
     strh(r1, [r0, stm.GPIO_BSRRL])</nowiki>
   −
This code uses a few new concepts:
+
Ce code utilise quelques nouveaux concepts:
   −
* {{fname|stm}} is a module which provides a set of constants for easy access to the registers of the pyboard’s microcontroller. Try running {{fname|import stm}} and then {{fname|help(stm)}} at the REPL. It will give you a list of all the available constants.
+
* {{fname|stm}} est un module qui offre un ensemble de constante pour facilement accéder plus facilement aux différents registres du microcontrôleur de la PyBoard. Essayer d'exécuter {{fname|import stm}} puis {{fname|help(stm)}} sur l'invite REPL. Cela vous fournira toutes les constantes disponibles.
* {{fname|stm.GPIOA}} is the address in memory of the GPIOA peripheral. On the pyboard, the red LED is on port A, pin PA13.
+
* {{fname|stm.GPIOA}} est l'adresse, en mémoire, du périphérique GPIOA. Sur la carte PyBoard, la LED rouge est sur le "port A", broche PA13.
* {{fname|movwt}} moves a 32-bit number into a register. It is a convenience function that turns into 2 thumb instructions: {{fname|movw}} followed by {{fname|movt}}. The {{fname|movt}} also shifts the immediate value right by 16 bits.
+
* {{fname|movwt}} déplace un nombre 32-bit dans un registre (un ''word''). C'est une fonction bien pratique qui exécute les deux fonctions basiques suivantes: {{fname|movw}} suivit de {{fname|movt}}. Le {{fname|movt}} décale (''shift'') la valeur de 16 bits (''à droite'').
* {{fname|strh}} stores a half-word (16 bits). The instruction above stores the lower 16-bits of {{fname|r1}} into the memory location {{fname|r0 + stm.GPIO_BSRRL}}. This has the effect of setting high all those pins on port A for which the corresponding bit in {{fname|r0}} is set. In our example above, the 13th bit in {{fname|r0}} is set, so PA13 is pulled high. This turns on the red LED.
+
* {{fname|strh}} stocke un ''half-word'' (16 bits, la moitier d'un ''Word''). L'instruction ci-avant stocke les 16-bits de poids faible de {{fname|r1}} à l'adresse mémoire {{fname|r0 + stm.GPIO_BSRRL}}. Cela à pour effet de placer toutes les broches du port A au niveau haut (HIGH) pour les bit correspondant activé dans le registre {{fname|r0}}. Dans l'exemple ci-dessus, le 13ieme bit dans {{fname|r0}} est activé, donc PA13 est placé au niveau haut (high) ce qui à pour effet d'allumer la LED rouge.
    
== Accepter des arguments ==
 
== Accepter des arguments ==
 +
Une fonction assembleur Inline peut accepter jusqu'à 3 arguments. Si ils sont utilisés, ces arguments doivent être nommés {{fname|r0}}, {{fname|r1}} et {{fname|r2}} pour refléter les registres et les conventions d'appel.
   −
Inline assembler functions can accept up to 3 arguments. If they are used, they must be named {{fname|r0}}, {{fname|r1}} et {{fname|r2}} to reflect the registers and the calling conventions.
+
Voici une fonction qui additionne ces arguments:
 
  −
Here is a function that adds its arguments:
      
  <nowiki>@micropython.asm_thumb
 
  <nowiki>@micropython.asm_thumb
Ligne 47 : Ligne 46 :  
     add(r0, r0, r1)</nowiki>
 
     add(r0, r0, r1)</nowiki>
   −
This performs the computation {{fname|r0 \= r0 + r1}}. Since the result is put in {{fname|r0}}, that is what is returned. Try {{fname|asm_add(1, 2)}}, it should return 3.
+
Cette fonction exécute le calcul {{fname|1=r0 = r0 + r1}}. Etant donné que le résultat est placé dans le registre {{fname|r0}}, ce sera donc la valeur qui sera retournée.  
 +
 
 +
Essayez la commande {{fname|asm_add(1, 2)}} qui devrait retourner la valeur 3.
    
== Les boucles ==
 
== Les boucles ==
We can assign labels with {{fname|label(my_label)}}, and branch to them using {{fname|b(my_label)}}, or a conditional branch like {{fname|bgt(my_label)}}.
+
Nous pouvons assigner un libellé (''label'' en anglais) a l'aide de {{fname|label(mon_label)}}, et faire sauter l'exécution du code vers l'étiquette (''to branch'' en anglais) en utilisant {{fname|b(mon_label)}}, ou un branchement conditionnel tel que {{fname|bgt(mon_label)}}.
   −
The following example flashes the green LED. It flashes it {{fname|r0}} times.
+
L'example de code suivant fait clignoter la LED vertes. La LED clignotera {{fname|r0}} fois.
    
  <nowiki>@micropython.asm_thumb
 
  <nowiki>@micropython.asm_thumb
 
def flash_led(r0):
 
def flash_led(r0):
     # get the GPIOA address in r1
+
     # placer l'adresse GPIOA dans r1
 
     movwt(r1, stm.GPIOA)
 
     movwt(r1, stm.GPIOA)
   −
     # get the bit mask for PA14 (the pin LED #2 is on)
+
     # obtenir un masque de bits pour PA14 (broche de la LED #2)
 
     movw(r2, 1 << 14)
 
     movw(r2, 1 << 14)
   Ligne 66 : Ligne 67 :  
     label(loop1)
 
     label(loop1)
   −
     # turn LED on
+
     # allumer la LED
 
     strh(r2, [r1, stm.GPIO_BSRRL])
 
     strh(r2, [r1, stm.GPIO_BSRRL])
   −
     # delay for a bit
+
     # attendre un moment
 
     movwt(r4, 5599900)
 
     movwt(r4, 5599900)
 
     label(delay_on)
 
     label(delay_on)
Ligne 76 : Ligne 77 :  
     bgt(delay_on)
 
     bgt(delay_on)
   −
     # turn LED off
+
     # éteindre la LED
 
     strh(r2, [r1, stm.GPIO_BSRRH])
 
     strh(r2, [r1, stm.GPIO_BSRRH])
   −
     # delay for a bit
+
     # Attendre un peu
 
     movwt(r4, 5599900)
 
     movwt(r4, 5599900)
 
     label(delay_off)
 
     label(delay_off)
Ligne 86 : Ligne 87 :  
     bgt(delay_off)
 
     bgt(delay_off)
   −
     # loop r0 times
+
     # boucler r0 fois
 
     sub(r0, r0, 1)
 
     sub(r0, r0, 1)
 
     label(loop_entry)
 
     label(loop_entry)
29 917

modifications

Menu de navigation