Pure C programming on Arduino Due, issues!

The board I am using is Due, mcu is AT91SAM3X8E.

I found a blog about pure c programming without using IDE, at here

The source code of led.c is:

#include <avr/io.h>
#include <util/delay.h>

#define BLINK_DELAY_MS 2000

int main (void)
{
 /* set pin 5 of PORTB for output*/
 DDRB |= _BV(DDB5);

 while(1) {
  /* set pin 5 high to turn led on */
  PORTB |= _BV(PORTB5);
  _delay_ms(BLINK_DELAY_MS);

  /* set pin 5 low to turn led off */
  PORTB &= ~_BV(PORTB5);
  _delay_ms(BLINK_DELAY_MS);
 }
}

And the compile command is :

avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o led.o led.c
avr-objcopy -O ihex -R .eeprom led led.hex
sudo avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:led.hex

Although the example is based on UNO, avr-gcc and avr-objcopy works fine, but avrdude failed with the message:
"
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

"
So my question is:

  1. What -mmcu option should be for DUE, whose mcu is cortex-3, AT91SAM3X8E??
  2. How to fix the avrdude problem in pure C environment without IDE?
    ( The example works with IDE file->examples->basic->blink)

THANKS A LOT!

martinggww:
The board I am using is Due, mcu is AT91SAM3X8E.

I found a blog about pure c programming without using IDE, at here

The source code of led.c is:

#include <avr/io.h>

#include <util/delay.h>

#define BLINK_DELAY_MS 2000

int main (void)
{
/* set pin 5 of PORTB for output*/
DDRB |= _BV(DDB5);

while(1) {
  /* set pin 5 high to turn led on */
  PORTB |= _BV(PORTB5);
  _delay_ms(BLINK_DELAY_MS);

/* set pin 5 low to turn led off */
  PORTB &= ~_BV(PORTB5);
  _delay_ms(BLINK_DELAY_MS);
}
}




And the compile command is :


avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o led.o led.c
avr-objcopy -O ihex -R .eeprom led led.hex
sudo avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:led.hex




Although the example is based on UNO, avr-gcc and avr-objcopy works fine, but avrdude failed with the message:
"
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

"
So my question is:
1) What -mmcu option should be for DUE, whose mcu is cortex-3, AT91SAM3X8E??
2) How to fix the avrdude problem in pure C environment without IDE?
( The example works with IDE file->examples->basic->blink)

THANKS A LOT!

you compiled the code for a AtMega328p, 8bit AVR, not a DUE, The commands passed to Avrdude
tell it that it is talking to a ATMEGA328P, 8bit AVR not a 32bit SAM DUE, of course it fails.

You will have to use the correct makefile and the correct download commands.

I don't have any experience with SAM processors, I cannot help you, all I know is what won't work.

chuck.

Do not cross-post. Other thread removed.

chucktodd:
you compiled the code for a AtMega328p, 8bit AVR, not a DUE, The commands passed to Avrdude
tell it that it is talking to a ATMEGA328P, 8bit AVR not a 32bit SAM DUE, of course it fails.

You will have to use the correct makefile and the correct download commands.

I don't have any experience with SAM processors, I cannot help you, all I know is what won't work.

chuck.

Yes, what Chuck said. In fact, you're so far away from getting that code to work on an ARM Cortex M3 that I'm at a loss for where to even start. You've got to walk before you run. The compiler is different. The way you access I/O ports is different. The way you upload code to the board is different. It's all different. Don't jump into shark infested waters.

So, I think the best thing at this point is to ask why you want to use "pure c" and not the Arduino core files. Especially for the Due it is not pleasant to re-invent the wheel yourself. It's a complicated processor and requires a lot of code to make most things work. You should either use the Arduino core or you should look into CMSIS and ASF. You really ought to use existing libraries for as much as possible. The Arduino core isn't that bad and helps you out a lot. Take it from me (and many others on this forum), you can still write very large and advanced programs with Arduino.

As a bonus, once you get comfortable doing it the Arduino way you can start to branch out to doing it yourself. Where you don't like how Arduino does things you can override it. For instance, I have projects where the ADC code is custom and uses DMA. Arduino doesn't support this but I don't ever call the Arduino ADC functions.

If you really, really need to do it all manually I could help but I'm at a loss as to why you would want to really do that.

I found a blog about pure c programming without using IDE, at here

Which is all about AVR programming. When you use "pure C", Due programming will be MUCH different than AVR programming, because they are entirely different types of microcontroller chip. (and Due is much more complicated than an AVR as well.)

You could take a look on this side. [atwillys.de] "Low level" programming of the Arduino DUE SAM3 controller with a custom IDE