1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

OctoSPI and Memory Mapped Flash support (#11825)

* STM32H730/STM32H750 - Fix use of USE_LP_UART1 instead of USE_LPUART1.

* STM32H723 - Prepare for being able to build for using non-internal-flash
config storage.

* STM32H723 - Prepare for using non-default strings.

* STM32H723 - Disable 'use custom defaults' when using USE_EXST.

* STM32H723 - Disable CUSTOM_DEFAULTS_EXTENDED when EXST is used.

* OCTOSPI - Add initialisation code.

* Add support for RAM_CODE.

* STM32H730 - Add support for RAM_CODE via the .ram_code attribute.

* OCTOSPI - Proof-of-concept for disabling/enabling memory mapped mode on
a running system.

NOTE: The HAL libs are compiled into a memory mapped region, and this cannot be used for OctoSPI access when memory mapped mode is disabled.

* OCTOSPI - Drop HAL support after determining that it's not suitable for
the memory mapped flash use-case.

* OCTOSPI - Sometimes, when disabling memory map mode, the abort fails.
Handle this by disabling the OSPI peripheral first and re-enabling it
afterwards.

* SD/FLASH - Update comments regarding possible solutions to the catch-22
issue with SD/SPI/QUADSPI/OCTOSPI pin configurations.

* OCTOSPI - Use device instance directly.

* OCTOSPI - Prepare W25Q flash driver for octospi support.

* OCTOSPI - Add octospi flash detection.

Note: The method to detect flash chips is similar to the method used for
QUADSPI and as such the code was used as a base. However the initial
OCTOSPI implementation doesn't support the non-memory-mapped use-case so
the un-tested code is gated with `USE_OCTOSPI_EXPERIMENTAL`.

The key differences are:
* uses octospi api not quadspi api.
* flash chip clock speeds should not be changed for memory-mapped flash
chips, bootloader already set it correctly.
* only certain flash chips are capable of memory mapped support.

* W25Q - Ensure w25q128fv_readRegister returns 0 if the receive fails.

* OCTOSPI - Implement octoSpiTransmit1LINE, octoSpiReceive1LINE and
octoSpiReceive4LINES.

* OCTOSPI - Specify device from init.

* OCTOSPI - More fixes and work on init.

Current status is that memory mapped mode is disabled and flash chip is
detected, but w25q128fv_detect should not be calling w25q128fv_reset.

* FLASH - Add comment regarding wasted flash space on targets that only
use one bus type for the flash chip.

* FLASH - Split `detect` into `identify` and `configure`.

* OCTOSPI - Extract flashMemoryMappedModeEnable/Disable to separate
methods.

* FLASH - Reduce size of targets that don't support the use of multiple
flash interfaces.

* Single-flash-chip targets usually only support one type of io
interface.
* Without this, compiler warnings are generated in `flashSpiInit` for
targets that only use flash chip drivers that support quadspi or octospi
that don't even use SPI for flash.

* FLASH - Use MMFLASH_CODE/DATA to conditionally move code/data to RAM.

Only targets compiled to support memory mapped flash chips need the some
specific code in RAM.  Otherwise the code/data should be in the normal
linker section.

* FLASH - W25Q Prepare for memory mapped flash usage.

* Wait/Delay functions must work with interrupts disabled.
* Code used for reading/writing must run from RAM.

* OCTOSPI - Implement remaining required methods.

* OCTOSPI - Fixes for earlier code (not last commit).

* FLASH - W25Q update timeout values from Datasheet Rev L.

* FLASH - Prepare flash driver for use when memory mapped flash is
disabled.

* System - Prepare microsISR for use when memory mapped flash is disabled.

* FLASH - Add support for CONFIG_IN_MEMORY_MAPPED_FLASH.

* Flash - Fix incorrect gating on cli flash commands.

When compiling with USE_FLASH_CHIP and without USE_FLASHFS there were
compiler warnings.

* MMFLASH - Fix release-mode build.

* FLASH - Allow SPI pins to be reconfigured when using CONFIG_IN_MEMORY_MAPPED_FLASH.

MMFLASH only works via QuadSPI/OctoSPI peripherals.

* EXST - Disable the 2GB workaround which is now causing a different
error.

The error we get with 'remove-section' enabled is:

"error in private header data: sorry, cannot handle this file".  The
cause of this new error in the objcopy codebase is an out of memory
condition, somehow the 2GB files and this error are related but the root
cause of both is still unknown.

* OCTOSPI - Add support for STM32H723.

* STM32H723 - Add linker scripts for EXST usage.

* NucleoH723ZG - Add build script to demonstrate OCTOSPI and Memory Mapped
flash support.

* FLASH - WUse the size in bits to set the size of the buffer.

* FLASH - Fix typo in W25N driver defines.

Was using W28N instead of W25N

* OCTOSPI - Fix missing semilcolon when compiling without
USE_FLASH_MEMORY_MAPPED.

* OCTPSPI - Fix missing call to 'memoryMappedModeInit'.

* SPRacingH7RF - Add example build script to allow for testing prior to
unified target / cloud-build support.
This commit is contained in:
Dominic Clifton 2023-02-03 20:24:01 +01:00 committed by GitHub
parent e9269507ae
commit b3053be4dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 2445 additions and 206 deletions

View file

@ -22,6 +22,30 @@
* Author: jflyper
*/
/*
* Each flash chip should:
*
* * expose a public `identify` method.
* - return true if the driver supports the passed JEDEC ID and false otherwise.
* - configure the `geometry` member of the flashDevice_t or set all `geometry` members to 0 if driver doesn't support the JEDEC ID.
* - configure the `vTable` member, with an appropriate API.
* - configure remaining flashDevice_t members, as appropriate.
* * not reconfigure the bus or flash chip when in memory mapped mode.
* - the firmware is free to do whatever it wants when memory mapped mode is disabled
* - when memory mapped mode is restored, e.g. after saving config to external flash, it should be in
* the same state that firmware found it in before the firmware disabled memory mapped mode.
*
* When memory mapped mode is disabled the following applies to all flash chip drivers uses in a memory mapped system:
* - do not call any methods or use data from the flash chip. i.e. memory mapped code/data is INACCESSIBLE.
* i.e. when saving the config, *ALL* the code to erase a block and write data should be in RAM,
* this includes any `delay` methods.
* - not require the use of use any ISRs - interrupts are disabled during flash access when memory mapped mode is disabled.
*
* When compiling a driver for use in a memory mapped flash system the following applies:
* - the vTable must live in RAM so it can be used when memory mapped mode is disabled.
* - other constant data structures that usually live in flash memory must be stored in RAM.
* - methods used to erase sectors, write data and read data much live in RAM.
*/
#pragma once
#include "drivers/bus.h"
@ -32,20 +56,30 @@ struct flashVTable_s;
typedef enum {
FLASHIO_NONE = 0,
FLASHIO_SPI,
FLASHIO_QUADSPI
FLASHIO_QUADSPI,
FLASHIO_OCTOSPI,
} flashDeviceIoMode_e;
typedef struct flashDeviceIO_s {
union {
#ifdef USE_FLASH_SPI
extDevice_t *dev; // Device interface dependent handle (spi/i2c)
#ifdef USE_QUADSPI
#endif
#ifdef USE_FLASH_QUADSPI
QUADSPI_TypeDef *quadSpi;
#endif
#ifdef USE_FLASH_OCTOSPI
OCTOSPI_TypeDef *octoSpi;
#endif
} handle;
flashDeviceIoMode_e mode;
} flashDeviceIO_t;
typedef struct flashDevice_s {
//
// members to be configured by the flash chip implementation
//
const struct flashVTable_s *vTable;
flashGeometry_t geometry;
uint32_t currentWriteAddress;
@ -55,21 +89,33 @@ typedef struct flashDevice_s {
// when it is definitely ready already.
bool couldBeBusy;
uint32_t timeoutAt;
//
// members configured by the flash detection system, read-only from the flash chip implementation's perspective.
//
flashDeviceIO_t io;
void (*callback)(uint32_t arg);
uint32_t callbackArg;
} flashDevice_t;
typedef struct flashVTable_s {
void (*configure)(flashDevice_t *fdevice, uint32_t configurationFlags);
bool (*isReady)(flashDevice_t *fdevice);
bool (*waitForReady)(flashDevice_t *fdevice);
void (*eraseSector)(flashDevice_t *fdevice, uint32_t address);
void (*eraseCompletely)(flashDevice_t *fdevice);
void (*pageProgramBegin)(flashDevice_t *fdevice, uint32_t address, void (*callback)(uint32_t length));
uint32_t (*pageProgramContinue)(flashDevice_t *fdevice, uint8_t const **buffers, uint32_t *bufferSizes, uint32_t bufferCount);
void (*pageProgramFinish)(flashDevice_t *fdevice);
void (*pageProgram)(flashDevice_t *fdevice, uint32_t address, const uint8_t *data, uint32_t length, void (*callback)(uint32_t length));
void (*flush)(flashDevice_t *fdevice);
int (*readBytes)(flashDevice_t *fdevice, uint32_t address, uint8_t *buffer, uint32_t length);
const flashGeometry_t *(*getGeometry)(flashDevice_t *fdevice);
} flashVTable_t;