blink in Arduino Due [using ASF on SAM3]

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi freaks,

I bought an Arduino due and I am trying to run a blink program on it. This is my program:

#include 
#include 
#define MY_LED IOPORT_CREATE_PIN(PIOC, 22)
int main (void)
{
board_init();
ioport_init();
delay_init(F_CPU);
ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT);
ioport_set_pin_level(MY_LED, LOW);
while(1){
delay_s(1);
ioport_set_pin_level(MY_LED, HIGH);
delay_s(1);
ioport_set_pin_level(MY_LED, LOW);
}
}

I am programming it with a jlink-edu, with SWD debugging interface. The same program in Arduino IDE works:

int led = 8;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

what could be the problem?

Last Edited: Wed. Jan 15, 2014 - 09:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I thought I saw you post this earlier with formatting. Please put your code between code tags. It makes it much easier for us to help you if we can readily read the code that you have posted.

Thank you

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ereihani wrote:
The same program in Arduino IDE

what could be the problem?

They are NOT the same program. The algorithm appears similar, but the functions are all different and not shown.

Also if the SWD debugging interface is like the ones I'm familiar with, it probably doesn't run a delay as does the raw code.

Do the folks who make the debugger have a forum?

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Aren't you getting an error that says that the include file delay.h is not found? Zip your project folder and post it here.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

smileymicros wrote:
ereihani wrote:
The same program in Arduino IDE

what could be the problem?

They are NOT the same program. The algorithm appears similar, but the functions are all different and not shown.

Also if the SWD debugging interface is like the ones I'm familiar with, it probably doesn't run a delay as does the raw code.

Do the folks who make the debugger have a forum?

Smiley

There is a forum with the following address:
[url]
http://forum.segger.com/
[/url]
cause I did not get any error I thought the problem might be from the code not the debugger.
The code is attached.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ereihani wrote:
cause I did not get any error I thought the problem might be from the code not the debugger.
The code is attached.

I am pretty sure that it is the code that is not working. Where is it attached? Do you mean the code in your original post? That is very incomplete. Zip up and post the entire project folder, not just your ASF based .c file.

Once you do that we will be able to help you more.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry Larry I thought it is uploaded. I will put in dropbox. This is the link:
[url]
https://www.dropbox.com/s/9270ab...
[/url]
Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, to tell you the truth, I think you have done a remarkable job of converting the program from a .ino to an ASF based project. I checked all the functions that are called and they do appear to be correct. I even checked the pin assignment for MY_LED. The code looks like it should work.

I'm sorry, I do not have an answer for you as to why it does not work, but you were also not very specific in your first post as to what is not working. Can you describe the symptoms that indicate to you that it is not working?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

larryvc wrote:
Well, to tell you the truth, I think you have done a remarkable job of converting the program from a .ino to an ASF based project. I checked all the functions that are called and they do appear to be correct. I even checked the pin assignment for MY_LED. The code looks like it should work.

I'm sorry, I do not have an answer for you as to why it does not work, but you were also not very specific in your first post as to what is not working. Can you describe the symptoms that indicate to you that it is not working?


Thank you. I have connected a LED in series with a 1Kohm resistor. When I plug in the Arduino USB port and program it, the led starts blinking but not when I program it with jlink-edu using SWD.
The intersting point is here that I program the chip with Arduino IDE and then read back the flash memory with jlink and write back with jlink again and it works! so I think I am missing sth in the code!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Still looking at the project and noticed a couple of things that are most likely not causing the problem that you are having. They should be addressed though.

There is a compiler warning:

Warning	1	#warning "Using a default value. Edit this conf_sio2host.h file to modify that define value according to the current board." [-Wcpp]

Notice also that the two Libraries in the Solution Explorer are highlighted with yellow triangles. These are not the correct names for the libraries. The correct libraries are:

ibarm_cortexM3l_math.a
libm

They are found in the

C:\Program Files (x86)\Atmel\Atmel Toolchain\ARM GCC\Native\4.7.4.1035\CMSIS_Atmel\CMSIS

folder, at least in my install they are. I do not know if you need them both or not.

I am not by any means an expert on ASF but I will try to help you find a solution.

By chance do you have a .hex file you could post of the arduino build?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Larry. I was trying to send the data via uart that's why I used conf_sio2host.h. I removed it and got no warning. I put the hex file in the the following dropbox folder:

https://www.dropbox.com/sh/rmbo8...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I changed the delay to 1ms and put the waveform data in the same dropbox folder. As smiley said, delay does not work as expected and delay of 1ms comes out as 21ms.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Am I to take your last post as confirmation that the code works and that the issue was due to the SWD? That would be very good news! Mahalo

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually SWD works fine and the issue is about the clock definition.Do I need to know what is the value of F_CPU and change it 84MHz?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you have to add

sysclk_init();

before

board_init();

Also

delay_init(F_CPU);

is deprecated.

However it would be good for someone else to verify these.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

However it would be good for someone else to verify these.

Should I move this thread to the ASF forum? I'm not sure there's any guarantee it will be "seen" in Off Topic.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also, board_init() already calls ioport_init() (for the due project template), so it's possible that the second call "undoes" some of the board io initialization...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Should I move this thread to the ASF forum? I'm not sure there's any guarantee it will be "seen" in Off Topic.

I think that is a very good idea, I would.
westfw wrote:
also, board_init() already calls ioport_init() (for the due project template), so it's possible that the second call "undoes" some of the board io initialization...

How did I miss that, it's right at the beginning of the function?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I commented ioport_init(). Still get the same result.
Cliff: Could you please move it to ASF forum?
Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you add sysclk_init() as I indicated above?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Larry it worked. I am disappointed starting a blink program. I wanted to do more sophisticated things such SPI,UART, FIR filter implementation. I was stuck with a blink and had no idea how to solve it. I thought ASF would give me ready to use functions to make my project faster but I see little progress on it :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I thought ASF would give me ready to use functions to make my project faster but I see little progress on it

Well, you could try comparing it to the effort required to write blink (or whatever) from scratch WITHOUT ASF.
But yeah, Arduino gives you inefficient code that provides abstractions that are easy to use. ASF gives you inefficient abstractions that allow a vast quantity of different CPUs/etc to use similar-looking code. (I HOPE it does that. Otherwise it looks like it provides abstraction for the sake of abstraction...)