drivers: mtd_spi_nor MTD interface driver for SPI NOR flash chips#6762
drivers: mtd_spi_nor MTD interface driver for SPI NOR flash chips#6762jnohlgard merged 2 commits intoRIOT-OS:masterfrom
Conversation
|
There's an accidental autosave file included in this PR |
|
Fixed |
jnohlgard
left a comment
There was a problem hiding this comment.
Found some minor comments. I will test the code on mulle later tonight or tomorrow
boards/mulle/board.c
Outdated
| .private_data = &mulle_nvram_dev, | ||
| }; | ||
|
|
||
| mtd_spi_nor_t mulle_nor_dev = { |
boards/mulle/Makefile.dep
Outdated
| USEMODULE += devfs | ||
| USEMODULE += mtd_spi_nor | ||
|
|
||
| #FEATURES_REQUIRED += periph_spi |
There was a problem hiding this comment.
Remove, already handled by drivers/Makefile.dep
| mulle_nvram->write(mulle_nvram, &rec.u8[0], MULLE_NVRAM_BOOT_COUNT, sizeof(rec.u32)); | ||
| } | ||
|
|
||
| int mulle_nor_init(void) |
There was a problem hiding this comment.
Forgot to add a call to this function from board_init
drivers/include/mtd_spi_nor.h
Outdated
| #define MTD_SPI_NOR_H_ | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdbool.h> |
drivers/mtd_spi_nor/Makefile
Outdated
| @@ -0,0 +1,3 @@ | |||
| MODULE = mtd_spi_nor | |||
There was a problem hiding this comment.
Not needed when the directory name is the same as the module name
drivers/mtd_spi_nor/mtd_spi_nor.c
Outdated
| break; | ||
| } | ||
| #if MODULE_XTIMER | ||
| xtimer_usleep(50 * US_PER_MS); /* TODO magic number */ |
There was a problem hiding this comment.
Let's move this to a macro define at the top of this file.
|
Needs rebase |
9281eaf to
66d8e09
Compare
|
rebased |
| /* 4 KiO sectors can be erased with sector erase command */ | ||
| mtd_spi_cmd_addr_write(dev, dev->opcode->block_erase_32k, addr_be, NULL, 0); | ||
| } | ||
| else { |
There was a problem hiding this comment.
size is not checked here. This causes the unit test for erase of invalid size to fail.
| * software bugs (the erase-all-your-files kind) */ | ||
| DEBUG("addr = %" PRIx32 " ~dev->erase_addr_mask = %" PRIx32 "", addr, ~dev->sec_addr_mask); | ||
| DEBUG("mtd_spi_nor_erase: ERR: erase addr not aligned on %" PRIu32 " byte boundary.\n", | ||
| sector_size); |
There was a problem hiding this comment.
riot/drivers/mtd_spi_nor/mtd_spi_nor.c:447:13: error: ‘sector_size’ undeclared (first use in this function)
sector_size);
^
jnohlgard
left a comment
There was a problem hiding this comment.
Found a small bug in mtd_spi_cmd_addr_write
drivers/mtd_spi_nor/mtd_spi_nor.c
Outdated
| do { | ||
| /* Send opcode followed by address */ | ||
| spi_transfer_byte(dev->spi, dev->cs, true, opcode); | ||
| spi_transfer_bytes(dev->spi, dev->cs, true, (char *)addr_buf, NULL, dev->addr_width); |
There was a problem hiding this comment.
This currently keeps the CS pin asserted on erase commands (count = 0), causes unit test failures on Mulle
Fixed:
bool cont = (count > 0); /* only keep CS asserted when there is data that follows */
spi_transfer_bytes(dev->spi, dev->cs, cont, (char *)addr_buf, NULL, dev->addr_width);
/* Write data */
if (cont) {
/* Erase 2nd - 3rd sector */
ret = mtd_erase(dev, dev->pages_per_sector * dev->page_size,
dev->pages_per_sector * dev->page_size * 2);
TEST_ASSERT_EQUAL_INT(0, ret);erase only supports a single page in the current implementation /* out of bounds write (addr) */
ret = mtd_write(dev, buf, dev->pages_per_sector * dev->page_size * dev->sector_count,
sizeof(buf));
TEST_ASSERT_EQUAL_INT(-EOVERFLOW, ret);not sure what happens here. |
|
jnohlgard@451af3d has some configuration for the Mulle MTD flash Depends on #6810 |
c7c5ea3 to
e8219d9
Compare
|
|
OK to squash |
This is a generic SPI NOR flash driver which can be used with many different flash chips.
42a82c5 to
2c6088d
Compare
|
Squashed |
|
@vincent-d do you mind approving #6810? It's a very small changeset |
|
\o/ Thanks @gebart |
benpicco
left a comment
There was a problem hiding this comment.
I think I just discovered an old bug that was never noticed in the last 4 years 😨
| .page_program = 0x02, | ||
| .sector_erase = 0x20, | ||
| .block_erase_32k = 0x52, | ||
| .block_erase = 0xd8, |
| else { | ||
| for (size_t i = 0; i < size / sector_size; i++) { | ||
| mtd_spi_cmd_addr_write(dev, dev->opcode->block_erase, addr_be, NULL, 0); | ||
| addr += sector_size; |
There was a problem hiding this comment.
and sector_size != 64k
So this will delete a lot more data than it should.
This is based on #5668 with some minor improvements with erase and this has been ported to new spi interface.