Beispiel #1
0
/*! \brief Tests single-sector access functions.
 */
static void at45dbx_example_test_RAM_mem(void)
{
  static U8 PatternTable[AT45DBX_SECTOR_SIZE];
  static U8 ReceiveTable[AT45DBX_SECTOR_SIZE];

  U8 Pattern = 0x55;
  memset(PatternTable, Pattern, AT45DBX_SECTOR_SIZE);
  memset(ReceiveTable, 0xA5, AT45DBX_SECTOR_SIZE);
  print_dbg("\tUsing Pattern 0x55");
  // Perform write access.
  if (at45dbx_write_open(Pattern))
  {
    at45dbx_write_sector_from_ram(PatternTable);
    at45dbx_write_close();
  }
  // Perform read access.
  if (at45dbx_read_open(Pattern))
  {
    at45dbx_read_sector_2_ram(ReceiveTable);
    at45dbx_read_close();
  }
  // Check read and write operations.
  if (!memcmp(ReceiveTable, PatternTable, AT45DBX_SECTOR_SIZE))
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL);
  }

  // Change the pattern used.
  Pattern = 0xAA;
  memset(PatternTable, Pattern, AT45DBX_SECTOR_SIZE);
  memset(ReceiveTable, 0xA5, AT45DBX_SECTOR_SIZE);
  print_dbg("\tUsing Pattern 0xAA");
  // Perform write access.
  if (at45dbx_write_open(Pattern))
  {
    at45dbx_write_sector_from_ram(PatternTable);
    at45dbx_write_close();
  }
  // Perform read access.
  if (at45dbx_read_open(Pattern))
  {
    at45dbx_read_sector_2_ram(ReceiveTable);
    at45dbx_read_close();
  }
  // Check read and write operations.
  if (!memcmp(ReceiveTable, PatternTable, AT45DBX_SECTOR_SIZE))
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL);
  }
}
Beispiel #2
0
/*! \brief Tests single-byte access functions.
 */
static void at45dbx_example_test_byte_mem(void)
{
  U8 Pattern = 0x55;
  U8 j = 0xA5;
  print_dbg("\tUsing Pattern 0x55");
  // Perform write access.
  if (at45dbx_write_open(Pattern))
  {
    at45dbx_write_byte(Pattern);
    at45dbx_write_close();
  }
  // Perform read access.
  if (at45dbx_read_open(Pattern))
  {
    j = at45dbx_read_byte();
    at45dbx_read_close();
  }
  // Check read and write operations.
  if (j == Pattern)
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL);
  }

  // Change the pattern used.
  Pattern = 0xAA;
  j = 0xA5;
  print_dbg("\tUsing Pattern 0xAA");
  // Perform write access.
  if (at45dbx_write_open(Pattern))
  {
    at45dbx_write_byte(Pattern);
    at45dbx_write_close();
  }
  // Perform read access.
  if (at45dbx_read_open(Pattern))
  {
    j = at45dbx_read_byte();
    at45dbx_read_close();
  }
  // Check read and write operations.
  if (j == Pattern)
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL);
  }
}
status_code_t nvm_write(mem_type_t mem, uint32_t address, void *buffer,
		uint32_t len)
{
	switch (mem) {
	case INT_FLASH:
	case INT_USERPAGE:
		flash_api_memcpy((volatile void *)address, (const void *)buffer,
				len, true);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
	{
		uint32_t sector = address / AT45DBX_SECTOR_SIZE;
		if (!at45dbx_write_sector_open(sector)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_sector_from_ram((const void *)buffer);
		at45dbx_write_close();
	}
	break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
	case INT_USERPAGE:
		flash_api_memcpy((volatile void *)address, (const void *)&data,
				1, true);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open(address)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
Beispiel #5
0
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
		nvm_flash_erase_and_write_buffer((flash_addr_t)address,
				(const void *)&data, 1, true);
		break;

	case INT_USERPAGE:
		nvm_user_sig_write_buffer((flash_addr_t)address,
				(const void *)&data, 1, true);
		break;

	case INT_EEPROM:
		nvm_eeprom_write_byte((eeprom_addr_t)address, data);
		break;

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open(address)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
Beispiel #6
0
/*! \brief Tests multiple-sector access functions.
 */
static void at45dbx_example_test_multiple_sector(void)
{
  U32 position = 252;
  U32 nb_sector = 4;

  // Initialize counters.
  at45dbx_example_error_cnt = 0;

  // Write sectors.
  print_dbg("\tWriting sectors\r\n");
  at45dbx_write_open(position);
  at45dbx_write_multiple_sector(nb_sector);
  at45dbx_write_close();

  // Read written sectors.
  print_dbg("\tReading sectors\t");
  at45dbx_read_open(position);
  at45dbx_read_multiple_sector(nb_sector);
  at45dbx_read_close();

  if (!at45dbx_example_error_cnt)
  {
    print_dbg(TEST_SUCCESS);
  }
  else
  {
    print_dbg(TEST_FAIL "\t");
    print_dbg_ulong(at45dbx_example_error_cnt);
    print_dbg(" errors\r\n");
  }
}
Beispiel #7
0
/**
 * \brief Test the read and write byte operations on the DataFlash
 *
 * This function will test the read and write functionalities of the DataFlash
 * using byte access. It will first write a known pattern on the 2 first
 * consecutive sectors and read it back by testing each value read.\n
 * In addition to test the data integrity and the byte read / write
 * functions, this will also test the continuity of the sectors as well as the
 * auto-incrementation of the DataFlash address.
 *
 * \param test Current test case.
 */
static void run_byte_access_test(const struct test_case *test)
{
	uint32_t i;
	bool status;
	uint8_t byte;

	/* Write bytes one by one to the 2 first continuous sectors
	 */
	status = at45dbx_write_byte_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for write access");
	for (i=0; i<AT45DBX_SECTOR_SIZE * 2; i++) {
		status = at45dbx_write_byte(BYTE_PATTERN1(i));
		test_assert_true(test, status == true,
				"Write byte operation error @ 0x%08x", i);
	}
	at45dbx_write_close();

	/* Read back the 2 first sectors of the DataFlash and check the values
	 */
	status = at45dbx_read_byte_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for read access");
	for (i=0; i<AT45DBX_SECTOR_SIZE * 2; i++) {
		byte = at45dbx_read_byte();
		test_assert_true(test, byte == BYTE_PATTERN1(i),
				"Read byte operation error @ 0x%08x"
				" (read: 0x%02x, expected: 0x%02x)", i,
				byte, BYTE_PATTERN1(i));
	}
	at45dbx_read_close();
}
Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram)
{
  if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;

  at45dbx_write_open(addr);
  at45dbx_write_sector_from_ram(ram);
  at45dbx_write_close();

  return CTRL_GOOD;
}
Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector)
{
  if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;

  at45dbx_write_open(addr);
  at45dbx_write_multiple_sector(nb_sector);
  at45dbx_write_close();

  return CTRL_GOOD;
}
Beispiel #10
0
status_code_t nvm_write(mem_type_t mem, uint32_t address, void *buffer,
		uint32_t len)
{
	switch (mem) {
	case INT_FLASH:
#if SAM4S
		/*! This erases 8 pages of flash before writing */
		if (flash_erase_page(address, IFLASH_ERASE_PAGES_8)) {
			return ERR_INVALID_ARG;
		}

		if (flash_write(address, (const void *)buffer, len, false)) {
			return ERR_INVALID_ARG;
		}

#elif SAM4L
		flashcalw_memcpy((volatile void *)address, (const void *)buffer,
				len, true);
#else
		if (flash_write(address, (const void *)buffer, len, true)) {
			return ERR_INVALID_ARG;
		}
#endif
		break;

#if SAM4S
	case INT_USERPAGE:
		if (flash_write_user_signature((const void *)buffer, len)) {
			return ERR_INVALID_ARG;
		}
		break;
#endif

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
	{
		uint32_t sector = address / AT45DBX_SECTOR_SIZE;
		if (!at45dbx_write_sector_open(sector)) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_sector_from_ram((const void *)buffer);
		at45dbx_write_close();
	}
	break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
Beispiel #11
0
/**
 * \brief Test the read and write multiple sector operations on the DataFlash
 *
 * This function will test the read and write functionalities of the DataFlash
 * using multiple sector access. It will first fill the 10 first DataFlash
 * sectors with a known pattern and read it back to test each value.\n
 *
 * \param test Current test case.
 */
static void run_multiple_sector_access_test(const struct test_case *test)
{
	bool status;
	uint32_t i;
	uint8_t value, cur_sector;
	uint8_t expected;

	/* Write the ram sector to the DataFlash
	 */
	status = at45dbx_write_sector_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for write access");
	cur_sector = 0;
	while (cur_sector++ < 10) {
		/* Fills a ram sector with a known pattern
		 */
		for (i=0; i<AT45DBX_SECTOR_SIZE; i++) {
			value = BYTE_PATTERN3(cur_sector * AT45DBX_SECTOR_SIZE + i);
			((uint8_t *) sector_buf)[i] = value;
		}
		/* Write sector on DataFlash */
		status = at45dbx_write_sector_from_ram(sector_buf);
		test_assert_true(test, status == true,
				"Error while writing sector # %i", cur_sector);
	}
	at45dbx_write_close();

	/* Read back the sector of the DataFlash
	 */
	status = at45dbx_read_sector_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for read access");
	cur_sector = 0;
	while (cur_sector++ < 10) {
		// Read the next sector.
		status = at45dbx_read_sector_to_ram(sector_buf);
		test_assert_true(test, status == true,
				"Error while reading sector # %i", cur_sector);

		/* Test each values of the current sector
		 */
		for (i=0; i<AT45DBX_SECTOR_SIZE; i++) {
			expected = BYTE_PATTERN3(cur_sector * AT45DBX_SECTOR_SIZE + i);
			test_assert_true(test, ((uint8_t *) sector_buf)[i] == expected,
					"Value not expected @ 0x%08x in sector # %i"
					" (read: 0x%02x, expected: 0x%02x)", i,
					cur_sector, ((uint8_t *) sector_buf)[i],
					expected);
		}
	}
	at45dbx_read_close();
}
Beispiel #12
0
status_code_t nvm_write_char(mem_type_t mem, uint32_t address, uint8_t data)
{
	switch (mem) {
	case INT_FLASH:
#if SAM4S
		/*! This erases 8 pages of flash before writing */
		if (flash_erase_page(address, IFLASH_ERASE_PAGES_8)) {
			return ERR_INVALID_ARG;
		} else if (flash_write(address, (const void *)&data, 1,
				false)) {
			return ERR_INVALID_ARG;
		}

#else
		if (flash_write(address, (const void *)&data, 1, true)) {
			return ERR_INVALID_ARG;
		}

#endif
		break;

#if SAM4S
	case INT_USERPAGE:
		if (flash_write_user_signature((const void *)&data,	1)) {
			return ERR_INVALID_ARG;
		}
		break;
#endif

#if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX)
	case AT45DBX:
		if (!at45dbx_write_byte_open() address) {
			return ERR_BAD_ADDRESS;
		}

		at45dbx_write_byte(data);
		at45dbx_write_close();
		at45dbx_read_byte_open(address);
		read = at45dbx_read_byte();
		at45dbx_read_close();
		break;
#endif

	default:
		return ERR_INVALID_ARG;
	}

	return STATUS_OK;
}
Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector)
{
	if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)){
		return CTRL_FAIL;
	}

	at45dbx_write_sector_open(addr);
	while (nb_sector--) {
		// Write the next sector.
		udi_msc_trans_block( false, sector_buf, AT45DBX_SECTOR_SIZE, NULL);
		at45dbx_write_sector_from_ram(sector_buf);
	}
	at45dbx_write_close();
	return CTRL_GOOD;
}
Beispiel #14
0
/**
 * \brief Test the read and write sector operations on the DataFlash
 *
 * This function will test the read and write functionalities of the DataFlash
 * using sector access. It will first fill a sector with a known pattern and
 * read it back by testing each value read.\n
 *
 * \param test Current test case.
 */
static void run_sector_access_test(const struct test_case *test)
{
	uint32_t i;
	bool status;

	/* Fills a ram sector with a known pattern
	 */
	for (i=0; i<AT45DBX_SECTOR_SIZE; i++) {
		sector_buf[i] = BYTE_PATTERN2(i);
	}

	/* Write the ram sector to the DataFlash
	 */
	status = at45dbx_write_sector_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for write access");
	status = at45dbx_write_sector_from_ram(sector_buf);
	test_assert_true(test, status == true,
			"Write sector operation error");
	at45dbx_write_close();

	/* Clear the ram sector buffer
	 */
	for (i=0; i<AT45DBX_SECTOR_SIZE; i++) {
		sector_buf[i] = 0;
	}

	/* Read back the sector of the DataFlash
	 */
	status = at45dbx_read_sector_open(0);
	test_assert_true(test, status == true,
			"Cannot open the DataFlash memory for read access");
	status = at45dbx_read_sector_to_ram(sector_buf);
	test_assert_true(test, status == true,
			"Read sector operation error");
	at45dbx_read_close();

	/* Compare the values read from the DataFlash with the expected values
	 */
	for (i=0; i<AT45DBX_SECTOR_SIZE; i++) {
		test_assert_true(test, sector_buf[i] == BYTE_PATTERN2(i),
				"Value not expected @ 0x%08x (read: 0x%02x,"
				" expected: 0x%02x)", i, sector_buf[i],
				BYTE_PATTERN2(i));
	}
}
Beispiel #15
0
/*! \brief Main function.
 */
int main(void)
{
	uint16_t i;

	// Initialize the system - clock and board.
	system_init();
	at45dbx_init();
	if(at45dbx_mem_check()==true)	{
		port_pin_set_output_level(DATA_FLASH_LED_EXAMPLE_0, false);
	} else
	{
		test_ko();
	}

	// Prepare half a data flash sector to 0xAA
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		ram_buf[i]=0xAA;
	}
	// And the remaining half to 0x55
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=0x55;
	}

	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read back this sector and compare to expected values
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		if (ram_buf[i]!=0xAA) {
			test_ko();
		}
	}
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		if (ram_buf[i]!=0x55) {
			test_ko();
		}
	}

	// Write one data flash sector to 0x00, 0x01 ....
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=i;
	}
	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read one data flash sector to ram
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		if ( ram_buf[i]!=(i%0x100) ) {
			test_ko();
		}
	}

	while (1);
}
/*! \brief Main function.
 */
int main(void)
{
	uint16_t i;
	sysclk_init();

	// Initialize the board.
	// The board-specific conf_board.h file contains the configuration of the board
	// initialization.
	board_init();
	at45dbx_init();
	if(at45dbx_mem_check()==true)	{
		gpio_set_pin_low(DATA_FLASH_LED_EXAMPLE_0);
	} else
	{
		test_ko();
	}

	// Prepare half a data flash sector to 0xAA
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		ram_buf[i]=0xAA;
	}
	// And the remaining half to 0x55
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=0x55;
	}

	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read back this sector and compare to expected values
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE/2;i++) {
		if (ram_buf[i]!=0xAA) {
			test_ko();
		}
	}
	for(;i<AT45DBX_SECTOR_SIZE;i++) {
		if (ram_buf[i]!=0x55) {
			test_ko();
		}
	}

	// Write one data flash sector to 0x00, 0x01 ....
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		ram_buf[i]=i;
	}
	at45dbx_write_sector_open(TARGET_SECTOR);
	at45dbx_write_sector_from_ram(ram_buf);
	at45dbx_write_close();

	// Read one data flash sector to ram
	at45dbx_read_sector_open(TARGET_SECTOR);
	at45dbx_read_sector_to_ram(ram_buf);
	at45dbx_read_close();
	for(i=0;i<AT45DBX_SECTOR_SIZE;i++) {
		if ( ram_buf[i]!=(i%0x100) ) {
			test_ko();
		}
	}

	gpio_set_pin_low(DATA_FLASH_LED_EXAMPLE_1);
	while (1);
}