Marzogh / SPIMemory

Arduino library for Flash Memory Chips (SPI based only). Formerly SPIFlash
http://spimemory.readthedocs.io/en/latest/
GNU General Public License v3.0
435 stars 138 forks source link

Bug report - *SPI Flash W25Q128 not working using SPI2 on STM32F103C8T6 (Blue Pill) or STM32F401CCU (Black Pill)* #209

Open delgadosouza opened 4 years ago

delgadosouza commented 4 years ago

Describe the bug When using the SPI Flash W25Q128 on the second SPI port of both the variants BluePill and BlackPill the code compiles but the chip is not recognized.

To Reproduce I used the Arduino_Core_STM32 by stm32duino. To make sure the frequency wasn't too high I changed the "defines.h" file of the library SPIMemory. I edited the frequency for non ESP32 boards:

#if defined (ARDUINO_ARCH_ESP32)
#define SPI_CLK       20000000        //Hz equivalent of 20MHz
#else
#define SPI_CLK       1000000       //Was 104000000
#endif

Also I had to define the ARCH_STM32 flag that was used by the library but not set by the core.

#define ARCH_STM32 true // The library didn't recognize the archtecture by itself
#include<SPIMemory.h> // SPIMemory library v 3.2.0 by Marzogh

// SPI2
#define SPI2_MISO PB14
#define SPI2_MOSI PB15
#define SPI2_SCK PB13
#define SPI2_CS PB12

// SPI 1
#define SPI1_SCK PA5
#define SPI1_MOSI PA7
#define SPI1_MISO PA6
#define SPI1_CS PA4

// THE LINES BELOW WORK (wired to SPI1 instead of SPI2, of course)
//SPIClass my_SPI1(SPI1_MOSI,SPI1_MISO,SPI1_SCK,SPI1_CS);
//SPIFlash flash(SPI1_CS, &my_SPI1);

SPIClass my_SPI2(SPI2_MOSI,SPI2_MISO,SPI2_SCK,SPI2_CS);
SPIFlash flash(SPI2_CS, &my_SPI2);

void setup() {
  Serial.begin(115200);
  while (!Serial) ; // Wait for Serial monitor to open
  delay(50);

  flash.begin();
  delay(50);

  // Get ID
  uint32_t JEDEC = flash.getJEDECID();
  if (!JEDEC) {
    Serial.println("Check wiring.");
  } else {
    // Show ID
    Serial.print("JEDEC ID: 0x"); Serial.println(JEDEC, HEX);
    Serial.print("Man ID: 0x"); Serial.println(uint8_t(JEDEC >> 16), HEX);
    Serial.print("Memory ID: 0x"); Serial.println(uint8_t(JEDEC >> 8), HEX);
    Serial.print("Capacity: "); Serial.println(flash.getCapacity());
    Serial.print("Max Pages: "); Serial.println(flash.getMaxPage());
  }
}

void loop() {}

Answer on SPI 1: image

Answer on SPI 2: image

For some reason it didn't even print the "Check wiring." message...

Desktop (please complete the following information):

For Black Pill: image

Tried same cofigs on both Arduino IDE versions.

Board (please complete the following information):

Additional context I would like to use both the LCD ST7920 and the SPI Flash W25Q128, each one in a separate SPI. I have heard that the ST7920 controller doesn't play nicely with other devices on the same bus.

I reached out to the Arduino_Core_STM32 people and they said that their implementation of the SPI2 works fine on both boards.

Any help would be really apreciated! Thank you!