-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/mtd_spi_nor: Added test with security features
- Loading branch information
Showing
5 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
BOARD ?= nrf52840dk | ||
|
||
include ../Makefile.drivers_common | ||
|
||
USEMODULE += embunit | ||
USEMODULE += mtd_spi_nor | ||
|
||
#CFLAGS += -DTHREAD_STACKSIZE_MAIN=2048 | ||
#CFLAGS += -DISR_STACKSIZE=1024 | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
atmega8 \ | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Test Program for the MTD SPI NOR Flash Driver | ||
|
||
This program performs a number of tests with the MTD SPI NOR Flash driver, | ||
including reading, writing and erasing of the chip. | ||
|
||
This test will destroy the data present on the chip! | ||
|
||
# Usage | ||
|
||
## nRF52840DK | ||
The test is designed to work with the built-in MX25F6435F flash of the | ||
Nordic Semiconductor nRF52840DK development board. | ||
Currently the nRF52840DK Flash definitions do not have the security options enabled. | ||
|
||
To run the test you simply have to compile and run the test: | ||
``` | ||
make flash term | ||
``` | ||
The tests should conclude with "OK (3 tests)". | ||
|
||
To enable the security features of the built-in flash, the "MTD_SPI_NOR_MX_SECURITY" | ||
pseudomodule can be added to the make call: | ||
``` | ||
USEMODULE+=mtd_spi_nor_mx_security make flash term | ||
``` | ||
|
||
Likewise, the tests should conclude with "OK (3 tests)". | ||
|
||
## nRF52840DK with different flash chips | ||
The default SPI Device for using different Flash chips is SPI(1), which is present on | ||
the Arduino Uno style headers. The default pin for Chip Select is P1.5. The SPI Device and | ||
Chip Select pin can be changed with the CFLAGS FLASH_SPI_DEV and FLASH_SPI_CS: | ||
``` | ||
CFLAGS+="-DFLASH_SPI_DEV=1 -DFLASH_SPI_CS='GPIO_PIN(1,5)'" ... | ||
``` | ||
|
||
The Device under Test can be changed with CFLAGS as well: | ||
``` | ||
... CFLAGS+="-DTEST_IS25LE01G" ... | ||
``` | ||
|
||
If the Flash supports the security features, they can be enabled with the usage of a | ||
pseudomodule as well: | ||
``` | ||
... USEMODULE+=mtd_spi_nor_issi_security ... | ||
``` | ||
|
||
A full test call would therefore be for example: | ||
``` | ||
CFLAGS+="-DFLASH_SPI_DEV=1 -DFLASH_SPI_CS='GPIO_PIN(1,5)' -DTEST_IS25LE01G" \ | ||
USEMODULE+=mtd_spi_nor_issi_security make flash term | ||
``` | ||
|
||
# Tested/Supported Chips | ||
|
||
## ISSI | ||
|
||
- IS25LP128 (no security features) | ||
- IS25LE01G | ||
|
||
## Macronix | ||
|
||
- M25F6435F (built-in on nRF52840DK) | ||
- M25F12873F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright (C) 2024 Technische Universität Hamburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
/** | ||
* @{ | ||
* | ||
* @file | ||
* @brief Definitions for different Flash chips that can be tested | ||
* | ||
* @author Christopher Büchse <[email protected]> | ||
*/ | ||
|
||
#include "timex.h" | ||
#include "mtd_spi_nor.h" | ||
|
||
/* The default CS pin and SPI device is for the built-in flash of the nRF52840DK */ | ||
#ifndef FLASH_SPI_CS | ||
#define FLASH_SPI_CS GPIO_PIN(0, 17) | ||
#endif | ||
|
||
#ifndef FLASH_SPI_DEV | ||
#define FLASH_SPI_DEV 0 | ||
#endif | ||
|
||
#ifdef TEST_IS25LP128 | ||
|
||
#define IS25LP128_PAGE_SIZE (256) | ||
#define IS25LP128_PAGES_PER_SECTOR (16) | ||
#define IS25LP128_SECTOR_COUNT (4096) | ||
#define IS25LP128_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | \ | ||
SPI_NOR_F_SECT_64K) | ||
#define IS25LP128_SPI_CLK SPI_CLK_100KHZ | ||
#define IS25LP128_SPI_MODE SPI_MODE_0 | ||
|
||
static const mtd_spi_nor_params_t _is25lp128_flash_nor_params = { | ||
.opcode = &mtd_spi_nor_opcode_default, | ||
.wait_chip_erase = 30LU * US_PER_SEC, | ||
.wait_32k_erase = 100LU *US_PER_MS, | ||
.wait_sector_erase = 70LU * US_PER_MS, | ||
.wait_chip_wake_up = 100LU * US_PER_MS, | ||
.clk = IS25LP128_SPI_CLK, | ||
.flag = IS25LP128_FLAGS, | ||
.spi = SPI_DEV(FLASH_SPI_DEV), | ||
.mode = IS25LP128_SPI_MODE, | ||
.cs = FLASH_SPI_CS, | ||
.wp = GPIO_UNDEF, | ||
.hold = GPIO_UNDEF, | ||
}; | ||
|
||
static mtd_spi_nor_t _is25lp128_nor_dev = { | ||
.base = { | ||
.driver = &mtd_spi_nor_driver, | ||
.page_size = IS25LP128_PAGE_SIZE, | ||
.pages_per_sector = IS25LP128_PAGES_PER_SECTOR, | ||
.sector_count = IS25LP128_SECTOR_COUNT, | ||
}, | ||
.params = &_is25lp128_flash_nor_params, | ||
}; | ||
|
||
MTD_XFA_ADD(_is25lp128_nor_dev, 10); | ||
|
||
#elif defined TEST_IS25LE01G | ||
|
||
#define IS25LE01G_PAGE_SIZE (256) | ||
#define IS25LE01G_PAGES_PER_SECTOR (16) | ||
#define IS25LE01G_SECTOR_COUNT (32768) | ||
#define IS25LE01G_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | \ | ||
SPI_NOR_F_SECT_64K) | ||
#define IS25LE01G_SPI_CLK SPI_CLK_10MHZ | ||
#define IS25LE01G_SPI_MODE SPI_MODE_0 | ||
|
||
static const mtd_spi_nor_params_t _is25le01g_flash_nor_params = { | ||
.opcode = &mtd_spi_nor_opcode_default, | ||
.wait_chip_erase = 90LU * US_PER_SEC, | ||
.wait_32k_erase = 140LU * US_PER_MS, | ||
.wait_sector_erase = 100LU * US_PER_MS, | ||
.wait_chip_wake_up = 35LU * US_PER_MS, | ||
.clk = IS25LE01G_SPI_CLK, | ||
.flag = IS25LE01G_FLAGS, | ||
.spi = SPI_DEV(FLASH_SPI_DEV), | ||
.mode = IS25LE01G_SPI_MODE, | ||
.cs = FLASH_SPI_CS, | ||
.wp = GPIO_UNDEF, | ||
.hold = GPIO_UNDEF, | ||
}; | ||
|
||
static mtd_spi_nor_t _is25le01g_nor_dev = { | ||
.base = { | ||
.driver = &mtd_spi_nor_driver, | ||
.page_size = IS25LE01G_PAGE_SIZE, | ||
.pages_per_sector = IS25LE01G_PAGES_PER_SECTOR, | ||
.sector_count = IS25LE01G_SECTOR_COUNT, | ||
}, | ||
.params = &_is25le01g_flash_nor_params, | ||
}; | ||
|
||
MTD_XFA_ADD(_is25le01g_nor_dev, 10); | ||
|
||
#elif defined TEST_MX25L12873F | ||
|
||
#define MX25L12873F_PAGE_SIZE (256) | ||
#define MX25L12873F_PAGES_PER_SECTOR (16) | ||
#define MX25L12873F_SECTOR_COUNT (4096) | ||
#define MX25L12873F_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | \ | ||
SPI_NOR_F_SECT_64K) | ||
#define MX25L12873F_SPI_CLK SPI_CLK_10MHZ | ||
#define MX25L12873F_SPI_MODE SPI_MODE_0 | ||
|
||
static const mtd_spi_nor_params_t _mx25l12873f_flash_nor_params = { | ||
.opcode = &mtd_spi_nor_opcode_default, | ||
.wait_chip_erase = 50LU * US_PER_SEC, | ||
.wait_32k_erase = 150LU *US_PER_MS, | ||
.wait_sector_erase = 40LU * US_PER_MS, | ||
.wait_chip_wake_up = 35LU * US_PER_MS, | ||
.clk = MX25L12873F_SPI_CLK, | ||
.flag = MX25L12873F_FLAGS, | ||
.spi = SPI_DEV(FLASH_SPI_DEV), | ||
.mode = MX25L12873F_SPI_MODE, | ||
.cs = FLASH_SPI_CS, | ||
.wp = GPIO_UNDEF, | ||
.hold = GPIO_UNDEF, | ||
}; | ||
|
||
static mtd_spi_nor_t _mx25l12873f_nor_dev = { | ||
.base = { | ||
.driver = &mtd_spi_nor_driver, | ||
.page_size = MX25L12873F_PAGE_SIZE, | ||
.pages_per_sector = MX25L12873F_PAGES_PER_SECTOR, | ||
.sector_count = MX25L12873F_SECTOR_COUNT, | ||
}, | ||
.params = &_mx25l12873f_flash_nor_params, | ||
}; | ||
|
||
MTD_XFA_ADD(_mx25l12873f_nor_dev, 10); | ||
|
||
#endif /* TEST_MX25L12873F */ | ||
/** @} */ |
Oops, something went wrong.