Esempio n. 1
0
/**
 * \brief Test AT25DFx initialization procedure.
 *
 * This test calls the initialization function and checks the SerialFlash.
 *
 * \param test Current test case.
 */
static void run_test_at25dfx_init(const struct test_case *test)
{
    at25_status_t status;

    /* Initialize the SerialFlash */
    at25dfx_initialize();

    /* Set the SerialFlash active */
    at25dfx_set_mem_active(AT25DFX_MEM_ID);

    /* Check if the SerialFlash is valid */
    status = at25dfx_mem_check();

    /* Validate the SerialFlash init and check function */
    test_assert_true(test, status == AT25_SUCCESS,
                     "Specific SerialFlash not found!");
}
/**
 * \brief Application entry point for AT25DFx example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint16_t i;

	sysclk_init();
	board_init();

	/* Initialize the SerialFlash */
	at25dfx_initialize();

	/* Set the SerialFlash active */
	at25dfx_set_mem_active(AT25DFX_MEM_ID);

	/* Unprotect the chip */
	if (at25dfx_protect_chip(AT25_TYPE_UNPROTECT) == AT25_SUCCESS) {
		LED_On(DATA_FLASH_LED_EXAMPLE_0);
	} else {
		test_ko();
	}

	/* Check if the SerialFlash is valid */
	if (at25dfx_mem_check() == AT25_SUCCESS) {
		LED_On(DATA_FLASH_LED_EXAMPLE_0);
	} else {
		test_ko();
	}

	/* Prepare half of the SerialFlash sector as 0xAA */
	for (i = 0; i < AT25DFX_TEST_DATA_SIZE / 2; i++) {
		ram_buff[i] = 0xAA;
	}

	/* And the remaining half as 0x55 */
	for (; i < AT25DFX_TEST_DATA_SIZE; i++) {
		ram_buff[i] = 0x55;
	}

	/* Erase the block before write */
	at25dfx_erase_block(AT25DFX_TEST_BLOCK_ADDR);

	/* Write the data to the SerialFlash */
	at25dfx_write(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	/* Read back this sector and compare them with the expected values */
	at25dfx_read(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	for (i = 0; i < AT25DFX_TEST_DATA_SIZE / 2; i++) {
		if (ram_buff[i] != 0xAA) {
			test_ko();
		}
	}
	for (; i < AT25DFX_TEST_DATA_SIZE; i++) {
		if (ram_buff[i] != 0x55) {
			test_ko();
		}
	}

	/* Write one SerialFlash sector as 0x00, 0x01 .... */
	for (i = 0; i < AT25DFX_TEST_DATA_SIZE; i++) {
		ram_buff[i] = i;
	}

	/* Erase the block before write */
	at25dfx_erase_block(AT25DFX_TEST_BLOCK_ADDR);

	/* Write the data to the SerialFlash */
	at25dfx_write(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	/* Read back this sector and compare them with the expected values */
	at25dfx_read(ram_buff, AT25DFX_TEST_DATA_SIZE, AT25DFX_TEST_BLOCK_ADDR);

	for (i = 0; i < AT25DFX_TEST_DATA_SIZE; i++) {
		if (ram_buff[i] != (i % 0x100)) {
			test_ko();
		}
	}

	LED_On(DATA_FLASH_LED_EXAMPLE_1);
	while (1);
}