예제 #1
0
파일: flash_example.c 프로젝트: avrxml/asf
/*! \brief Main function running the example on both the flash array and the
 *         User page.
 */
int main(void)
{
#if BOARD == UC3L_EK
	// Note: on the AT32UC3L-EK board, there is no crystal/external clock connected
	// to the OSC0 pinout XIN0/XOUT0. We shall then program the DFLL and switch the
	// main clock source to the DFLL.
	pcl_configure_clocks(&pcl_dfll_freq_param);
	// Note: since it is dynamically computing the appropriate field values of the
	// configuration registers from the parameters structure, this function is not
	// optimal in terms of code size. For a code size optimal solution, it is better
	// to create a new function from pcl_configure_clocks_dfll0() and modify it
	// to use preprocessor computation from pre-defined target frequencies.
#else
	// Configure Osc0 in crystal mode (i.e. use of an external crystal source, with
	// frequency FOSC0) with an appropriate startup time then switch the main clock
	// source to Osc0.
	pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
#endif

	// Initialize the debug USART module.
	init_dbg_rs232(EXAMPLE_TARGET_PBACLK_FREQ_HZ);

	// Apply the example to the flash array.
	flash_rw_example("\x0C=== Using a piece of the flash array as NVRAM ===\r\n",
			&flash_nvram_data);

	// Apply the example to the User page.
	flash_rw_example("\r\n\r\n=== Using a piece of the User page as NVRAM ===\r\n",
			&user_nvram_data);

	//*** Sleep mode
	// This program won't be doing anything else from now on, so it might as well
	// sleep.
	// Modules communicating with external circuits should normally be disabled
	// before entering a sleep mode that will stop the module operation.
	// For this application, we must disable the USART module that the DEBUG
	// software module is using.
	pcl_disable_module(DBG_USART_CLOCK_MASK);

	// Since we're going into a sleep mode deeper than IDLE, all HSB masters must
	// be stopped before entering the sleep mode.
	pcl_disable_module(AVR32_PDCA_CLK_HSB);
	pcl_disable_module(AVR32_PDCA_CLK_PBA);

	// If there is a chance that any PB write operations are incomplete, the CPU
	// should perform a read operation from any register on the PB bus before
	// executing the sleep instruction.
	AVR32_INTC.ipr[0];  // Dummy read

	// Go to STATIC sleep mode.
	SLEEP(AVR32_PM_SMODE_STATIC);

	while (true);
}
예제 #2
0
/*! \brief Main function running the example on both the flash array and the
 *         User page.
 */
int main(void)
{
	// Switch main clock to external oscillator 0 (crystal).
	pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

	// Initialize the debug USART module.
	init_dbg_rs232(FOSC0);

	// Apply the example to the flash array.
	flash_rw_example("\x0C=== Using a piece of the flash array as NVRAM ===\r\n",
			&flash_nvram_data);

	// Apply the example to the User page.
	flash_rw_example("\r\n\r\n=== Using a piece of the User page as NVRAM ===\r\n",
			&user_nvram_data);

	while (true);
}
예제 #3
0
/*!
 * \brief main function : perform several read/write accesses to the flash then
 * lock and unlock a page in the flash.
 */
int main(void)
{
	uint32_t key;

	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the console uart */
	configure_console();

	/* Output example information */
	printf("-- FLASHCALW Example --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Apply the example to the flash array. */
	flash_rw_example(
		"\x0C=== Using a piece of the flash array as NVRAM ===\r\n",
		(nvram_data_t *)NVRAM_PAGE_ADDRESS);

	/* Apply the example to the user page. */
	flash_rw_example(
		"\r\n\r\n=== Using a piece of the user page as NVRAM ===\r\n",
		(nvram_data_t *)USER_PAGE_ADDRESS);

	/* Flash lock example */
	flash_protect_example();

	printf("-I- Good job!\n\r"
		"-I- Now set the security bit \n\r"
		"-I- Press any key to continue to see what happened...\n\r");
	while (0 != usart_read(CONF_UART, &key));

	/* Set security bit */
	printf("-I- Setting security bit \n\r");
	flashcalw_set_security_bit();

	printf("-I- All tests done\n\r");

	while (true) {
	}
}