Skip to content

Commit 8f25a37

Browse files
committed
tests/mtd_spi_nor: Added test with security features
1 parent e435a37 commit 8f25a37

File tree

5 files changed

+488
-0
lines changed

5 files changed

+488
-0
lines changed

tests/drivers/mtd_spi_nor/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BOARD ?= nrf52840dk
2+
3+
include ../Makefile.drivers_common
4+
5+
USEMODULE += embunit
6+
USEMODULE += mtd_spi_nor
7+
8+
#CFLAGS += -DTHREAD_STACKSIZE_MAIN=2048
9+
#CFLAGS += -DISR_STACKSIZE=1024
10+
11+
include $(RIOTBASE)/Makefile.include

tests/drivers/mtd_spi_nor/Makefile.ci

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BOARD_INSUFFICIENT_MEMORY := \
2+
atmega8 \
3+
#

tests/drivers/mtd_spi_nor/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Test Program for the MTD SPI NOR Flash Driver
2+
3+
This program performs a number of tests with the MTD SPI NOR Flash driver,
4+
including reading, writing and erasing of the chip.
5+
6+
This test will destroy the data present on the chip!
7+
8+
# Usage
9+
10+
## nRF52840DK
11+
The test is designed to work with the built-in MX25F6435F flash of the
12+
Nordic Semiconductor nRF52840DK development board.
13+
Currently the nRF52840DK Flash definitions do not have the security options enabled.
14+
15+
To run the test you simply have to compile and run the test:
16+
```
17+
make flash term
18+
```
19+
The tests should conclude with "OK (3 tests)".
20+
21+
To enable the security features of the built-in flash, the "MTD_SPI_NOR_MX_SECURITY"
22+
pseudomodule can be added to the make call:
23+
```
24+
USEMODULE+=mtd_spi_nor_mx_security make flash term
25+
```
26+
27+
Likewise, the tests should conclude with "OK (3 tests)".
28+
29+
## nRF52840DK with different flash chips
30+
The default SPI Device for using different Flash chips is SPI(1), which is present on
31+
the Arduino Uno style headers. The default pin for Chip Select is P1.5. The SPI Device and
32+
Chip Select pin can be changed with the CFLAGS FLASH_SPI_DEV and FLASH_SPI_CS:
33+
```
34+
CFLAGS+="-DFLASH_SPI_DEV=1 -DFLASH_SPI_CS='GPIO_PIN(1,5)'" ...
35+
```
36+
37+
The Device under Test can be changed with CFLAGS as well:
38+
```
39+
... CFLAGS+="-DTEST_IS25LE01G" ...
40+
```
41+
42+
If the Flash supports the security features, they can be enabled with the usage of a
43+
pseudomodule as well:
44+
```
45+
... USEMODULE+=mtd_spi_nor_issi_security ...
46+
```
47+
48+
A full test call would therefore be for example:
49+
```
50+
CFLAGS+="-DFLASH_SPI_DEV=1 -DFLASH_SPI_CS='GPIO_PIN(1,5)' -DTEST_IS25LE01G" \
51+
USEMODULE+=mtd_spi_nor_issi_security make flash term
52+
```
53+
54+
# Tested/Supported Chips
55+
56+
## ISSI
57+
58+
- IS25LP128 (no security features)
59+
- IS25LE01G
60+
61+
## Macronix
62+
63+
- M25F6435F (built-in on nRF52840DK)
64+
- M25F12873F

