Open brightproject opened 1 year ago
I added in SPIFlash.cpp into function SPIFlash::initialize() code:
SPI.setMOSI(PB5);
SPI.setMISO(PB4);
SPI.setSCLK(PB3);
and got the following
boolean SPIFlash::initialize()
{
#if defined (SPCR) && defined (SPSR)
_SPCR = SPCR;
_SPSR = SPSR;
#endif
//reMAP pins from SPI to SPI3
SPI.setMOSI(PB5);
SPI.setMISO(PB4);
SPI.setSCLK(PB3);
pinMode(_slaveSelectPin, OUTPUT);
//divider not work
//SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.begin();
#ifdef SPI_HAS_TRANSACTION
_settings = SPISettings(10000000L, MSBFIRST, SPI_MODE0);// set 10 MHz(10000000 Hz), real 8 MHz
#endif
unselect();
wakeup();
if (_jedecID == 0 || readDeviceId() == _jedecID) {
command(SPIFLASH_STATUSWRITE, true); // Write Status Register
SPI.transfer(0); // Global Unprotect
unselect();
return true;
}
return false;
}
SPI frequency not work by DIVIDER. Worked during transaction only
Code from example worked with core stm32duino - https://github.com/stm32duino/Arduino_Core_STM32
Logic analizer image
Max CLK frequency - 8 Mhz for SPI_3, then :
_settings = SPISettings(10000000L, MSBFIRST, SPI_MODE0);// set 10 MHz(10000000 Hz), real 8 MHz
How to use this library for black pill STM32F401CCU6? The files SPIFlash.cpp and SPIFlash.h, as I understand it, are an "add-on" over the main SPI library from Arduino? I am using an arduino IDE and two cores to work with a microcontroller STM32F401CCU6. Each kernel folder has its own files with examples for working with SPI. Accordingly, I have three folders on the PC with the same file names in them:
#include <SPI.h>
Or rather, as far as I understand - depending on the selected kernel through the plan menu, such a file will be loaded during compilation. But these questions do not remove questions about how to work with external flash memory through the SPI2 and SPI3 interfaces, but rather add questions and confuse even more.