Skip to content

Conversation

@thaoluonguw
Copy link
Contributor

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

zephyrbot commented Sep 24, 2024

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

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

@thaoluonguw thaoluonguw force-pushed the support_renesas_ra6_qspi branch from 96a9f25 to 92e6654 Compare October 11, 2024 17:22
@zephyrbot zephyrbot removed the DNM This PR should not be merged (Do Not Merge) label Oct 11, 2024
@thaoluonguw thaoluonguw force-pushed the support_renesas_ra6_qspi branch from 92e6654 to 8187848 Compare October 11, 2024 17:50
@KhiemNguyenT KhiemNguyenT added this to the v4.0.0 milestone Oct 14, 2024
KhiemNguyenT
KhiemNguyenT previously approved these changes Oct 14, 2024
Copy link
Contributor

@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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Spi->SPI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Qpi->QSPI

Copy link
Contributor 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.

Copy link
Contributor

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
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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
Contributor 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.

Copy link
Contributor

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
Contributor

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
Contributor 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 341
Copy link
Contributor

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
Contributor 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 191
Copy link
Contributor

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
Contributor 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.

Copy link
Contributor

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
Contributor 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
Contributor

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

@thaoluonguw
Copy link
Contributor 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.

Comment on lines 15 to 44
/* Reset Flash device (at QPI(4-4-4) mode) */
QSPI_FLASH_EX_OP_EXIT_QPI,
Copy link
Contributor

@kartben kartben Aug 26, 2025

Choose a reason for hiding this comment

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

this needs proper documentation, see FLASH_RA_EX_OP_WRITE_PROTECT doc in main -- even though I guess there's no in / out to document, there should still be proper doxygen documentation

Copy link
Contributor

Choose a reason for hiding this comment

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

I have updated it to follow proper Doxygen documentation standards, thank you

#define PAGE_SIZE_BYTE SPI_NOR_PAGE_SIZE
/* sector size of QSPI flash device */
#define BLOCK_SIZE_4K (4096U)
#define BLOCK_SIZE_32K (32678U)
Copy link
Contributor

@kartben kartben Aug 26, 2025

Choose a reason for hiding this comment

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

Indeed. Please fix

Comment on lines 269 to 285
uint8_t buffer[size];

acquire_device(dev);
memset(&buffer[0], 0, sizeof(buffer));
buffer[0] = QSPI_QPI_CMD_RDSFDP;
buffer[1] = addr;
buffer[2] = addr >> 8;
buffer[3] = addr >> 16;

err = R_QSPI_DirectWrite(&qspi_data->qspi_ctrl, &buffer[0], FOUR_BYTE, true);
if (err != FSP_SUCCESS) {
LOG_ERR("Direct write for READ SFDP failed");
err = -EIO;
goto out;
}

err = R_QSPI_DirectRead(&qspi_data->qspi_ctrl, &buffer[0], size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 58 to 59
#define QSPI_FLASH_ADDRESS(page_no) \
((uint8_t *)(QSPI_DEVICE_START_ADDRESS + ((page_no) * SPI_NOR_PAGE_SIZE)))
Copy link
Contributor

Choose a reason for hiding this comment

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

unused?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I have removed it. Many thanks

@kartben kartben assigned soburi and KhiemNguyenT and unassigned de-nordic Aug 26, 2025
@kartben
Copy link
Contributor

kartben commented Sep 1, 2025

@khoa-nguyen-18 @thaoluonguw ping in case you missed my comments

Tri Nguyen and others added 6 commits September 3, 2025 06:26
Add QSPI Flash driver supports for Renesas RA6.

Signed-off-by: Tri Nguyen <[email protected]>
Signed-off-by: Thao Luong <[email protected]>
Signed-off-by: Khoa Nguyen <[email protected]>
Add qspi node on Renesas RA6 devicetree to support QSPI flash driver

Signed-off-by: Quy Tran <[email protected]>
Add support for QSPI flash driver on EK-RA6E2, EK-RA6M3, EK-RA6M4
and EK-RA6M5

Signed-off-by: Quy Tran <[email protected]>
Signed-off-by: Khoa Nguyen <[email protected]>
Add support to test flash/common for qspi_nor on Renesas
ek_ra6m5, ek_ra6m4, ek_ra6m3, ek_ra6e2

Signed-off-by: Khoa Nguyen <[email protected]>
Add support for qspi Renesas RA to run the sample spi_flash

Signed-off-by: Khoa Nguyen <[email protected]>
Add support for qspi_nor for the sample jesd216 to run sample
on Renesas RA6 boards

Signed-off-by: Khoa Nguyen <[email protected]>
@khoa-nguyen-18 khoa-nguyen-18 force-pushed the support_renesas_ra6_qspi branch from a406f3e to 04e7722 Compare September 3, 2025 06:27
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 3, 2025

@henrikbrixandersen henrikbrixandersen merged commit 9a7a2b0 into zephyrproject-rtos:main Sep 5, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Flash area: Samples Samples area: SPI SPI bus platform: Renesas RA Renesas Electronics Corporation, RA

Projects

None yet

Development

Successfully merging this pull request may close these issues.