Commit 022e60309b22978f432140efddd51886c0def791
1 parent
9d698fff
Test de la com serie arduino
Showing
6 changed files
with
200 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +export CC = avr-gcc | ||
2 | + | ||
3 | +export MCU = atmega328p | ||
4 | +export TARGET_ARCH = -mmcu=$(MCU) | ||
5 | + | ||
6 | +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g | ||
7 | +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os | ||
8 | + | ||
9 | +TARGET = usb | ||
10 | +TERM = /dev/ttyACM0 | ||
11 | +CPPFLAGS = -mmcu=$(MCU) | ||
12 | +PGMERISP = -c stk500v1 -b 115200 -P $(TERM) | ||
13 | +ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf | ||
14 | +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) | ||
15 | + | ||
16 | +C_SRC = $(wildcard *.c) | ||
17 | +OBJS = $(C_SRC:.c=.o) | ||
18 | + | ||
19 | +all: $(TARGET).hex | ||
20 | + | ||
21 | +clean: | ||
22 | + rm -f *.o *.hex *.elf | ||
23 | + | ||
24 | +%.o:%.c | ||
25 | + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ | ||
26 | + | ||
27 | +$(TARGET).elf: $(OBJS) | ||
28 | + $(CC) $(LDFLAGS) -o $@ $(OBJS) | ||
29 | + | ||
30 | +$(TARGET).hex: $(TARGET).elf | ||
31 | + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex | ||
32 | + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex | ||
33 | + | ||
34 | +upload: $(TARGET).hex | ||
35 | + stty -F $(TERM) hupcl # reset | ||
36 | + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex | ||
37 | + |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +export CC = avr-gcc | ||
2 | + | ||
3 | +export MCU = atmega328p | ||
4 | +export TARGET_ARCH = -mmcu=$(MCU) | ||
5 | + | ||
6 | +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g | ||
7 | +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os | ||
8 | + | ||
9 | +TARGET = usb | ||
10 | +TERM = /dev/ttyACM0 | ||
11 | +CPPFLAGS = -mmcu=$(MCU) | ||
12 | +PGMERISP = -c stk500v1 -b 115200 -P $(TERM) | ||
13 | +ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf | ||
14 | +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) | ||
15 | + | ||
16 | +C_SRC = $(wildcard *.c) | ||
17 | +OBJS = $(C_SRC:.c=.o) | ||
18 | + | ||
19 | +all: $(TARGET).hex | ||
20 | + | ||
21 | +clean: | ||
22 | + rm -f *.o *.hex *.elf | ||
23 | + | ||
24 | +%.o:%.c | ||
25 | + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ | ||
26 | + | ||
27 | +$(TARGET).elf: $(OBJS) | ||
28 | + $(CC) $(LDFLAGS) -o $@ $(OBJS) | ||
29 | + | ||
30 | +$(TARGET).hex: $(TARGET).elf | ||
31 | + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex | ||
32 | + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex | ||
33 | + | ||
34 | +upload: $(TARGET).hex | ||
35 | + stty -F $(TERM) hupcl # reset | ||
36 | + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex | ||
37 | + |
@@ -0,0 +1,63 @@ | @@ -0,0 +1,63 @@ | ||
1 | +#include <avr/io.h> // for the input/output registers | ||
2 | +#include <util/delay.h> // for _delay_ms | ||
3 | + | ||
4 | +// For the serial port | ||
5 | +#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz | ||
6 | + | ||
7 | +//compile -> makefile | ||
8 | + | ||
9 | +void init_serial(int speed){ | ||
10 | + /* Set baud rate */ | ||
11 | + UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; | ||
12 | + | ||
13 | + /* Enable transmitter & receiver */ | ||
14 | + UCSR0B = (1<<TXEN0 | 1<<RXEN0); | ||
15 | + | ||
16 | + /* Set 8 bits character and 1 stop bit */ | ||
17 | + UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); | ||
18 | + | ||
19 | + /* Set off UART baud doubler */ | ||
20 | + UCSR0A &= ~(1 << U2X0); | ||
21 | +} | ||
22 | + | ||
23 | +void send_serial(unsigned char c){ | ||
24 | + loop_until_bit_is_set(UCSR0A, UDRE0); | ||
25 | + UDR0 = c; | ||
26 | +} | ||
27 | + | ||
28 | +unsigned char get_serial(void) { | ||
29 | + loop_until_bit_is_set(UCSR0A, RXC0); | ||
30 | + return UDR0; | ||
31 | +} | ||
32 | + | ||
33 | +// For I/O handling (examples for PIN 8 as output and PIN 2 as input) | ||
34 | +void output_init(void){ | ||
35 | + DDRB |= 0x01; // PIN 8 as output | ||
36 | +} | ||
37 | + | ||
38 | +void output_set(unsigned char value){ | ||
39 | + if(value == 0) PORTB &= 0xfe; | ||
40 | + else PORTB |= 0x01; | ||
41 | +} | ||
42 | + | ||
43 | +void input_init(void){ | ||
44 | + DDRD &= 0xfb; // PIN 2 as input | ||
45 | + PORTD |= 0x04; // Pull-up activated on PIN 2 | ||
46 | +} | ||
47 | + | ||
48 | +unsigned char input_get(void){ | ||
49 | + return ((PIND & 0x04) != 0) ? 1 : 0; | ||
50 | +} | ||
51 | + | ||
52 | +// Dummy main | ||
53 | +int main(void){ | ||
54 | + init_serial(9600); | ||
55 | + while(1){ | ||
56 | + send_serial('A'); | ||
57 | + _delay_ms(500); | ||
58 | + } | ||
59 | + return 0; | ||
60 | +} | ||
61 | + | ||
62 | + | ||
63 | + |
@@ -0,0 +1,63 @@ | @@ -0,0 +1,63 @@ | ||
1 | +#include <avr/io.h> // for the input/output registers | ||
2 | +#include <util/delay.h> // for _delay_ms | ||
3 | + | ||
4 | +// For the serial port | ||
5 | +#define CPU_FREQ 16000000L // Assume a CPU frequency of 16Mhz | ||
6 | + | ||
7 | +//compile -> makefile | ||
8 | + | ||
9 | +void init_serial(int speed){ | ||
10 | + /* Set baud rate */ | ||
11 | + UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; | ||
12 | + | ||
13 | + /* Enable transmitter & receiver */ | ||
14 | + UCSR0B = (1<<TXEN0 | 1<<RXEN0); | ||
15 | + | ||
16 | + /* Set 8 bits character and 1 stop bit */ | ||
17 | + UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); | ||
18 | + | ||
19 | + /* Set off UART baud doubler */ | ||
20 | + UCSR0A &= ~(1 << U2X0); | ||
21 | +} | ||
22 | + | ||
23 | +void send_serial(unsigned char c){ | ||
24 | + loop_until_bit_is_set(UCSR0A, UDRE0); | ||
25 | + UDR0 = c; | ||
26 | +} | ||
27 | + | ||
28 | +unsigned char get_serial(void) { | ||
29 | + loop_until_bit_is_set(UCSR0A, RXC0); | ||
30 | + return UDR0; | ||
31 | +} | ||
32 | + | ||
33 | +// For I/O handling (examples for PIN 8 as output and PIN 2 as input) | ||
34 | +void output_init(void){ | ||
35 | + DDRB |= 0x01; // PIN 8 as output | ||
36 | +} | ||
37 | + | ||
38 | +void output_set(unsigned char value){ | ||
39 | + if(value == 0) PORTB &= 0xfe; | ||
40 | + else PORTB |= 0x01; | ||
41 | +} | ||
42 | + | ||
43 | +void input_init(void){ | ||
44 | + DDRD &= 0xfb; // PIN 2 as input | ||
45 | + PORTD |= 0x04; // Pull-up activated on PIN 2 | ||
46 | +} | ||
47 | + | ||
48 | +unsigned char input_get(void){ | ||
49 | + return ((PIND & 0x04) != 0) ? 1 : 0; | ||
50 | +} | ||
51 | + | ||
52 | +// Dummy main | ||
53 | +int main(void){ | ||
54 | + init_serial(9600); | ||
55 | + while(1){ | ||
56 | + send_serial('A'); | ||
57 | + _delay_ms(500); | ||
58 | + } | ||
59 | + return 0; | ||
60 | +} | ||
61 | + | ||
62 | + | ||
63 | + |
test_list_devices.c renamed to tests/test_list_devices.c
test_list_endpoints.c renamed to tests/test_list_endpoints.c