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

Support QSPI Flash driver for Renesas RA6 devices #78959

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thaoluonguw
Copy link
Collaborator

Add support for QSPI Flash driver for RA6 devices

  • Add QSPI Flash driver support on EK_RA6M5, EK_RA6M4, EK_RA6M3 and EK_RA6E2.

@thaoluonguw thaoluonguw added the platform: Renesas RA Renesas Electronics Corporation, RA label Sep 24, 2024
@zephyrbot
Copy link
Collaborator

zephyrbot commented Sep 24, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_renesas zephyrproject-rtos/hal_renesas@3dafd03 zephyrproject-rtos/hal_renesas@7a6ef38 zephyrproject-rtos/hal_renesas@3dafd030..7a6ef381

Note: This message is automatically posted and updated by the Manifest GitHub Action.

enum qspi_flash_ex_op_types {
QSPI_FLASH_EX_OP_RESET = 0,
QSPI_FLASH_EX_OP_EXIT_QPI = 1,
};
Copy link
Member

Choose a reason for hiding this comment

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

Please insert blank line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I fixed it. Thank you for your comment.

@zephyrbot zephyrbot removed the DNM This PR should not be merged (Do Not Merge) label Oct 11, 2024
@KhiemNguyenT KhiemNguyenT added this to the v4.0.0 milestone Oct 14, 2024
KhiemNguyenT
KhiemNguyenT previously approved these changes Oct 14, 2024
reg:
required: true

size:
Copy link
Member

Choose a reason for hiding this comment

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

Renesas specific property should have renesas, prefix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@soburi : Thank you for your feedback. We decided to keep it as current because I saw that other vendors have similar declaration and as comment in #76134 (comment), we understand that it's still in Renesas specific.

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.

Issue with EX_OP and mostly nits regarding other areas.


#define QSPI_CMD_RESET_EN (0x66) /* Reset Enable */
#define QSPI_CMD_RESET_MEM (0x99) /* Reset Memory */
#define Ex_SPI_CMD_READ_ID (0x9F) /* Extended Spi Read JEDEC ID */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spi->SPI

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#define QSPI_CMD_RESET_EN (0x66) /* Reset Enable */
#define QSPI_CMD_RESET_MEM (0x99) /* Reset Memory */
#define Ex_SPI_CMD_READ_ID (0x9F) /* Extended Spi Read JEDEC ID */
#define QSPI_CMD_READ_ID (0xAF) /* Qpi Read JEDEC ID */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Qpi->QSPI

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't typo. We mentioned QPI mode (4-4-4) here.

#define QSPI_CMD_RESET_MEM (0x99) /* Reset Memory */
#define Ex_SPI_CMD_READ_ID (0x9F) /* Extended Spi Read JEDEC ID */
#define QSPI_CMD_READ_ID (0xAF) /* Qpi Read JEDEC ID */
#define QSPI_CMD_READ_SFDP (0x5A) /* Read SFDP */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Most of those defines are actually provided here https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/flash/spi_nor.h, I know the naming is SPI_NOR, but adding additional defines only brings new names for functionally the same things.
You could just use the SPI_NOR defines and define these that are not provided by the header.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -13,6 +13,11 @@ enum ra_ex_ops {
FLASH_RA_EX_OP_WRITE_PROTECT = FLASH_EX_OP_VENDOR_BASE,
};

