NCS 2.7.0 and "requires-ulbpr" for spi-nor

Hello,

I am currently migrating from NCS 2.6.0 to NCS 2.7.0 on my board with an NRF9160.

During that process I switched to the new hardware model and to sysbuild. As far as I see everything works as expected after the migration with NCS 2.7.0, except for writing to the SPI-NOR-Flash on my board. Reading from the SPI-NOR-Flash works with NCS 2.7.0.

I could narrow the issue down to the the requires_ulbpr setting, which is defined in the device tree for the SPI-NOR on my board:

&spi2 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    cs-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi2_default>;
    pinctrl-1 = <&spi2_sleep>;
    pinctrl-names = "default", "sleep";
    sst26vf016b: sst26vf016b@0 {
        compatible = "jedec,spi-nor";
        requires-ulbpr;
        reg = <0>;
        spi-max-frequency = <100000000>;
        size = <16777216>;
        has-dpd;
        t-enter-dpd = <3000>;
        t-exit-dpd = <5000>;
        jedec-id = [ bf 26 41 ];
    };
};

It seems in NCS 2.7.0 the setting is not evaluated correctly in spi_nor.c. In this version it is mapped to a bitfield, but the bit does not seem to be set, even if the requires-ulbpr is defined in the device-tree.

If I do the check the same it was done in NCS 2.6.0 instead of using the cfg->requires_ulbpr_exist bit (in function spi_nor_write_protection_set() of spi_nor.c) the setting is recognized correctly and writing is possible:

IS_ENABLED(DT_INST_PROP(0, requires_ulbpr)

Am I missing something? Is the bit field filled automatically or does it now require some initialization call for the SPI driver so it is working correctly?

Best regards

rw

Parents Reply Children
  • Yes, it is enabled in the device tree. That is not the problem.

    The problem is that if CONFIG_SPI_NOR_SFDP_RUNTIME=y is used in the prj.conf file cfg->requires_ulbpr_exist is not initialized for spi_nor in NCS 2.7.0.

  • Can you please explain this "cfg->requires_ulbpr_exist is not initialized"?

  • In the spi_nor driver (zephyr/drivers/flash/spi_nor.c) the struct spi_nor_config in v2.7.0 now also contains flags for some device tree opt-ins:

    struct spi_nor_config {
        ...
    	/* exist flags for dts opt-ins */
    	bool dpd_exist:1;
    	bool dpd_wakeup_sequence_exist:1;
    	bool mxicy_mx25r_power_mode_exist:1;
    	bool reset_gpios_exist:1;
    	bool requires_ulbpr_exist:1;
    	bool wp_gpios_exist:1;
    	bool hold_gpios_exist:1;
    };

    If CONFIG_SPI_NOR_SFDP_RUNTIME=y is not used in the project configuration, requires_ulpbr from the devicetree is evaluated correctly and cfg->requires_ulbpr_exist is set to 1.

    If CONFIG_SPI_NOR_SFDP_RUNTIME=y is used in the project configuration, it seems that requires_ulpbr from the devicetree is not evaluated and cfg->requires_ulbpr_exist stays 0.

    The reason for that seems to be (line 1678):

    #define GENERATE_CONFIG_STRUCT(idx)								\
    	static const struct spi_nor_config spi_nor_##idx##_config = {				\
    		.spi = SPI_DT_SPEC_INST_GET(idx, SPI_WORD_SET(8), CONFIG_SPI_NOR_CS_WAIT_DELAY),\
    		COND_CODE_1(CONFIG_SPI_NOR_SFDP_RUNTIME, EMPTY(), (INST_CONFIG_STRUCT_GEN(idx)))};

    So INST_CONFIG_STRUCT_GEN(idx), which would set cfg->requires_ulbpr_exist according to the device tree, is not called if CONFIG_SPI_NOR_SFDP_RUNTIME is used. But there also does not seem to be any other way to provide the information that ulbpr command is required to the spi nor driver at runtime.

Related