NVM是非易失性存贮器的意思,包括EEPROM和FLASH,我以前总以为是中断控制的东东。
首先建立ASF工程,
然后加入NVM模块。
打开ASF EXPLORER中的快速指导。
最后打断点调试,看看程序执行没有。
以下是程序执行结果截图。
程序清单如下:
- /**
- * \file
- *
- * \brief Empty user application template
- *
- */
- /**
- * \mainpage User Application template doxygen documentation
- *
- * \par Empty user application template
- *
- * This is a bare minimum user application template.
- *
- * For documentation of the board, go \ref group_common_boards "here" for a link
- * to the board-specific documentation.
- *
- * \par Content
- *
- * -# Include the ASF header files (through asf.h)
- * -# Minimal main function that starts with a call to system_init()
- * -# Basic usage of on-board LED and button
- * -# "Insert application code here" comment
- *
- */
- /*
- * Include header files for all drivers that have been imported from
- * Atmel Software Framework (ASF).
- */
- void configure_nvm(void);
- #include <asf.h>
- void configure_nvm(void)
- {
- struct nvm_config config_nvm;
- nvm_get_config_defaults(&config_nvm);
- nvm_set_config(&config_nvm);
- }
- int main (void)
- {
- system_init();
- configure_nvm();
- uint8_t page_buffer[NVMCTRL_PAGE_SIZE];
- for (uint32_t i = 0; i < NVMCTRL_PAGE_SIZE; i++) {
- page_buffer[i] = i;
- }
- enum status_code error_code;
- do
- {
- error_code = nvm_erase_row(
- 100 * NVMCTRL_ROW_PAGES * NVMCTRL_PAGE_SIZE);
- } while (error_code == STATUS_BUSY);
- do
- {
- error_code = nvm_write_buffer(
- 100 * NVMCTRL_ROW_PAGES * NVMCTRL_PAGE_SIZE,
- page_buffer, NVMCTRL_PAGE_SIZE);
- } while (error_code == STATUS_BUSY);
- do
- {
- error_code = nvm_read_buffer(
- 100 * NVMCTRL_ROW_PAGES * NVMCTRL_PAGE_SIZE,
- page_buffer, NVMCTRL_PAGE_SIZE);
- } while (error_code == STATUS_BUSY);
-
- while(1);
- }
|