/** * \brief 32-bit CRC of flash memory test * * This test does a 32-bit checksum on the flash memory and verifies the * checksum against a pre-calculated 32-bit CRC checksum. * * \param test Current test case */ static void run_flash_test(const struct test_case *test) { uint32_t checksum; checksum = crc_flash_checksum(CRC_FLASH_RANGE, (flash_addr_t)data_8bit_flash, LENGTH(data_8bit_flash)); test_assert_true(test, checksum == CRC_CHECKSUM_32BIT, "Checksum mismatch on flash range CRC-32 test"); }
/** * \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 } }