Skip to content

drivers: flash: Addition of MCHP g3 driver#109747

Open
sr-mchp wants to merge 4 commits into
zephyrproject-rtos:mainfrom
sr-mchp:mchp_flash_g3_driver
Open

drivers: flash: Addition of MCHP g3 driver#109747
sr-mchp wants to merge 4 commits into
zephyrproject-rtos:mainfrom
sr-mchp:mchp_flash_g3_driver

Conversation

@sr-mchp
Copy link
Copy Markdown
Contributor

@sr-mchp sr-mchp commented May 25, 2026

  • Addition of device tree nodes for supporting flash peripheral for PIC32CZ_CA series of devices.
  • Flash G3 driver implementation.
  • Update to the board metadata to list flash partitions and sections to support pic32cz_ca80 and pic32cz_ca90 series of boards.
  • Addition of board overlay files to enable flash tests.

Copy link
Copy Markdown
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

Overall seems fine.
I only recommend you do another pass and separate distinct logical blocks to make a easy reading.

soc {
flash0: flash@8000000 {
reg = <0x08000000 DT_SIZE_M(1)>;
nvmctrl: nvmctrl@44002000 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi,

Fix all the commit messages:

brief: 52 chars
description: <=72

dts: arm: microchip: NVMCTRL/Flash G3 driver

Added device tree nodes and binding files for supporting NVMCTRL and
Flash peripherals for PIC32CZ_CA series of devices.

Comment thread drivers/flash/flash_mchp_nvmctrl_g3.c Outdated
static inline const struct flash_config *get_flash_config(const struct device *dev)
{
if (dev->ops.init != NULL) {
#if MCHP_CHOSEN_FLASH_COVERS_ALL
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is ways in zephyr to check if the app chose a bootloader.
Could that works here? Is there other use cases that are not only a special bootloader usecase?

Comment thread drivers/flash/flash_mchp_nvmctrl_g3.c Outdated
Comment on lines +384 to +387
}
k_sem_take(&data->mutex_lock, K_FOREVER);
(void)memcpy(data_buff, (uint32_t *)(config->base_addr + offset), no_of_bytes);
k_sem_give(&data->mutex_lock);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is easy to read when you separate these two distinct logical blocks.

	}
+
	k_sem_take(&data->mutex_lock, K_FOREVER);
	(void)memcpy(data_buff, (uint32_t *)(config->base_addr + offset), no_of_bytes);
	k_sem_give(&data->mutex_lock);

I mean, the below is not tight with the previous operation.
You could apply this in other places to make this distinction.

Comment thread drivers/flash/flash_mchp_nvmctrl_g3.c Outdated
#define FLASH_MCHP_G3_CONFIG_PAGE_LAYOUT(n)
#endif /* CONFIG_FLASH_PAGE_LAYOUT */

#define MCHP_MAX(a, b) (((a) > (b)) ? (a) : (b))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In zephyr we define many util functions in include/sys/. I recommend a visit there to check the options.

#define MAX(a, b) Z_INTERNAL_MAX(a, b)

Comment on lines +15 to +16
- pic32cz_ca80_cult
- pic32cz_ca90_cult
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The main goal is make sure that NVMCTRL_G3 is tested. No need to add 2 devices that share the same driver.

Copy link
Copy Markdown
Contributor

@sunil-abraham sunil-abraham left a comment

Choose a reason for hiding this comment

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

Driver modification needed from an architectural perspective.

Comment thread drivers/flash/flash_mchp_nvmctrl_g3.c Outdated
/* App build: zephyr,flash (flash1) covers all partitions.
* Redirect to the child device (same as old sanitize_dev).
*/
const struct device *chosen = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using DT_CHOSEN(zephyr_flash) inside a flash driver does not make architectural sense. Please refactor the code.

Comment thread drivers/flash/flash_mchp_nvmctrl_g3.c Outdated

return (const struct flash_config *)chosen->config;
#else
/* MCUboot build: zephyr,flash (flash0/BFM) is too small.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Driver should not depend on the application using it. Please modify the design.

@sr-mchp sr-mchp force-pushed the mchp_flash_g3_driver branch from 3460766 to 13d3b6d Compare June 3, 2026 14:48
@zephyrbot zephyrbot requested a review from nashif June 3, 2026 14:50
Devicetree & binding files for NVMCTRL PIC32CZ_CA
series of devices

Signed-off-by: Shankar Ramasamy <shankar.ramasamy@microchip.com>
@sr-mchp sr-mchp force-pushed the mchp_flash_g3_driver branch from 13d3b6d to 53f4fb2 Compare June 3, 2026 15:02
sr-mchp added 3 commits June 3, 2026 15:52
NVMCTRL G3 driver implementation to support
PIC32CZ_CA device series

Signed-off-by: Shankar Ramasamy <shankar.ramasamy@microchip.com>
Add Flash partitions and board metadata for
pic32cz_ca80/90_cult boards

Signed-off-by: Shankar Ramasamy <shankar.ramasamy@microchip.com>
Add board support files for pic32cz_ca80_cult
to enable Flash test cases

Signed-off-by: Shankar Ramasamy <shankar.ramasamy@microchip.com>
@sr-mchp sr-mchp force-pushed the mchp_flash_g3_driver branch from 53f4fb2 to db58da7 Compare June 3, 2026 15:54
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 3, 2026


config FLASH_MCHP_NVMCTRL_G1
bool "Microchip G1 Flash Driver for NVMCTRL"
bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why remove the prompt?

space, not just at aligned addresses.

config FLASH_MCHP_NVMCTRL_G3
bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't be hidden


LOG_MODULE_REGISTER(flash_mchp_nvmctrl_g3);

#define SOC_NV_FLASH_NODE DT_NODELABEL(flash0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't be using node labels inside driver, use instance macros.

#define FLEXSPI_NOR_SOC_NV_FLASH_NODE(node_id) \

}
static struct nvmctrl_data nvmctrl_g3_data;
static const struct nvmctrl_config nvmctrl_g3_config = {
.clock_dev = DEVICE_DT_GET(DT_NODELABEL(clock)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what clock is that? this is not properly structured.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general you shouldn't rely on node labels in drivers, they can be changed easily.

soc {
flash0: flash@8000000 {
reg = <0x08000000 DT_SIZE_M(1)>;
nvmctrl: nvmctrl@44002000 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
nvmctrl: nvmctrl@44002000 {
nvmctrl: flash-comtroller@44002000 {

apply for all occurrences

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does this header exist!?

*/

/**
* @file mchp_nvmctrl_g3.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

extra_args:
- DTC_OVERLAY_FILE="./boards/${BOARD}_andestech_qspi_nor_xip.overlay"
- CONF_FILE="./prj.conf ./boards/${BOARD}_andestech_qspi_nor_xip.conf"
drivers.flash.common.mchp_pic32:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is a new test scenario needed since it's not applying any special config.
drivers.flash.common.default does it.

- frdm_imxrt1186/mimxrt1186/cm7
integration_platforms:
- nrf9160dk/nrf9160
drivers.flash.erase_blocks:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
drivers.flash.erase_blocks:

dt_label_compat_enabled("slot1_partition", "zephyr,mapped-partition"))
integration_platforms:
- imx95_evk/mimx9596/m7
drivers.flash.interface_test:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
drivers.flash.interface_test:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Devicetree Binding PR modifies or adds a Device Tree binding area: Flash area: Tests Issues related to a particular existing or missing test platform: Microchip PIC32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants