[ion/f730] Shutdown external flash

This commit is contained in:
Ruben Dashyan
2019-01-14 16:43:49 +01:00
parent 7ea87cf56f
commit ad9d89a756
3 changed files with 38 additions and 3 deletions

View File

@@ -228,6 +228,7 @@ void shutdownPeripherals(bool keepLEDAwake) {
#if USE_SD_CARD
SDCard::Device::shutdown();
#endif
ExternalFlash::Device::shutdown();
USB::Device::shutdown();
Battery::Device::shutdown();
if (!keepLEDAwake) {

View File

@@ -1,4 +1,5 @@
#include "external_flash.h"
#include "timing.h"
namespace Ion {
namespace ExternalFlash {
@@ -205,6 +206,12 @@ void init() {
initChip();
}
void shutdown() {
shutdownChip();
shutdownQSPI();
shutdownGPIO();
}
void initGPIO() {
for(const GPIOPin & g : QSPIPins) {
g.group().OSPEEDR()->setOutputSpeed(g.pin(), GPIO::OSPEEDR::OutputSpeed::High);
@@ -213,9 +220,17 @@ void initGPIO() {
}
}
void shutdownGPIO() {
for(const GPIOPin & g : QSPIPins) {
g.group().OSPEEDR()->setOutputSpeed(g.pin(), GPIO::OSPEEDR::OutputSpeed::Low);
g.group().MODER()->setMode(g.pin(), GPIO::MODER::Mode::Analog);
g.group().PUPDR()->setPull(g.pin(), GPIO::PUPDR::Pull::None);
}
}
void initQSPI() {
// Enable QUADSPI AHB3 peripheral clock
RCC.AHB3ENR()->setQSPIEN(true);
RCC.AHB3ENR()->setQSPIEN(true); // TODO: move in Device::initClocks
// Configure controller for target device
class QUADSPI::DCR dcr(0);
dcr.setFSIZE(NumberOfAddressBitsInChip - 1);
@@ -228,10 +243,15 @@ void initQSPI() {
QUADSPI.CR()->set(cr);
}
void shutdownQSPI() {
RCC.AHB3ENR()->setQSPIEN(false); // TODO: move in Device::shutdownClocks
}
void initChip() {
static bool firstPass = true;
/* The chip initially expects commands in SPI mode. We need to use SPI to tell
* it to switch to QPI. */
if (DefaultOperatingMode == QUADSPI::CCR::OperatingMode::Quad) {
if (firstPass && DefaultOperatingMode == QUADSPI::CCR::OperatingMode::Quad) {
send_command(Command::WriteEnable, QUADSPI::CCR::OperatingMode::Single);
ExternalFlashStatusRegister::StatusRegister2 statusRegister2(0);
statusRegister2.setQE(true);
@@ -252,10 +272,19 @@ void initChip() {
readParameters.setP5(true);
send_write_command(Command::SetReadParameters, reinterpret_cast<uint8_t *>(FlashAddressSpaceSize), reinterpret_cast<uint8_t *>(&readParameters), sizeof(readParameters));
}
firstPass = false;
} else {
// TODO
}
set_as_memory_mapped();
}
void shutdownChip() {
unset_memory_mapped_mode();
send_command(Command::DeepPowerDown);
Timing::usleep(100); // TODO should be 3us when usleep adjusted
}
int SectorAtAddress(uint32_t address) {
int i = address >> NumberOfAddressBitsIn64KbyteBlock;
if (i >= NumberOfSectors) {

View File

@@ -36,8 +36,11 @@ void init();
void shutdown();
void initGPIO();
void shutdownGPIO();
void initQSPI();
void shutdownQSPI();
void initChip();
void shutdownChip();
void MassErase();
@@ -61,7 +64,9 @@ enum class Command : uint8_t {
// Erase the whole chip or a 64-Kbyte block as being "1"
ChipErase = 0xC7,
Erase64KbyteBlock = 0xD8,
SetReadParameters = 0xC0
SetReadParameters = 0xC0,
DeepPowerDown = 0xB9,
ReleaseDeepPowerDown = 0xAB
};
constexpr static uint32_t QSPIBaseAddress = 0x90000000;