This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading JEDEC ID External Flash

Hello,

 I have an external flash w25q32 spi nor flash. I tried to communicate with my flash using spi_nor driver code in zephery however it didn't detect the external flash saying "flash driver was not found" .The device get binding was returning false. Then I tried to just read the jedec id with spi_transceive. I am sending 9F command and dummy bytes to detect the jedec id however still I am not able to get the jedec id. You can see the logic analyzer output attached. The jedec id  has to be ef 40 16.

My main.c is:

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>

#include <sys/printk.h>

#include <drivers/spi.h>

//addition for combining blinky

static struct spi_config spi_cfg = {
  .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
  SPI_MODE_CPOL | SPI_MODE_CPHA,
  .frequency = 4000000,
  .slave = 0,
};

struct device * spi_dev;

static void spi_init(void) {
    const char *
      const spiName = "SPI_3";
    spi_dev = device_get_binding(spiName);

    if (spi_dev == NULL) {
      printk("Could not get %s device\n", spiName);
      return;
    }
}

void spi_test_send(void) {
  int err;
  //static u8_t tx_buffer[1];
  //static u8_t rx_buffer[1];
  static u8_t tx_buffer[5] = {
	0X9F,
        0x00,
        0x00,
        0x00,
        0x00
        

  };
  static u8_t rx_buffer[5];

  const struct spi_buf tx_buf = {
	.buf = tx_buffer,
	.len = sizeof(tx_buffer)
  };
  const struct spi_buf_set tx = {
	.buffers = & tx_buf,
	.count = 1
  };

  struct spi_buf rx_buf = {
	.buf = rx_buffer,
	.len = sizeof(rx_buffer),
  };
  const struct spi_buf_set rx = {
	.buffers = & rx_buf,
	.count = 1
  };

  struct device * gpio_dev;
  struct spi_cs_control cs_control;

  gpio_dev = device_get_binding("GPIO_0");
  if (!gpio_dev) {
	printk("could not find GPIO device\n");
	return;
  }

  gpio_pin_configure(gpio_dev,13,GPIO_OUTPUT_ACTIVE);
  gpio_pin_set(gpio_dev,13,0);
  err = spi_transceive(spi_dev, & spi_cfg, & tx, & rx);
  gpio_pin_set(gpio_dev,13,1);
  if (err) {
	printk("SPI error: %d\n", err);
  } else {
	/* Connect MISO to MOSI for loopback */

	for (int i = 0; i < sizeof(tx_buffer); i++) {
	  printk("TX transmit: %x\n", tx_buffer[i]);
	}

	for (int i = 0; i <sizeof(rx_buffer); i++) {
	  printk("RX recv: %x\n", rx_buffer[i]);
	}
  }
}

void main(void) {
  printk("SPIM Example\n");
  spi_init();
  printk("After init\n");
  while (1) {
	spi_test_send();
	k_sleep(K_MSEC(10));
	printk(".");
  }
}
,

my overlay is:

&spi3 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <10>;
	mosi-pin = <11>;
	miso-pin = <12>;
    //cs-gpios = <&gpio0 13 0>;

};

My proj.conf:

CONFIG_SPI=y
CONFIG_MAIN_STACK_SIZE=4096
# CONFIG_SPI_0=y
# UART, SPIM, and I2C are shared peripherals on nrf9160
# therefore we choose SPI3
CONFIG_SPI_3=y
CONFIG_SPI_NRFX=y
CONFIG_DEPRECATED_ZEPHYR_INT_TYPES=y

#addition for combining blinky
CONFIG_GPIO=y

The logic analyzer output is:

Can you help me with this issue. I couldn't understand why it is not working for detecting jedec id. Any help would be so helpful.

Thank you

Parents Reply Children
  • Hi,

    No, it is even not detecting the flash driver hence not moving any further in the code. The device get binding returns false thats why I wanted to try reading the jedec id on my own with SPİ transceive. I can't figure out what might be the proble  I tested the flash with another microcontroller and I was able to read the jedec id with the same process however even with the spi nor driver I am not able to read the jedec id for this flash with nrf9160. I can observe the signals in spi bus it is sending 9f but receiving meaningless values hence I am also sure that spi bus is working meaning my pins are working fine too.

    Thank you

  • You need to find out what is happening inside the spi_nor_configure() call. That happens when the driver is initialized, before main() is started. When you try to get the device binding the error has likely already occurred. So you need to step through the code where the driver is initialized.

  • Hi,

    I don't know how to find spi_nor_configure. I put the breakpoint before main and started debugging but it goes some functions(which is not spi_nor) and then returns. Can you guide me about this issue? Also the jedec id is not matching with the overlay hence device get binding returns false the problem is I can't read the jedec id properly.

    Thank you

  • verulia said:
    I put the breakpoint before main and started debugging but it goes some functions(which is not spi_nor) and then returns.

     Did you put the breakpoint inside spi_nor_configure()? Does it not enter spi_nor_configure() at all? You need to check this.

  • Hi Hakon,

    Yes I put the break points inside spi_nor_conf and it enters the function withouth any problem. The problem is I can see everything on pins clk,mosi, and cs however I see nothing in miso in logic analyzer and I am sure that miso pin is working. I am running out of time and trying to find a solution to my problem for months. So any help would be helpful.

    Thank you

Related