Problems with spi nor flash

Hi,

I have a custom board using a NRF52832. together with a SPI NOR Flash. I am having problems with the initialisation of the flash. I already tested my board with the spi_example.

In the Sample when executing device_is_ready(), it is always return "device not ready". This is because

dev->state->init_res = 22

and therefore

return dev->state->initialized && (dev->state->init_res == 0U);

returns false.

But If  I modify the sample and let it continue even if the device is not ready the erasing, writing and reading of the flash is successful.

My board has the possibility to turn on and off the supply voltage of the board to save power and this problem only appears to happen when the flash is connected to the voltage that can be switched on and off. If I connect it to supply voltage that is constantly turned on device_is_ready() always returns true.

Can you help me with this issue?

I am using ncs v.2.5.0

This is my devicetree definition of the spi and the flash:

[...]
aliases {
    spi-flash0 = &mx25r80;
};
[...]
&spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";
    cs-gpios =  < &gpio0 28 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi1_default>;
    pinctrl-1 = <&spi1_sleep>;
    pinctrl-names = "default", "sleep";
    mx25r80: mx25r8035f@0 {
        compatible = "jedec,spi-nor";
        label = "MX25R8035F";
        reg = <0>;
        spi-max-frequency = <8000000>;
        size = <0x800000>;
        jedec-id = [c2 28 14];
        sfdp-bfp = [
             e5 20 f1 ff  ff ff 7f 00  44 eb 08 6b  08 3b 04 bb
             ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
             10 d8 00 ff  23 72 f5 00  82 ed 04 b7  44 83 38 44
             30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
];
        has-dpd;
        t-enter-dpd = < 10000 >;
        t-exit-dpd = < 35000 >;
    };
};
  • Hi,

    As you are turning your power supply on/off, it might be that device is not powered when you check it, or the device might not have enough time to boot up before init functions are called. You could try to introduce some delay of few ms using wait function early in your application to check if this helps in fixing the problem.

    Best regards,
    Dejan


  • Hi Dejan,

    thanks for the quick response. Unfortunately a delay di not solve the problem. I added a delay of 5s but that had no effect on the outcome. The device was still not ready but the sample runs successfully

    Kind Regards

    Paul

  • Hi Paul,

    Device might not be ready at the time of checking. You could try to manage your power supply experimentally in a way that would ensure that your device is ready by giving the device enough time to become ready before checking its status.

    Best regards,
    Dejan

  • Hi Dejan,

    I did some more digging on my problem:

    I fond this post stating, that zephyr does the initialisation of the nor flash before boot up according to the device tree. Is there any possibility to prevent zephyr from doing that because my switching voltage is off by default.

    Is there a possibility to set an initial level of a GPIO in the device tree file?

    I further found out that the SPI peripheral is also initialized before my main function is executed leading to the problem that my Flash is back sourced because Mosi is driven high.

    Is there generally the possibility to define the order of the initialisation process in the main function?

    Kind Regards

    Paul

  • Hi Paul,

    You could perform modifications of the spi_nor driver located in the drivers\flash so that flash is powered on before you perform any operations on it. You would need to do this yourself.
    Another option would be to change default state of the switch by adding external pull-up to the GPIO power control signal.
    Regardless of which of 2 above-mentioned ways you choose, when you need to turn off the flash you would need to make sure that MOSI is not driven high. You could do that by switching down (uninitializing) SPI peripheral. Otherwise, flash would not be turned off. 

    Best regards,
    Dejan

Related