简体   繁体   English

Cortex-M0 + ASF基础知识

[英]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. 我只是在从AVR过渡到ARM,而在使一个简单的眨眼程序正常工作时遇到了一些问题。 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. 我一直在互联网上搜索,在我看来,Atmel ASF库应该是最简单的入门方法,但是我似乎无法获得有效的程序。

I am using Atmel Studio to write the code and have tried several of the templates without success. 我正在使用Atmel Studio编写代码,并尝试了多个模板,但均未成功。 I am using a RobotDYN Cortex-M0 that has minimal support at best so I am flying a little blind here. 我所使用的RobotDYN Cortex-M0充其量只有很少的支持,所以我在这里有点盲目。

Here is what I have so far: 这是我到目前为止的内容:

  • Created a new C ASF Board project using the User Board Template for ATSAMD21G18A (confirmed the chip) 使用用于ATSAMD21G18A的用户板模板创建了一个新的C ASF板项目(已确认芯片)
  • Using the ASF Wizard I added: 使用ASF向导,我添加了:
    • IOPORT - General purpose I/O service IOPORT-通用I / O服务
    • Delay routines service 延迟例行服务

main.c: 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. 一切似乎编译罚款,我就可以开始调试器(采用Atmel-ICE)和程序获取到第一ioport_set_pin_level和似乎没有任何关于董事会发生,当它试图执行delay_ms它进入延迟,但不会返回。 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". 当我暂停程序执行时,似乎卡住了,等待delay_cycles的延迟完成,但是当我在delay函数中查看参数const uint32_t n ,它只会给出一条消息“ optimized out”。

What am I missing? 我想念什么? Are there possibly some compiler switches or other ASF libraries that I need to import? 我可能需要导入一些编译器开关或其他ASF库吗?

Here is what I currently have for the C Compiler options: 这是我目前拥有的C编译器选项:

-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. 发布此消息后不久,我偶然发现了答案,也许有人可以更好地解释如何使用ARM控制器/ 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. 现在,这是一个适用于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. 我不确定为什么不初始化延迟也会使IO输出混乱,也许其他人可以对此有所了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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