# The type auto-detection of a SPI memory device connected via SPIMCTRL

**URL:** <https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436>\
**Category:** General - Software\
**Created:** [14 October 2024 04:51 UTC](https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436 "2024-10-14T04:51:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WEI](https://avatars.discourse-cdn.com/v4/letter/w/90ced4/32.png) [@WEI](https://discourse.grlib.community/u/WEI)\
**Post date:** [14 October 2024 04:51 UTC](https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436/1 "2024-10-14T04:51:51Z")

</div>

Does anyone have experience using the ‘spim’ command ?

In my operation, the auto-detection command is failed.

```auto
grmon3> spim flash detect
  Got manufacturer ID 0x00 and device ID 0x0000
  Could not find matching device!

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000008
      0xfff00008 Status register 0x000000c4
      0xfff0000c Receive register 0x00000000
      0xfff00010 Transmit register 0x00000000

```

In addition, other commands also failed, such as

```auto
grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000001
      0xfff00008 Status register 0x000000c4
      0xfff0000c Receive register 0x00000000
      0xfff00010 Transmit register 0x00000000

grmon3> spim tx 0x9F
  Core not initialized!

```

But I can successfully read the device ID value through direct I/O register operations.

```auto
grmon3> spim reset
  SPIM memory controller has been reset

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000008
      0xfff00008 Status register 0x000000c4
      0xfff0000c Receive register 0x00000018
      0xfff00010 Transmit register 0x00000000

grmon3> wmem 0xfff00004 0x1

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000001 --> enable Chip select (CSN) and User control (USRC)
      0xfff00008 Status register 0x000000c4
      0xfff0000c Receive register 0x00000018
      0xfff00010 Transmit register 0x00000000

grmon3> wmem 0xfff00010 0x9F --> issue read ID command (RDID)

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000001
      0xfff00008 Status register 0x000000c5
      0xfff0000c Receive register 0x00000000
      0xfff00010 Transmit register 0x00000000

grmon3> wmem 0xfff00010 0x00 --> issue dummy byte

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000001
      0xfff00008 Status register 0x000000c5
      0xfff0000c Receive register 0x00000020 --> 1st Byte, Manufacturer Identification
      0xfff00010 Transmit register 0x00000000

grmon3> wmem 0xfff00010 0x00

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000001
      0xfff00008 Status register 0x000000c5
      0xfff0000c Receive register 0x00000020 --> 2nd Byte, Device Identification: Memory Type
      0xfff00010 Transmit register 0x00000000

grmon3> wmem 0xfff00010 0x00

grmon3> info reg spim0
  SPI Memory Controller
      0xfff00000 Configuration register 0x02000003
      0xfff00004 Control register 0x00000001
      0xfff00008 Status register 0x000000c5
      0xfff0000c Receive register 0x00000018 --> 3rd Byte, Device Identification: Memory Capacity
      0xfff00010 Transmit register 0x00000000

grmon3>

```

---

<div class="post-metadata">

**Author:** ![Axel](https://dub1.discourse-cdn.com/flex017/user_avatar/discourse.grlib.community/axel/32/87_2.png) [@Axel](https://discourse.grlib.community/u/Axel)\
**Post date:** [14 October 2024 08:18 UTC](https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436/2 "2024-10-14T08:18:31Z")

</div>

Hello Wei,

That indeed looks strange.  
In particular the `Core not initialized!` message you are getting for the `spim tx` command, which should only happen if the `init` bit in the status register was not set when GRMON tries to read the status register just before starting the command. That bit has however been hardwired to a value of ‘1’ in the SPIMCTRL IP for some time now, so this scenario in GRMON should theoretically never happen if everything in the hardware is working as it should.

The reason to why the `spim flash detect` command doesn’t work is probably because it encounters the same problem when checking the `init` bit. For the `spim flash detect` command there is no printout when this problem occurs, instead it just silently fails.

I see that for your `info reg spim0` the init bit is set, which is promising. Can you think of any reason to why GRMON might have not read that bit as ‘1’ earlier? E.g., instabilities in the hardware or local modifications to the SPIMCTRL IP?

Best regards,  
Axel

---

<div class="post-metadata">

**Author:** ![WEI](https://avatars.discourse-cdn.com/v4/letter/w/90ced4/32.png) [@WEI](https://discourse.grlib.community/u/WEI)\
**Post date:** [14 October 2024 16:17 UTC](https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436/3 "2024-10-14T16:17:49Z")

</div>

Hi Axel, thank you for your response.

I am using the original IP, the init bit is fixed to ‘1’.

```auto
514 when STAT_REG_OFF =>
515 v.rrdata(7) := to_ulogic(allow_writes);
516 v.rrdata(6) := to_ulogic(reconf);
517 v.rrdata(2) := '1';
518 v.rrdata(1) := r.reg.stat.busy;
519 v.rrdata(0) := r.reg.stat.done;

```

The issue seems to lie in GRMON itself.

---

<div class="post-metadata">

**Author:** ![arvid](https://dub1.discourse-cdn.com/flex017/user_avatar/discourse.grlib.community/arvid/32/12_2.png) [@arvid](https://discourse.grlib.community/u/arvid)\
**Post date:** [16 October 2024 06:04 UTC](https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436/4 "2024-10-16T06:04:52Z")

</div>

We have found an issue in GRMON. It will be fixed in the next release. I will try to make one this week or next.

---

<div class="post-metadata">

**Author:** ![WEI](https://avatars.discourse-cdn.com/v4/letter/w/90ced4/32.png) [@WEI](https://discourse.grlib.community/u/WEI)\
**Post date:** [18 October 2024 01:03 UTC](https://discourse.grlib.community/t/the-type-auto-detection-of-a-spi-memory-device-connected-via-spimctrl/436/5 "2024-10-18T01:03:49Z")

</div>

The new version is working, thanks for your work.

```auto
grmon3> spim flash detect
  Got manufacturer ID 0xc2 and device ID 0x201a
  Detected device: Macronix MX25L51245G

grmon3> spim flash show
  Current Flash/EEPROM device config:
    Name Macronix MX25L51245G
    Page size 256 bytes
    Number of bytes in address 3
    Allow erase command Yes
    Can use FAST READ command Yes
    FAST READ requires dummy byte Yes
    Area 0 sector count 16384
    Area 0 bytes per sector 4096

  Command set:
    Write Enable 0x06
    Write Disable 0x04
    Read status register 0x05
    Write status register 0x01
    Read data bytes 0x03
    Read data bytes at higher speed 0x0b
    Page program 0x02
    Sector erase 0x20
    Bulk/die erase 0x60
    Bulk/die erase command bytes 0x01

grmon3>

```
