问题
I have an ATtiny25v connected to a raspberry pi thtough SPI.
I use avr-gcc to compile my code. Then I use avrdude to upload it.
But I encounter a very strange phenomena : the main function is not called, and instead, the first instructions of the first function have effects on gpio...
I have a led connected on portb4.
...I tried with several chip of the same model, and they all behave the same (excluding a buggy one)
...Can someone explain it ?
NOTE :
I omitted to detail it, but neither the compiler (with -Wall -pedantic
) nor avrdude (with -v -v
) gives any error.
both the kcuzner and the upstream version (linux_gpio patched http://savannah.nongnu.org/bugs/?47550 ) gives the same results. kcuzner using linuxspi programmer behaves also the same.
this :
#include <avr/io.h>
#include <avr/interrupt.h>
#define B(b) (1 << b)
void ledT(){
PORTB ^= B(PORTB4);
}
void led(uint8_t s){
if(s)
PORTB |= B(PORTB4);
else {
PORTB &= ~B(PORTB4);
}
}
int main(){
PORTB = 0;
DDRB = 0;
USISR = 0;
USIDR = 0;
while(1);
//return 0;
}
...lights on the led on start.
#include <avr/io.h>
#include <avr/interrupt.h>
#define B(b) (1 << b)
void ledT(){
PORTB ^= B(PORTB3);
}
void led(uint8_t s){
if(s)
PORTB |= B(PORTB4);
else {
PORTB &= ~B(PORTB4);
}
}
int main(){
PORTB = 0;
DDRB = 0;
USISR = 0;
USIDR = 0;
while(1);
//return 0;
}
...Keeps the led off
and this one :
#include <avr/io.h>
#include <avr/interrupt.h>
#define B(b) (1 << b)
void ledT(){
PORTB ^= B(PORTB4);
PORTB ^= B(PORTB4);
}
void led(uint8_t s){
if(s)
PORTB |= B(PORTB4);
else {
PORTB &= ~B(PORTB4);
}
}
int main(){
PORTB = 0;
DDRB = 0;
USISR = 0;
USIDR = 0;
while(1);
//return 0;
}
...keeps also the led off.
#include <avr/io.h>
#include <avr/interrupt.h>
#define B(b) (1 << b)
void ledT(){
PORTB = PORTB | B(PORTB3);
PORTB = PORTB | B(PORTB4);
}
void led(uint8_t s){
if(s)
PORTB |= B(PORTB4);
else {
PORTB &= ~B(PORTB4);
}
}
int main(){
PORTB = 0;
DDRB = 0;
USISR = 0;
USIDR = 0;
while(1);
//return 0;
}
...Lights the led on
来源:https://stackoverflow.com/questions/55440304/very-strange-gpio-behaviour-programming-attiny25v-with-avr-gcc-and-avrdude-via-a