tests/drivers/mtd_spi_nor/flash_dut.c

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (C) 2024 Technische Universität Hamburg
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
/**
9+
* @{
10+
*
11+
* @file
12+
* @brief Definitions for different Flash chips that can be tested
13+
*
14+
* @author Christopher Büchse <christopher.buechse@tuhh.de>
15+
*/
16+
17+
#include "timex.h"
18+
#include "mtd_spi_nor.h"
19+
20+
/* The default CS pin and SPI device is for the built-in flash of the nRF52840DK */
21+
#ifndef FLASH_SPI_CS
22+
#define FLASH_SPI_CS GPIO_PIN(0, 17)
23+
#endif
24+
25+
#ifndef FLASH_SPI_DEV
26+
#define FLASH_SPI_DEV 0
27+
#endif
28+
29+
#ifdef TEST_IS25LP128
30+
31+
#define IS25LP128_PAGE_SIZE (256)
32+
#define IS25LP128_PAGES_PER_SECTOR (16)
33+
#define IS25LP128_SECTOR_COUNT (4096)
34+
#define IS25LP128_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | \
35+
SPI_NOR_F_SECT_64K)
36+
#define IS25LP128_SPI_CLK SPI_CLK_100KHZ
37+
#define IS25LP128_SPI_MODE SPI_MODE_0
38+
39+
static const mtd_spi_nor_params_t _is25lp128_flash_nor_params = {
40+
.opcode = &mtd_spi_nor_opcode_default,
41+
.wait_chip_erase = 30LU * US_PER_SEC,
42+
.wait_32k_erase = 100LU *US_PER_MS,
43+
.wait_sector_erase = 70LU * US_PER_MS,
44+
.wait_chip_wake_up = 100LU * US_PER_MS,
45+
.clk = IS25LP128_SPI_CLK,
46+
.flag = IS25LP128_FLAGS,
47+
.spi = SPI_DEV(FLASH_SPI_DEV),
48+
.mode = IS25LP128_SPI_MODE,
49+
.cs = FLASH_SPI_CS,
50+
.wp = GPIO_UNDEF,
51+
.hold = GPIO_UNDEF,
52+
};
53+
54+
static mtd_spi_nor_t _is25lp128_nor_dev = {
55+
.base = {
56+
.driver = &mtd_spi_nor_driver,
57+
.page_size = IS25LP128_PAGE_SIZE,
58+
.pages_per_sector = IS25LP128_PAGES_PER_SECTOR,
59+
.sector_count = IS25LP128_SECTOR_COUNT,
60+
},
61+
.params = &_is25lp128_flash_nor_params,
62+
};
63+
64+
MTD_XFA_ADD(_is25lp128_nor_dev, 10);
65+
66+
#elif defined TEST_IS25LE01G
67+
68+
#define IS25LE01G_PAGE_SIZE (256)
69+
#define IS25LE01G_PAGES_PER_SECTOR (16)
70+
#define IS25LE01G_SECTOR_COUNT (32768)
71+
#define IS25LE01G_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | \
72+
SPI_NOR_F_SECT_64K)
73+
#define IS25LE01G_SPI_CLK SPI_CLK_10MHZ
74+
#define IS25LE01G_SPI_MODE SPI_MODE_0
75+
76+
static const mtd_spi_nor_params_t _is25le01g_flash_nor_params = {
77+
.opcode = &mtd_spi_nor_opcode_default,
78+
.wait_chip_erase = 90LU * US_PER_SEC,
79+
.wait_32k_erase = 140LU * US_PER_MS,
80+
.wait_sector_erase = 100LU * US_PER_MS,
81+
.wait_chip_wake_up = 35LU * US_PER_MS,
82+
.clk = IS25LE01G_SPI_CLK,
83+
.flag = IS25LE01G_FLAGS,
84+
.spi = SPI_DEV(FLASH_SPI_DEV),
85+
.mode = IS25LE01G_SPI_MODE,
86+
.cs = FLASH_SPI_CS,
87+
.wp = GPIO_UNDEF,
88+
.hold = GPIO_UNDEF,
89+
};
90+
91+
static mtd_spi_nor_t _is25le01g_nor_dev = {
92+
.base = {
93+
.driver = &mtd_spi_nor_driver,
94+
.page_size = IS25LE01G_PAGE_SIZE,
95+
.pages_per_sector = IS25LE01G_PAGES_PER_SECTOR,
96+
.sector_count = IS25LE01G_SECTOR_COUNT,
97+
},
98+
.params = &_is25le01g_flash_nor_params,
99+
};
100+
101+
MTD_XFA_ADD(_is25le01g_nor_dev, 10);
102+
103+
#elif defined TEST_MX25L12873F
104+
105+
#define MX25L12873F_PAGE_SIZE (256)
106+
#define MX25L12873F_PAGES_PER_SECTOR (16)
107+
#define MX25L12873F_SECTOR_COUNT (4096)
108+
#define MX25L12873F_FLAGS (SPI_NOR_F_SECT_4K | SPI_NOR_F_SECT_32K | \
109+
SPI_NOR_F_SECT_64K)
110+
#define MX25L12873F_SPI_CLK SPI_CLK_10MHZ
111+
#define MX25L12873F_SPI_MODE SPI_MODE_0
112+
113+
static const mtd_spi_nor_params_t _mx25l12873f_flash_nor_params = {
114+
.opcode = &mtd_spi_nor_opcode_default,
115+
.wait_chip_erase = 50LU * US_PER_SEC,
116+
.wait_32k_erase = 150LU *US_PER_MS,
117+
.wait_sector_erase = 40LU * US_PER_MS,
118+
.wait_chip_wake_up = 35LU * US_PER_MS,
119+
.clk = MX25L12873F_SPI_CLK,
120+
.flag = MX25L12873F_FLAGS,
121+
.spi = SPI_DEV(FLASH_SPI_DEV),
122+
.mode = MX25L12873F_SPI_MODE,
123+
.cs = FLASH_SPI_CS,
124+
.wp = GPIO_UNDEF,
125+
.hold = GPIO_UNDEF,
126+
};
127+
128+
static mtd_spi_nor_t _mx25l12873f_nor_dev = {
129+
.base = {
130+
.driver = &mtd_spi_nor_driver,
131+
.page_size = MX25L12873F_PAGE_SIZE,
132+
.pages_per_sector = MX25L12873F_PAGES_PER_SECTOR,
133+
.sector_count = MX25L12873F_SECTOR_COUNT,
134+
},
135+
.params = &_mx25l12873f_flash_nor_params,
136+
};
137+
138+
MTD_XFA_ADD(_mx25l12873f_nor_dev, 10);
139+
140+
#endif /* TEST_MX25L12873F */
141+
/** @} */

0 commit comments

Comments
 (0)