Linux/Mac AVR 编程套件?

电器工程 大气压 avr linux osx
2022-01-06 21:46:00

我已经编码和使用 Arduinos 已经有一段时间了。不过,我已经准备好在没有 arduino 引导加载程序的情况下使用直接 AVR 芯片。我的问题是这样做的资源是什么?

我想使用 linux / mac,所以 winavr 和 avrstudio 一样不适用。如果没有我以后的样子,我会选择windows虚拟机。但在我确定之前。我想要的是某种使用 avr-gcc 的 IDE。

作为这个问题的奖励,是否有人有任何关于学习 C for avr 的好资源?具体如何为各种不同的芯片配置 Makefile 等?

4个回答

我同意 zklapow 但也请查看 AVR Freaks 上的项目部分。这就是我在arduinos之前的一天学到的东西。此外,您几乎肯定必须阅读芯片的数据表才能完成任何有用的事情。没有很好的功能可以读取模拟引脚,因为 arduino 环境对您隐藏了太多参数。让我举一个例子:

 int ledPin =  13;    // LED connected to digital pin 13
 // The setup() method runs once, when the sketch starts
 void setup()   {                
   // initialize the digital pin as an output:
   pinMode(ledPin, OUTPUT);     
 }
 // the loop() method runs over and over again,
 // as long as the Arduino has power
 void loop()                     
 {
   digitalWrite(ledPin, HIGH);   // set the LED on
   delay(1000);                  // wait for a second
   digitalWrite(ledPin, LOW);    // set the LED off
   delay(1000);                  // wait for a second
 }

大致类似于以下C(未测试):

int main(void) {
    // I just randomly picked pin 6 on PORTB, this may not be the same on an arduino
    DDRB = (1<<6); // set pin to output in data direction register
    int i; // have to do this outside the for loop because of C standard

    while(1) {
        PORTB |= (1<<6); // send pin 6 high and leave other pins in their current state
        for (i=0; i<10000; i++); // delay

        PORTB &= ~(1<<6); // send pin 6 low
        for (i=0; i<10000; i++); // delay
    }
}

当然,有些库中有延迟函数,其他库中可能有输出函数,但要习惯于编写这样的代码。您可能知道所有这些 PORTB 和 DDRB 的含义的唯一方法是阅读数据表。我很抱歉就此发表意见,但没有足够多的人意识到数据表是获取信息的金矿。

您还应该查看Eclipse for C/C++AVR-Eclipse 插件。对我来说完美无缺,尤其是交叉背包。我使用它大约一年了,我真的很喜欢它。

我也使用ObDev 的 CrossPack它是编写 AVR-GCC C 代码所需的所有工具的完美捆绑。它们与标准 Arduino 安装中存在的工具相同,因此有时我会使用 Arduino 构建系统的内容来编写简单的 AVR-GCC 代码。

通常,当我编写 C 代码时,我使用的“IDE”是文本编辑器、命令行命令和 Makefile。我只是这样更有效率。我打开了一个窗口,它是文本编辑器(emacs),另一个窗口正在编译,第三个或第四个窗口正在执行串行监视器或类似的操作。但是所有这些都可以在一个命令行窗口中完成,在这种情况下,命令看起来像:

% emacs foo.c [编辑文件]
% make [编译代码]
% make flash [上传到芯片]
% screen /dev/tty.usbserial 9600 [与芯片对话]
...然后根据需要重复...

此外,您可能想查看SmileyMicros.com在 Arduino 之前,他写了一本非常好的关于基于 AVR Butterfly 板的 AVR GCC 编程介绍的书,并且此后一直在更新他的示例以包含 Arduino。这是一个很好的比较,可以看到 AVR C 编程是如何在比 Arduino 更复杂的芯片上完成的。

如果你安装crosspack,你可以使用 Apple 的 Xcode for mac,这是一个很棒的 IDE。如果您想了解 AVR 的 c,请查看AVR Freaks 的教程论坛也至于 linux 看看这个问题