-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add spi nand driver #50690
base: main
Are you sure you want to change the base?
add spi nand driver #50690
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution.
Some clean up required.
My main request would be to remove STM32 mentions, since there is nothing STM32 specific here aside from the board used for test.
@rogeryou can you please format your commits as described here: |
9755c14
to
901b863
Compare
I have formated my commits. |
@rogeryou, thank you for this contribution. It would be very nice to have nand flash support in zephyr. Regarding the PR, I have seen that the ecc is hidden for the user as to be able to use the standard flash interface. This is a good thing, but doesn't this also make any other part of the oob data unavailable ? IMHO it would be good to extend the flash driver for nand flashes with read/write possibilities of the oob data. This would allow adding bad block info to the oob area. |
@rogeryou |
Thank you for your suggestion. We will add APIs that operate OOB later. |
Could you tell me which part of the program you mentioned? |
OK, so we should consider offset address given to flash API as logical, or rather dependent on whether obb/ecc feature of device is enabled or extra bytes are available for user. |
c7b00e4
to
51605d4
Compare
51605d4
to
c167d73
Compare
e014de8
to
c167d73
Compare
@rogeryou Can you please fix the compliance and documentation? |
|
66a06e6
to
9d94e4c
Compare
Hi @de-nordic , we have fixed the compliance and documentation, please review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be configuration for existing flash tests added, as the driver implements the Flash API and should work with these tests and samples we already have.
Some comments left, still reviewing.
@@ -63,6 +63,8 @@ zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_SMARTBOND flash_smartbond.c) | |||
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 soc_flash_b91.c) | |||
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_XMC4XXX soc_flash_xmc4xxx.c) | |||
zephyr_library_sources_ifdef(CONFIG_SPI_FLASH_AT45 spi_flash_at45.c) | |||
zephyr_library_sources_ifdef(CONFIG_SPI_NAND bch.c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to be fixed with this PR, but just want to mention that I will propose enhancement where bch implementation gets moved to CRC subsystem.
drivers/flash/Kconfig.nand
Outdated
@@ -0,0 +1,38 @@ | |||
# Copyright (c) 2022 Macronix International Co., Ltd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to update date in copyrights.
|
||
menuconfig SPI_NAND | ||
bool "SPI NAND Flash" | ||
select FLASH_HAS_DRIVER_ENABLED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing FLASH_HAS_EXPLICIT_ERASE
drivers/flash/Kconfig.nand
Outdated
Device is connected to SPI bus, it has to | ||
be initialized after SPI driver. | ||
|
||
config SPI_NAND_CS_WAIT_DELAY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be defined in DTS for a device?
drivers/flash/Kconfig.nand
Outdated
help | ||
This is the wait delay (in us) to allow for CS switching to take effect | ||
|
||
config SPI_NAND_IDLE_IN_DPD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be defined in dts?
drivers/flash/spi_nand.c
Outdated
LOG_ERR("Enable continuous read failed: %d\n", secur_reg); | ||
} | ||
|
||
out: release_device(dev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Labels alone in the line, drop the function call to the next line.
drivers/flash/spi_nand.c
Outdated
return ret; | ||
} | ||
|
||
static int spi_nand_conti_read_enable(const struct device *dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge the spi_nand_conti_read_enable
and spi_nand_conti_read_disable
. They are looking very similar.
drivers/flash/spi_nand.c
Outdated
size -= chunk; | ||
} | ||
|
||
out: release_device(dev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Labels get own lines.
drivers/flash/spi_nand.c
Outdated
offset = addr % data->page_size; | ||
chunk = (offset + size < data->page_size) ? | ||
size : (data->page_size - offset); | ||
read_bytes = chunk; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need read_bytes
; it seem that is equivalent of chunk
, through the loop, and not used outside.
goto out; | ||
} | ||
|
||
ret = spi_nand_wait_until_ready(dev); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unchecked ret
, static analysis will not be happy.
samples/drivers/spi_nand/README.rst
Outdated
:name: JEDEC SPI-NAND flash | ||
:relevant-api: flash_interface | ||
|
||
Use the flash API to interact with an SPI NOR serial flash memory device. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the flash API to interact with an SPI NOR serial flash memory device. | |
Use the flash API to interact with an SPI NAND serial flash memory device. |
9d94e4c
to
e43cdde
Compare
Add SPI NAND Flash driver support Signed-off-by: Daniel Zhang <[email protected]>
e43cdde
to
04e8854
Compare
This PR is updated for #43915.
Add SPI NAND block device driver for using SPI NAND Flash like Macronix Flash MX31LF4GE4BC.
This driver is tested on STM32L562E-DK.
The license of BCH code is updated.