Différences entre versions de « Pololu-Romi-32U4-Programmer-AVRDUDE »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 28 : Ligne 28 :
 
<syntaxhighlight lang="C">
 
<syntaxhighlight lang="C">
 
#define F_CPU 16000000
 
#define F_CPU 16000000
#include <avr/io.h>
+
#include &lt;avr/io.h&gt;
#include <util/delay.h>
+
#include &lt;util/delay.h&gt;
 
   
 
   
 
int main()
 
int main()

Version du 11 décembre 2019 à 20:05

Cette section explique comment programmer la famille des carte 32U4 de Pololu avec la chaîne de compilation avr-gcc et AVRDUDE. Cette section est destiné au utilisateurs avancés qui ne veulent pas utiliser Arduino IDE domme décrit dans la section précédente.

Prérequis

Si vous utilisez Windows, Pololu recommande de télécharger WinAVR, qui contient la chaîne de compilation avr-gcc et un outil en ligne de commande appelé AVRDUDE qui est utiisé pour téléverser le programme via le bootloader de l'A-Star. Si la version GNU Make de WinAVR crash sur votre ordinateur alors vous pouvez opter pour version la version GNU Make de Pololu.

Si vous utilisez Mac OS X, Pololu recommande de télécharger le CrossPack pour développement AVR.

Si vous utilisez Linux, vous aurez besoin d'installer avr-gcc, avr-libc et AVRDUDE. Les utilisateur d'Ubuntu peuvent obtenir les logiciels nécessaires à l'aide de:

sudo apt-get install gcc-avr avr-libc avrdude

Après avoir installé les pré-requis, ouvrez une invite de commande et essayez les commandes suivantes pour vous assurer que tous les utilitaires nécessaires soient bien disponibles

avr-gcc -v
avr-objcopy -V
make -v
avrdude

Si une quelconque commande échoue alors assurez vous que les exécutables nécessaires sur votre ordinateur et assurez vous que leurs répertoires soient bien mentionnés dans la variable d'environnement PATH.

Compiler un programme d'exemple

Copy the following code to a file named “main.c”:

<syntaxhighlight lang="C">

  1. define F_CPU 16000000
  2. include <avr/io.h>
  3. include <util/delay.h>

int main() {

 DDRC |= (1 << DDC7);    // Make pin 13 be an output.  
 while(1)
 {
   PORTC |= (1 << PORTC7);   // Turn the LED on.
   _delay_ms(500);
   PORTC &= ~(1 << PORTC7);  // Turn the LED off.
   _delay_ms(500);
 }

} </<syntaxhighlight>

In the same folder, create a file named “Makefile” with the following contents:

PORT=\\\\.\\USBSER000
MCU=atmega32u4
CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) -Os
LDFLAGS=-Wl,-gc-sections -Wl,-relax
CC=avr-gcc
TARGET=main
OBJECT_FILES=main.o

all: $(TARGET).hex

clean:
	rm -f *.o *.hex *.obj *.hex

%.hex: %.obj
	avr-objcopy -R .eeprom -O ihex $< $@

%.obj: $(OBJECT_FILES)
	$(CC) $(CFLAGS) $(OBJECT_FILES) $(LDFLAGS) -o $@

program: $(TARGET).hex
	avrdude -p $(MCU) -c avr109 -P $(PORT) -U flash:w:$(TARGET).hex

Make sure that the PORT variable in the Makefile is set to the name of the device’s virtual serial port. In Windows, \\\\.\\USBSER000 should work if the A-Star is the only USB device connected that is using the usbser.sys driver, but you can change it to be the actual name of the COM port (e.g. COM13).

In a command prompt, navigate to the directory with the Makefile and main.c. If you run the command make, the code should get compiled and produce a file named “main.hex”.

Programmer

To program the A-Star device, you will need to get it into bootloader mode first. One way to do this is to reset the AVR twice within 750 ms. Most of the boards in our 32U4 family have a reset button that can be used to reset the board. On any of our 32U4 family of boards, a pushbutton can be connected between the GND and RST pins to serve as a reset button, or you can use a wire. Once the device is in bootloader mode, quickly run the command make program to program it. If you wait longer than 8 seconds, the A-Star bootloader will exit and the AVR will go back to running the user program.


Basé sur "Guide utilisateur de la carte de contrôle Romi 32U4" de Pololu (https://www.pololu.com/docs/0J69) - Traduit en Français par shop.mchobby.be CC-BY-SA pour la traduction
Toute copie doit contenir ce crédit, lien vers cette page et la section "crédit de traduction". Traduit avec l'autorisation expresse de Pololu (www.pololu.com)

Based on "Pololu Romi 32U4 Control Board User’s Guide" from Pololu (https://www.pololu.com/docs/0J69) - Translated to French by shop.mchobby.be CC-BY-SA for the translation
Copies must includes this credit, link to this page and the section "crédit de traduction" (translation credit). Translated with the Pololu's authorization (www.pololu.com)