enum qspi_flash_ex_op_types {
QSPI_FLASH_EX_OP_RESET = 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is already system wide id for reset
FLASH_EX_OP_RESET = 0

FLASH_EX_OP_RESET = 0,

and if the meaning is the same, the system wide one should be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We fixed it as your advice.

@@ -13,6 +13,11 @@ enum ra_ex_ops {
FLASH_RA_EX_OP_WRITE_PROTECT = FLASH_EX_OP_VENDOR_BASE,
};

enum qspi_flash_ex_op_types {
QSPI_FLASH_EX_OP_RESET = 0,
QSPI_FLASH_EX_OP_EXIT_QPI = 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This define is in the same range as system wide definition for non-vendor space, and as such is not allowed.
Please refer to

/*
* Extended operation interface provides flexible way for supporting flash
* controller features. Code space is divided equally into Zephyr codes
* (MSb == 0) and vendor codes (MSb == 1). This way we can easily add extended
* operations to the drivers without cluttering the API or problems with API
* incompatibility. Extended operation can be promoted from vendor codes to
* Zephyr codes if the feature is available in most flash controllers and
* can be represented in the same way.
*
* It's not forbidden to have operation in Zephyr codes and vendor codes for
* the same functionality. In this case, vendor operation could provide more
* specific access when abstraction in Zephyr counterpart is insufficient.
*/
#define FLASH_EX_OP_VENDOR_BASE 0x8000
#define FLASH_EX_OP_IS_VENDOR(c) ((c) & FLASH_EX_OP_VENDOR_BASE)

for instruction on how to define vendor specific operation
and to https://github.com/zephyrproject-rtos/zephyr/blob/03959a20f7834ffe50a51df2b2e45ef87d1b610b/include/zephyr/drivers/flash/stm32_flash_api_extensions.h for an example of such definition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that there is also typo and QPI should be QSPI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We updated for "QSPI_FLASH_EX_OP_EXIT_QPI" as your advice.
And "QPI" isn't typo. We mentioned QPI mode (4-4-4).

Comment on lines 269 to 340
if (!qspi_flash_ra_valid(QSPI_NOR_FLASH_SIZE, offset, len)) {
return -EINVAL;
}

if (len % QSPI_ERASE_BLK_SZ != 0) {
return -EINVAL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably want to have some logging in at least one of the ifs, otherwise you have the same error returned to user with no way to distinguish problems except for debugging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We fixed it. We added log to distinguish for errors.

Comment on lines 104 to 190
switch (code) {
case QSPI_FLASH_EX_OP_EXIT_QPI:
if (SPI_FLASH_PROTOCOL_QPI != qspi_data->qspi_cfg.spi_protocol) {
err = 0;
break;
}
cmd = QSPI_CMD_EXIT_QPI_MODE;
err = R_QSPI_DirectWrite(&qspi_data->qspi_ctrl, &cmd, ONE_BYTE, false);
if (err != FSP_SUCCESS) {
LOG_ERR("qspi: direct write failed");
err = -EIO;
}
break;

case QSPI_FLASH_EX_OP_RESET:
cmd = QSPI_CMD_RESET_EN;
err = R_QSPI_DirectWrite(&qspi_data->qspi_ctrl, &cmd, ONE_BYTE, false);
if (err == FSP_SUCCESS) {
cmd = QSPI_CMD_RESET_MEM;
err = R_QSPI_DirectWrite(&qspi_data->qspi_ctrl, &cmd, ONE_BYTE, false);
if (err != FSP_SUCCESS) {
LOG_ERR("qspi: direct write failed");
err = -EIO;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You lack here userspace processing, is that desired?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is designed without userspace processing.
It is supported to reset QPI mode and memory.

return -EINVAL;
}

if (!len) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you fail operation of -EINVAL, even if len == 0 would cause nothing happening at all,
on the other side in qspi_flash_ra_write you first check len == 0 and bypass any more checks as there is no more work to.

Consider having one flow everywhere, for example checking the len == 0 and just exit as there is no work to do and actually no possibility to failure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We fixed it. We unified one flow for both qspi_flash_ra_write() and qspi_flash_ra_read(): check "len == 0" first and just exit.

@de-nordic
Copy link
Collaborator

There is a lot of QPI in the code, shouldn't that be QSPI?

@thaoluonguw
Copy link
Collaborator Author

There is a lot of QPI in the code, shouldn't that be QSPI?

@de-nordic : Thank you so much for your review. We fixed issues which you pointed out.
Please check the updates at: https://github.com/zephyrproject-rtos/zephyr/compare/81878488837d751b4711ff629a61c9c098011dce..f462ce16a76f505fde14c40293db08f204f108a2

For "QPI" in the code, it isn't typo of "QSPI", this is support for QPI mode (4-4-4).

Could you please help us to recheck for the update? Thanks again.

@thaoluonguw thaoluonguw force-pushed the support_renesas_ra6_qspi branch 2 times, most recently from 2698314 to d1216b4 Compare October 27, 2024 15:37
Tri Nguyen and others added 2 commits November 1, 2024 19:42
Add support for QSPI Flash driver running on Renesas EK_RA6M5,
EK_RA6M4, EK_RA6M3 and EK_RA6E2.

Signed-off-by: Tri Nguyen <tri.nguyen.wj@bp.renesas.com>
Signed-off-by: Thao Luong <thao.luong.uw@renesas.com>
Update hal_renesas which support for qspi on RA6

Signed-off-by: Thao Luong <thao.luong.uw@renesas.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants