Modifications

Sauter à la navigation Sauter à la recherche
aucun résumé de modification
Ligne 2 : Ligne 2 :     
{{traduction}}
 
{{traduction}}
 +
 +
This section explains how to program our 32U4 family of boards using the avr-gcc toolchain and AVRDUDE. This section is intended for advanced users who do not want to use the Arduino IDE as described in the previous section.
 +
 +
== Prérequis ==
 +
If you are using Windows, we recommend downloading [http://winavr.sourceforge.net/ WinAVR], which contains the avr-gcc toolchain and a command-line utility called [http://www.nongnu.org/avrdude/ AVRDUDE] that can be used to upload programs to the A-Star bootloader. If the version of GNU Make that comes with WinAVR crashes on your computer, we recommend using the [https://github.com/pololu/make/releases Pololu version of GNU Make].
 +
 +
If you are using Mac OS X, we recommend downloading the [http://www.obdev.at/products/crosspack CrossPack for AVR Development].
 +
 +
If you are using Linux, you will need to install avr-gcc, avr-libc, and AVRDUDE. Ubuntu users can get the required software by running:
 +
 +
<nowiki>sudo apt-get install gcc-avr avr-libc avrdude</nowiki>
 +
 +
After you have installed the prerequisites, open a command prompt and try running these commands to make sure all the required utilities are available:
 +
 +
<nowiki>avr-gcc -v
 +
avr-objcopy -V
 +
make -v
 +
avrdude</nowiki>
 +
 +
If any of those commands fail, make sure the desired executable is installed on your computer and make sure that it is in a directory listed in your PATH environment variable.
 +
 +
== Compiler un programme d'exemple ==
 +
Copy the following code to a file named “main.c”:
 +
 +
<syntaxhighlight lang="C">
 +
#define F_CPU 16000000
 +
#include <avr/io.h>
 +
#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:
 +
 +
<nowiki>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</nowiki>
 +
 +
Make sure that the PORT variable in the Makefile is set to the name of the device’s virtual serial port. In Windows, {{fname|\\\\.\\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. {{fname|COM13}}).
 +
 +
In a command prompt, navigate to the directory with the Makefile and main.c. If you run the command {{fname|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 {{fname|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.
    
{{Pololu-Romi-32U4-TRAILER}}
 
{{Pololu-Romi-32U4-TRAILER}}
29 917

modifications

Menu de navigation