Hi.
Problem description
I'm currently using the MX25R64 as an external flash to perform FOTA over SPI on a custom board employing the nRF9160, which is working very well for the most part. However, I have some issues correctly configuring the power control to the flash chip in the dts-files. The external flash is placed within a power domain controlled by a GPIO, and the domain is turned on whenever the control pin is low. There are also other devices than the flash both within this power domain and on the SPI bus. Because I'm using the flash for FOTA, the power needs to be on before the application launches so MCUBoot can find the secondary image. Additionally, the SPI-driver can't have full control of the power domain since it's shared by other devices.
Current implementation and attempts
I'm currently achieving this by configuring the power control pin as a chip-select pin that is configured 'GPIO_ACTIVE_HIGH' (opposite of its real behavior), which makes the SPI-driver set the pin low when I'm using the flash. I have attached my current board files employing this method. This method works, strictly speaking, but it is a quick and dirty fix that breaks code coherency down the line. For instance, everyone working with the board have to remember that this particular power domain has reverse polarity. Also, reconfiguring the GPIO with 'gpio_pin_configure' after boot seems to break the SPI/flash driver, and regardless, it's confusing to have two different pin configurations in the project. Ideally, the pin should be configured correctly in the .dts files. I have tried to do this by specifying the correct pin configuration in 'supply-gpios
' for the MX25R64 entry in the dts file (jedec,spi-nor). However, the bootloader could not read the flash id when I did this, and this solution has the other problem that: "The supply state is entirely the responsibility of the device driver" when adding a supply gpio.
Solution?
What would be the correct way to approach this problem? A solution that would work for me is to configure the pin as its own entry in the .dts files, initialize it at a low level, and take manual control of it after boot. However, in that case it's important that I can rely 100% on the pin to be low at boot or the device can potentially be stuck in a boot-loop before the application is even launched.