Very strange gpio behaviour programming ATtiny25v with avr-gcc and avrdude via a raspberry pi

佐手、 提交于 2019-12-11 16:18:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!