简体   繁体   中英

Cortex-M0+ ASF Basics

I am just making the transition from AVR to ARM and I am having some problems just getting a simple blink program working. I have been searching around the internet and it seems to me that the Atmel ASF libraries should be the easiest way to get started but I can not seem to get a working program.

I am using Atmel Studio to write the code and have tried several of the templates without success. I am using a RobotDYN Cortex-M0 that has minimal support at best so I am flying a little blind here.

Here is what I have so far:

  • Created a new C ASF Board project using the User Board Template for ATSAMD21G18A (confirmed the chip)
  • Using the ASF Wizard I added:
    • IOPORT - General purpose I/O service
    • Delay routines service

main.c:

#include <asf.h>
#include <delay.h>

#define TEST_PIN PIN_PA17

int main (void)
{
    system_init();

   ioport_init();
   ioport_set_pin_dir(TEST_PIN, IOPORT_DIR_OUTPUT); 

   while(1){
      ioport_set_pin_level(TEST_PIN, 1);
      delay_ms(1000);
      ioport_set_pin_level(TEST_PIN, 0);
      delay_ms(1000);
   }

}

Everything seems to compile fine and I can start the debugger (Using Atmel-ICE) and the program gets to the first ioport_set_pin_level and nothing seems to happen on the board and when it tries to execute the delay_ms it enters the delay but never returns. When I pause the program execution it seems like it is stuck waiting for the delay to finish in the delay_cycles but when I look at the parameter const uint32_t n in the delay function it just gives a message "optimized out".

What am I missing? Are there possibly some compiler switches or other ASF libraries that I need to import?

Here is what I currently have for the C Compiler options:

-x c -mthumb -D__SAMD21G18A__ -DDEBUG -DBOARD=USER_BOARD -DARM_MATH_CM0PLUS=true -DSYSTICK_MODE  -I"../src/ASF/common/boards" -I"../src/ASF/sam0/utils" -I"../src/ASF/sam0/utils/header_files" -I"../src/ASF/sam0/utils/preprocessor" -I"../src/ASF/thirdparty/CMSIS/Include" -I"../src/ASF/thirdparty/CMSIS/Lib/GCC" -I"../src/ASF/common/utils" -I"../src/ASF/sam0/utils/cmsis/samd21/include" -I"../src/ASF/sam0/utils/cmsis/samd21/source" -I"../src/ASF/sam0/drivers/system" -I"../src/ASF/sam0/drivers/system/clock/clock_samd21_r21_da_ha1" -I"../src/ASF/sam0/drivers/system/clock" -I"../src/ASF/sam0/drivers/system/interrupt" -I"../src/ASF/sam0/drivers/system/interrupt/system_interrupt_samd21" -I"../src/ASF/sam0/drivers/system/pinmux" -I"../src/ASF/sam0/drivers/system/power" -I"../src/ASF/sam0/drivers/system/power/power_sam_d_r_h" -I"../src/ASF/sam0/drivers/system/reset" -I"../src/ASF/sam0/drivers/system/reset/reset_sam_d_r_h" -I"../src/ASF/common2/boards/user_board" -I"../src" -I"../src/config" -I"../src/ASF/common2/services/delay" -I"../src/ASF/common2/services/delay/sam0" -I"../src/ASF/common/services/ioport"  -O1 -fdata-sections -ffunction-sections -mlong-calls -g3 -Wall -mcpu=cortex-m0plus -c -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return  -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" 

I stumbled upon the answer shortly after I posted this and maybe someone can explain a little better how to catch these things using the ARM controllers/ASF. All that I had to do is make the following changes:

#include <asf.h>
#include <delay.h>

#define TEST_PIN PIN_PA17

int main (void)
{
   system_init();

   ioport_init();
   delay_init();  /*** Must initialize the Delays ***/

   ioport_set_pin_dir(TEST_PIN, IOPORT_DIR_OUTPUT);

   while(1){
      ioport_set_pin_level(TEST_PIN, 1);
      delay_ms(1000);
      ioport_set_pin_level(TEST_PIN, 0);
      delay_ms(1000);
   }
}

Now this is a functioning program for a ATSAMD21G18A. I am not sure why not initializing the delay's would also mess up the IO Output, maybe someone else can shed a little light on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM