status_code_t nvm_read(mem_type_t mem, uint32_t address, void *buffer, uint32_t len) { switch (mem) { case INT_FLASH: nvm_flash_read_buffer((flash_addr_t)address, buffer, (uint16_t)len); break; case INT_USERPAGE: nvm_user_sig_read_buffer((flash_addr_t)address, buffer, (uint16_t)len); break; case INT_EEPROM: nvm_eeprom_read_buffer((eeprom_addr_t)address, buffer, (uint16_t)len); break; #if defined(USE_EXTMEM) && defined(CONF_BOARD_AT45DBX) case AT45DBX: { uint32_t sector = address / AT45DBX_SECTOR_SIZE; if (!at45dbx_read_sector_open(sector)) { return ERR_BAD_ADDRESS; } at45dbx_read_sector_to_ram(buffer); at45dbx_read_close(); } break; #endif default: return ERR_INVALID_ARG; } return STATUS_OK; }
/** * \brief Example 2 main application routine */ int main(void) { uint8_t flashbuf[8]; uint32_t checksum1; uint32_t checksum2; board_init(); sysclk_init(); gfx_mono_init(); // Calculate checksum for an address range in flash. checksum1 = crc_flash_checksum(CRC_FLASH_RANGE, FLASHADDR, 4); // Read out the buffer from flash nvm_flash_read_buffer(FLASHADDR, flashbuf, 4); // Calculate checksum for the buffer from flash checksum2 = crc_io_checksum(flashbuf, 4, CRC_32BIT); // Make sure the calculated checksums are equal and write to screen if (checksum1 == checksum2) { gfx_mono_draw_string("Address range CRC OK", 0, 0, &sysfont); } // Append the flash checksum and recalculate crc32_append_value(checksum1, flashbuf+4); checksum1 = crc_io_checksum(flashbuf, 8, CRC_32BIT); // Make sure the checksum is zero and write to screen if (checksum1 == 0) { gfx_mono_draw_string("IO CRC zero OK", 0, SYSFONT_HEIGHT + 1, &sysfont); } // Calculate checksum for the boot section checksum1 = crc_flash_checksum(CRC_BOOT, 0, 0); // Recalculate checksum for the boot section using flash range CRC checksum2 = crc_flash_checksum(CRC_FLASH_RANGE, BOOT_SECTION_START, BOOT_SECTION_END-BOOT_SECTION_START+1); // Make sure the checksums are equal and write to screen if (checksum1 == checksum2) { gfx_mono_draw_string("Boot section CRC OK", 0, (SYSFONT_HEIGHT + 1)*2, &sysfont); } // Calculate checksum for the application section checksum1 = crc_flash_checksum(CRC_APP, 0, 0); // Recalculate checksum for the application section using flash range CRC checksum2 = crc_flash_checksum(CRC_FLASH_RANGE, APP_SECTION_START, APP_SECTION_END-APP_SECTION_START+1); // Make sure the checksums are equal and write to screen if (checksum1 == checksum2) { gfx_mono_draw_string("App section CRC OK", 0, (SYSFONT_HEIGHT + 1)*3, &sysfont); } // End of application, loop forever while (true) { // Intentionally left empty } }
/** * \brief Copy a flash memory section to a RAM buffer * * \param dst Pointer to data destination. * \param src Pointer to source flash. * \param nbytes Number of bytes to transfer. */ static void mem_flash_read(void *dst, isp_addr_t src, uint16_t nbytes) { nvm_flash_read_buffer(src, dst, nbytes); }