Skip to content
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

drivers/flash/nrf_qspi_nor: add support for enter 4-byte addressing mode #41743

Merged
merged 2 commits into from
Mar 23, 2022

Conversation

nvlsianpu
Copy link
Collaborator

@nvlsianpu nvlsianpu commented Jan 12, 2022

Added basic support for enter 4-byte addressing command.
Patch supports command 0xB7 (Enter 4-Byte Address Mode),
with or without preceding WREN.

Similar as for SPI-NOR the enter-4byte-addr property of
memory node is used or describing how to Enter 4-Byte Addressing
mode.
Worth to notice that along with that property the address-size-32
property is expected as it switch the driver to use 4-byte addressing
in operations.

Signed-off-by: Andrzej Puzdrowski andrzej.puzdrowski@nordicsemi.no

not tested on hardware yet
was tested using MX25L51245G

@nvlsianpu nvlsianpu added area: Flash platform: nRF Nordic nRFx DNM This PR should not be merged (Do Not Merge) labels Jan 12, 2022
@@ -564,7 +576,20 @@ static int qspi_nrfx_configure(const struct device *dev)
}
}

return 0;
if (INST_0_4BA != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add LOG_DBG that would be stating that we got into 4-byte address mode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@de-nordic
Copy link
Collaborator

Shouldn't we also address usage of sfdp-bfp in DTS? The enter_4byte_addr, as the binding states, is less important than sfdp bpfs, which stores the same info.

@nvlsianpu
Copy link
Collaborator Author

nvlsianpu commented Jan 13, 2022

Shouldn't we also address usage of sfdp-bfp in DTS? The enter_4byte_addr, as the binding states, is less important than sfdp bpfs, which stores the same info.

This driver doesn't support DTS bundled sfd-bfp. I think runtime processing of these build time records is not something I should apply in this PR. I was looking into spi-nor driver: It looks like support of that possibly results in implementation of features unused in given application.

Anyway, adding (runtime) read of DW16 of SFDP BFP make sense to me here.

@nvlsianpu
Copy link
Collaborator Author

nvlsianpu commented Jan 14, 2022

@de-nordic After I have been looking into spi_nor driver I conclude that the read and the runtime processing of SFDP might be implemented as there. Best approach would be extraction of common code from spi_nor.c (at last commonality of functionality of spi_nor_process_sfdp() function) and re-usage in both drivers. Such a task would be over what I want to introduce here.
#41819

@de-nordic
Copy link
Collaborator

@de-nordic After I have been looking into spi_nor driver I conclude that the read and the runtime processing of SFDP might be implemented as there. Best approach would be extraction of common code from spi_nor.c (at last commonality of functionality of spi_nor_process_sfdp() function) and re-usage in both drivers. Such a task would be over what I want to introduce here. #41819

Great. So I leave adding the LOG_DBG line up to you. I have looked at the code and it looks OK.
In the future we should probably add some defines to cover the bit meanings in the BFP bytes, but that will be a lot of work.

de-nordic
de-nordic previously approved these changes Jan 14, 2022
Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK. Thanks.

Comment on lines 580 to 589
if (INST_0_4BA & 0x02) {
qspi_nor_write_protection_set(dev, false);
}

struct qspi_cmd cmd = {
.op_code = SPI_NOR_CMD_4BA,
.rx_buf = NULL,
.tx_buf = NULL,
};
ret = qspi_send_cmd(dev, &cmd, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just:

		struct qspi_cmd cmd = {
			.op_code = SPI_NOR_CMD_4BA,
		};
		ret = qspi_send_cmd(dev, &cmd, (INST_0_4BA & 0x02));

?

Copy link
Collaborator Author

@nvlsianpu nvlsianpu Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and right, the rest of struct members will be zeroed automatically.

Comment on lines 591 to 702
if (ret < 0) {
LOG_DBG("E4BA cmd issued.");
} else {
LOG_ERR("E4BA cmd issue failed: %d.", ret);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret < 0 means that an error occurred, so this should be the other way around.

Comment on lines 82 to 83
#if DT_INST_NODE_HAS_PROP(0, enter_4byte_addr)
#define INST_0_4BA DT_INST_PROP(0, enter_4byte_addr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if DT_INST_NODE_HAS_PROP(0, enter_4byte_addr)
#define INST_0_4BA DT_INST_PROP(0, enter_4byte_addr)
#define INST_0_4BA DT_INST_PROP_OR(0, enter_4byte_addr, 0)

@richesonk
Copy link

What is the status of this pull request? I'm very interested in this change as the solution to #40453

@de-nordic de-nordic self-requested a review March 4, 2022 16:52
de-nordic
de-nordic previously approved these changes Mar 4, 2022
@nvlsianpu
Copy link
Collaborator Author

@richesonk I'm going to test this finally.

@nvlsianpu nvlsianpu removed the DNM This PR should not be merged (Do Not Merge) label Mar 14, 2022
@carlescufi carlescufi requested a review from anangl March 15, 2022 10:51
#if (INST_0_4BA != 0)
BUILD_ASSERT(((INST_0_4BA & 0x03) != 0),
"Driver only supports command (0xB7) for entering 4 byte addressing mode");
BUILD_ASSERT((DT_INST_PROP(0, address_size_32) == NRF_QSPI_ADDRMODE_32BIT),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BUILD_ASSERT((DT_INST_PROP(0, address_size_32) == NRF_QSPI_ADDRMODE_32BIT),
BUILD_ASSERT(DT_INST_PROP(0, address_size_32),

This is a boolean property, so it should not be compared with the value of NRF_QSPI_ADDRMODE_32BIT (which by chance evaluates to 1, hence it works in the current form).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied

@dastarling
Copy link

I also need this change for an active development project soon. I hope it makes the next NCS release. Thanks

@nvlsianpu nvlsianpu requested a review from nashif as a code owner March 22, 2022 09:52
@github-actions github-actions bot added the area: Tests Issues related to a particular existing or missing test label Mar 22, 2022
@nvlsianpu
Copy link
Collaborator Author

@de-nordic @anangl Can you revisit?

@carlescufi carlescufi requested a review from anangl March 22, 2022 10:51
@@ -0,0 +1,37 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a test configuration in testcase.yaml that will use this overlay so that CI has a chance to check it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 10 to 13
&qspi {
sck-pin = <30>;
io-pins = <29>, <28>, <04>, <03>;
csn-pins = <31>;
Copy link
Member

@anangl anangl Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This board (nRF52840 DK) uses PINCTRL now, so you need to rebase and then modify pinctrl-* properties instead.

Suggested change
&qspi {
sck-pin = <30>;
io-pins = <29>, <28>, <04>, <03>;
csn-pins = <31>;
&pinctrl {
qspi_default: qspi_default {
group1 {
psels = <NRF_PSEL(QSPI_SCK, 0, 30)>,
<NRF_PSEL(QSPI_IO0, 0, 29)>,
<NRF_PSEL(QSPI_IO1, 0, 28)>,
<NRF_PSEL(QSPI_IO2, 0, 04)>,
<NRF_PSEL(QSPI_IO3, 0, 03)>,
<NRF_PSEL(QSPI_CSN, 0, 31)>;
};
};
qspi_sleep: qspi_sleep {
group1 {
psels = <NRF_PSEL(QSPI_SCK, 0, 30)>,
<NRF_PSEL(QSPI_IO0, 0, 29)>,
<NRF_PSEL(QSPI_IO1, 0, 28)>,
<NRF_PSEL(QSPI_IO2, 0, 04)>,
<NRF_PSEL(QSPI_IO3, 0, 03)>,
<NRF_PSEL(QSPI_CSN, 0, 31)>;
low-power-enable;
};
};
};
&qspi {
pinctrl-0 = <&qspi_default_alt>;
pinctrl-1 = <&qspi_sleep_alt>;
pinctrl-names = "default", "sleep";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@nvlsianpu nvlsianpu force-pushed the nrf_qspi_nor/4byteMode branch 2 times, most recently from ea55ed2 to d21447e Compare March 22, 2022 14:07
anangl
anangl previously approved these changes Mar 22, 2022
Comment on lines 11 to 12
extra_args: OVERLAY_CONFIG=boards/nrf52840_flash_qspi.conf
DTC_OVERLAY_FILE=./boards/nrf52840dk_mx25l51245g.overlay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "./" actually needed?

Suggested change
extra_args: OVERLAY_CONFIG=boards/nrf52840_flash_qspi.conf
DTC_OVERLAY_FILE=./boards/nrf52840dk_mx25l51245g.overlay
extra_args: OVERLAY_CONFIG=boards/nrf52840_flash_qspi.conf
DTC_OVERLAY_FILE=boards/nrf52840dk_mx25l51245g.overlay

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'./' is not needed.

anangl
anangl previously approved these changes Mar 22, 2022
de-nordic
de-nordic previously approved these changes Mar 22, 2022
anangl
anangl previously approved these changes Mar 23, 2022
de-nordic
de-nordic previously approved these changes Mar 23, 2022
@nvlsianpu nvlsianpu dismissed stale reviews from de-nordic and anangl via 9c46b98 March 23, 2022 13:14
@nvlsianpu nvlsianpu force-pushed the nrf_qspi_nor/4byteMode branch 2 times, most recently from 9c46b98 to 1b83bf9 Compare March 23, 2022 14:04
Added basic support for enter 4-byte addressing command.
Patch  supports command 0xB7 (Enter 4-Byte Address Mode),
with or without preceding WREN.

Similar as for SPI-NOR the `enter-4byte-addr` property of
memory node is used or describing how to Enter 4-Byte Addressing
mode.
Worth to notice that along with that property the `address-size-32`
property is expected as it switch the driver to use 4-byte addressing
in operations.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Added overlay with DTS of MX25L51245G qspi flash
memory. DTS configures qspi clock to 2 MHz which is supported
by nRF52840.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
@carlescufi carlescufi merged commit b5b05bc into zephyrproject-rtos:main Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Flash area: Tests Issues related to a particular existing or missing test platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants