Go Down

Topic: Arduino Due With Atmel Studio 6.1 and ASF (Read 7 times) previous topic - next topic

ARMGuy

Hi all.

I am currently using the Atmel Studio 6.1 and the Atmel Software Framework with my Arduino Due.  The reason I am doing this is the Arduino IDE keeps a lot of things under the hood that I am trying to see.  So, I am using the Atmel Studio 6.1 in order to better learn the Cortex M3 ARM microcontroller.

Unfortunately, the complexity has already gotten the best of me.  I searched for the answers myself but came up empty-handed.

What I am basically trying to do is a simple program to toggle a pin, say what is commonly referred to as PIN 13 on the Arduino Due board, which is LED "L".  I used the New Project template, specifying the Arduino Due board and also added the GPIO, System Clock, and Delay ASF libraries.  I cannot get the LED to flash on and off at a 1 Hz rate, and I am stumped as to why.  Here's the body of my main:

Code: [Select]
int main (void)
{
board_init();
sysclk_init();
delay_init(sysclk_get_cpu_hz());



pio_set_output(PIOB, LED0_GPIO, HIGH, DISABLE, DISABLE);



while(1)
{
gpio_set_pin_high(LED0_GPIO);
delay_ms(1000);
gpio_set_pin_low(LED0_GPIO);
delay_ms(1000);
}



// Insert application code here, after the board has been initialized.
}


I tried some of the other gpio and pio configure and set functions to no avail.  It would be nice to have documentation that shows how the ASF relates to the chip itself.  For instance, to configure the port bin PB_27 as output, first do this then that.  I have yet to find any documentation like this, so I have resorted to trial and error.

Oh, I am also aware that the Atmel database has an example on PWMing PWM Channels 0 and 1 to make an LED glow, but my scope shows nothing is happening.  I believe I am programming the board correctly with bossac, as the verify portion of the programming says it was successful.

PaulS

Does using 1.5.x of the IDE result in the behavior that you want? In other words, is it a hardware or a software problem?

ARMGuy

#2
Jun 24, 2013, 10:37 pm Last Edit: Jun 25, 2013, 05:18 am by ARMGuy Reason: 1
The answer is...both.  Using the Arduino 1.5.2 IDE results in the behavior I want, which is a blinking LED on my board.

I actually resolved my issue.  It's a combination of following an outdated video from Atmel using a deprecated ASF API and my burning the wrong file onto the chip.  I was using the gpio configure and set functions.  They have actually been superceded by the IOPORT functions.  Additionally, I was burning the hex instead of the bin file.  Here's my code:

     
Code: [Select]
#include <asf.h>

#define MY_LED    IOPORT_CREATE_PIN(PIOB, 27)

int main (void)
{
board_init();
sysclk_init();
delay_init(sysclk_get_cpu_hz());
ioport_init();

ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT);




while(1)
{
ioport_set_pin_level(MY_LED, true);
delay_ms(2500);
ioport_set_pin_level(MY_LED, false);
delay_ms(2500);
}

}


This will cause the LED marked "L" on the Due to flash.  It will also cause Pin 13 to go high for 2.5 seconds, then low, cyclically.

Additionally, here is the command to burn the bin file to your Arduino Due board:

     
Code: [Select]
@C:\arduino-1.5.2\hardware\tools\bossac.exe --port=COM5 -U false -e -w -v -b  $(TargetDir)\$(TargetName).bin -R

Replace COM5 with the COM port your Arduino Due is connected.  Of course, also hold the Erase and Reset button then let go after one second if bossac complains it cannot find a device on the specified COM port. bossac should then be able to locate the device.  Also, once the Due is programmed, you may have to press the Reset button on the board to start the program.  On my board, I have had to do this even though I specified the "-R" parameter to bossac.exe

westfw

Next, can you explain how:
Code: [Select]
ioport_init();

ioport_set_pin_dir(MY_LED, IOPORT_DIR_OUTPUT);
  :
ioport_set_pin_level(MY_LED, true);

is less "under the hood" than pinMode/digitalWrite?  :-)

If you want to learn Atmel CM3, you should probably ignore most of ASF...

fat16lib

#4
Jun 25, 2013, 11:32 pm Last Edit: Jun 25, 2013, 11:51 pm by fat16lib Reason: 1
Quote
I am using the Atmel Studio 6.1 in order to better learn the Cortex M3 ARM microcontroller.


Very little of ASF is about the Cortex M3 core.   All ASF I/O except the Nested Vector Interrupt Controller is SAM3X8E specific and doesn't apply to other CM3 processors.

Go Up