Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more stm32 support #248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

benjinne
Copy link

@benjinne benjinne commented Nov 28, 2022

Pull request details

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
  • [ x] Bug fix
  • [ x] Added feature
  • [ x] Documentation update

The stm32 defines needed updated.

This example code wouldn't compile:

#include "Arduino.h"
#include <SPI.h>
#include <SPIMemory.h>

#define MISO PB4
#define MOSI PB5
#define SCK  PB3
#define CS   PB0
SPIClass spiclass(MOSI, MISO, SCK);

SPIFlash flash(CS, &spiclass);

void setup() {
  SerialUSB.begin(115200);
  flash.setClock(20000000); //lower clock since default doesn't seem to work
  flash.begin(MB(2));
}

void loop() {
  uint16_t manID = flash.getJEDECID();
  SerialUSB.printf("manID %i \n\r", manID);
  delay(2000);
}

Due to SPIFlash.h being included before AARCH_STM32 was defined the code wouldn't compile:

src/main.cpp:11:29: error: no matching function for call to 'SPIFlash::SPIFlash(int, SPIClass*)'
   11 | SPIFlash flash(CS, &spiclass);
      |                             ^
In file included from .pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIMemory.h:75,
                 from src/main.cpp:3:
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:42:3: note: candidate: 'SPIFlash::SPIFlash(int8_t*)'
   42 |   SPIFlash(int8_t *SPIPinsArray);
      |   ^~~~~~~~
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:42:3: note:   candidate expects 1 argument, 2 provided
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:41:3: note: candidate: 'SPIFlash::SPIFlash(uint8_t)'
   41 |   SPIFlash(uint8_t cs = CS);
      |   ^~~~~~~~
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:41:3: note:   candidate expects 1 argument, 2 provided
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:32:7: note: candidate: 'constexpr SPIFlash::SPIFlash(const SPIFlash&)'
   32 | class SPIFlash {
      |       ^~~~~~~~
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:32:7: note:   candidate expects 1 argument, 2 provided
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:32:7: note: candidate: 'constexpr SPIFlash::SPIFlash(SPIFlash&&)'
.pio/libdeps/genericSTM32F407VET6/SPIMemory/src/SPIFlash.h:32:7: note:   candidate expects 1 argument, 2 provided
*** [.pio/build/genericSTM32F407VET6/src/main.cpp.o] Error 1

Also since this example is using a non-standard SPIClass, more ARCH_STM32 were needed so that the SPIFlash _spi object would be used instead of the generic SPI object

  • What is the new behavior? (if this is a feature change)
    Adds support for more STM32 boards like the one mentioned above.

  • Other information:


DO NOT DELETE OR EDIT anything below this

Note 1: Make sure to add all the information needed to understand the bug so that someone can help. If any essential information is missing we'll add the 'Needs more information' label and close the issue until there is enough information.

Note 2: For support questions (for example, tutorials on how to use the library), please use the Arduino Forums. This repository's issues are reserved for feature requests and bug reports.


GitHub issue state GitHub issue title GitHub issue author GitHub issue label GitHub issue comments GitHub issue age GitHub issue last updateGitHub pull request check contexts

@benjinne benjinne marked this pull request as draft November 28, 2022 14:29
@benjinne benjinne changed the title WIP:Pr fix stm32 defines Add more stm32 support Nov 28, 2022
@benjinne benjinne marked this pull request as ready for review November 28, 2022 18:13
@benjinne
Copy link
Author

Here's a fully working example from this branch:

#include "Arduino.h"
#include <SPI.h>
#include <SPIMemory.h>

#define MISO PB4
#define MOSI PB5
#define SCK  PB3
#define CS   PB0
SPIClass spiclass(MOSI, MISO, SCK);

SPIFlash flash(CS, &spiclass);

void setup() {
  SerialUSB.begin(115200);
  flash.setClock(20000000);
  flash.begin(MB(2));
}

void loop() {
  uint16_t manID = flash.getJEDECID();
  SerialUSB.printf("manID %i \n\r", manID);

  flash.eraseSector(0x03);
  if(flash.writeByte(0x03, 20)){ 
      SerialUSB.printf("write success!\n\r");
  }
  else
      SerialUSB.printf("Error.\n\r");
  uint8_t abyte = flash.readByte(0x03);
  SerialUSB.printf("abyte: %i\n\r", abyte);

  delay(2000);
}

output is:

manID 16405 
write success!
abyte: 20

chip included on the dev board is: https://stm32-base.org/assets/pdf/devices/W25Q16JV.pdf

@DprasK
Copy link

DprasK commented Aug 5, 2023

in my arduino IDE (SPIFlash.h) can't work. and can't compile. I added comment on SPIFlash.h file

//#if defined (ARDUINO_ARCH_SAMD) || defined(ARCH_STM32) || defined(ARDUINO_ARCH_ESP32)
// SPIFlash(uint8_t cs = CS, SPIClass *spiinterface=&SPI);
// #elif defined (BOARD_RTL8195A)
// SPIFlash(PinName cs = CS);
// #else
// SPIFlash(uint8_t cs = CS);
// SPIFlash(int8_t *SPIPinsArray);
// #endif
and add
SPIFlash(uint8_t cs = CS, SPIClass *spiinterface=&SPI);

and work, the skecth can upload to board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants