mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +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:
parent
e9269507ae
commit
b3053be4dd
42 changed files with 2445 additions and 206 deletions
|
@ -47,6 +47,7 @@
|
|||
#include "drivers/adc.h"
|
||||
#include "drivers/bus.h"
|
||||
#include "drivers/bus_i2c.h"
|
||||
#include "drivers/bus_octospi.h"
|
||||
#include "drivers/bus_quadspi.h"
|
||||
#include "drivers/bus_spi.h"
|
||||
#include "drivers/buttons.h"
|
||||
|
@ -195,8 +196,7 @@ void busSwitchInit(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void configureSPIAndQuadSPI(void)
|
||||
static void configureSPIBusses(void)
|
||||
{
|
||||
#ifdef USE_SPI
|
||||
spiPinConfigure(spiPinConfig(0));
|
||||
|
@ -226,7 +226,10 @@ static void configureSPIAndQuadSPI(void)
|
|||
spiInit(SPIDEV_6);
|
||||
#endif
|
||||
#endif // USE_SPI
|
||||
}
|
||||
|
||||
static void configureQuadSPIBusses(void)
|
||||
{
|
||||
#ifdef USE_QUADSPI
|
||||
quadSpiPinConfigure(quadSpiConfig(0));
|
||||
|
||||
|
@ -236,6 +239,15 @@ static void configureSPIAndQuadSPI(void)
|
|||
#endif // USE_QUAD_SPI
|
||||
}
|
||||
|
||||
static void configureOctoSPIBusses(void)
|
||||
{
|
||||
#ifdef USE_OCTOSPI
|
||||
#ifdef USE_OCTOSPI_DEVICE_1
|
||||
octoSpiInit(OCTOSPIDEV_1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_SDCARD
|
||||
static void sdCardAndFSInit(void)
|
||||
{
|
||||
|
@ -291,9 +303,10 @@ void init(void)
|
|||
#endif
|
||||
|
||||
enum {
|
||||
FLASH_INIT_ATTEMPTED = (1 << 0),
|
||||
SD_INIT_ATTEMPTED = (1 << 1),
|
||||
SPI_AND_QSPI_INIT_ATTEMPTED = (1 << 2),
|
||||
FLASH_INIT_ATTEMPTED = (1 << 0),
|
||||
SD_INIT_ATTEMPTED = (1 << 1),
|
||||
SPI_BUSSES_INIT_ATTEMPTED = (1 << 2),
|
||||
QUAD_OCTO_SPI_BUSSES_INIT_ATTEMPTED = (1 << 3),
|
||||
};
|
||||
uint8_t initFlags = 0;
|
||||
|
||||
|
@ -303,19 +316,17 @@ void init(void)
|
|||
// Config in sdcard presents an issue with pin configuration since the pin and sdcard configs for the
|
||||
// sdcard are in the config which is on the sdcard which we can't read yet!
|
||||
//
|
||||
// FIXME We need to add configuration somewhere, e.g. bootloader image or reserved flash area, that can be read by the firmware.
|
||||
// it's currently possible for the firmware resource allocation to be wrong after the config is loaded if the user changes the settings.
|
||||
// This would cause undefined behaviour once the config is loaded. so for now, users must NOT change sdio/spi configs needed for
|
||||
// the system to boot and/or to save the config.
|
||||
// FIXME For now, users must NOT change flash/pin configs needed for the system to boot and/or to save the config.
|
||||
// One possible solution is to lock the pins for the flash chip so they cannot be modified post-boot.
|
||||
//
|
||||
// note that target specific SDCARD/SDIO/SPI/QUADSPI configs are
|
||||
// note that target specific SDCARD/SDIO/SPI/QUADSPI/OCTOSPI configs are
|
||||
// also not supported in USE_TARGET_CONFIG/targetConfigure() when using CONFIG_IN_SDCARD.
|
||||
//
|
||||
|
||||
//
|
||||
// IMPORTANT: all default flash and pin configurations must be valid for the target after pgResetAll() is called.
|
||||
// Target designers must ensure other devices connected the same SPI/QUADSPI interface as the flash chip do not
|
||||
// cause communication issues with the flash chip. e.g. use external pullups on SPI/QUADSPI CS lines.
|
||||
// Target designers must ensure other devices connected the same SPI/QUADSPI/OCTOSPI interface as the flash chip do not
|
||||
// cause communication issues with the flash chip. e.g. use external pullups on SPI/QUADSPI/OCTOSPI CS lines.
|
||||
//
|
||||
|
||||
#ifdef TARGET_BUS_INIT
|
||||
|
@ -325,8 +336,8 @@ void init(void)
|
|||
pgResetAll();
|
||||
|
||||
#ifdef USE_SDCARD_SPI
|
||||
configureSPIAndQuadSPI();
|
||||
initFlags |= SPI_AND_QSPI_INIT_ATTEMPTED;
|
||||
configureSPIBusses();
|
||||
initFlags |= SPI_BUSSES_INIT_ATTEMPTED;
|
||||
#endif
|
||||
|
||||
sdCardAndFSInit();
|
||||
|
@ -346,37 +357,42 @@ void init(void)
|
|||
|
||||
#endif // CONFIG_IN_SDCARD
|
||||
|
||||
#ifdef CONFIG_IN_EXTERNAL_FLASH
|
||||
#if defined(CONFIG_IN_EXTERNAL_FLASH) || defined(CONFIG_IN_MEMORY_MAPPED_FLASH)
|
||||
//
|
||||
// Config on external flash presents an issue with pin configuration since the pin and flash configs for the
|
||||
// external flash are in the config which is on a chip which we can't read yet!
|
||||
//
|
||||
// FIXME We need to add configuration somewhere, e.g. bootloader image or reserved flash area, that can be read by the firmware.
|
||||
// it's currently possible for the firmware resource allocation to be wrong after the config is loaded if the user changes the settings.
|
||||
// This would cause undefined behaviour once the config is loaded. so for now, users must NOT change flash/pin configs needed for
|
||||
// the system to boot and/or to save the config.
|
||||
// FIXME For now, users must NOT change flash/pin configs needed for the system to boot and/or to save the config.
|
||||
// One possible solution is to lock the pins for the flash chip so they cannot be modified post-boot.
|
||||
//
|
||||
// note that target specific FLASH/SPI/QUADSPI configs are
|
||||
// also not supported in USE_TARGET_CONFIG/targetConfigure() when using CONFIG_IN_EXTERNAL_FLASH.
|
||||
// note that target specific FLASH/SPI/QUADSPI/OCTOSPI configs are
|
||||
// also not supported in USE_TARGET_CONFIG/targetConfigure() when using CONFIG_IN_EXTERNAL_FLASH/CONFIG_IN_MEMORY_MAPPED_FLASH.
|
||||
//
|
||||
|
||||
//
|
||||
// IMPORTANT: all default flash and pin configurations must be valid for the target after pgResetAll() is called.
|
||||
// Target designers must ensure other devices connected the same SPI/QUADSPI interface as the flash chip do not
|
||||
// cause communication issues with the flash chip. e.g. use external pullups on SPI/QUADSPI CS lines.
|
||||
// Target designers must ensure other devices connected the same SPI/QUADSPI/OCTOSPI interface as the flash chip do not
|
||||
// cause communication issues with the flash chip. e.g. use external pullups on SPI/QUADSPI/OCTOSPI CS lines.
|
||||
//
|
||||
pgResetAll();
|
||||
|
||||
#ifdef TARGET_BUS_INIT
|
||||
#error "CONFIG_IN_EXTERNAL_FLASH and TARGET_BUS_INIT are mutually exclusive"
|
||||
#error "CONFIG_IN_EXTERNAL_FLASH/CONFIG_IN_MEMORY_MAPPED_FLASH and TARGET_BUS_INIT are mutually exclusive"
|
||||
#endif
|
||||
|
||||
configureSPIAndQuadSPI();
|
||||
initFlags |= SPI_AND_QSPI_INIT_ATTEMPTED;
|
||||
#if defined(CONFIG_IN_EXTERNAL_FLASH)
|
||||
configureSPIBusses();
|
||||
initFlags |= SPI_BUSSES_INIT_ATTEMPTED;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_IN_MEMORY_MAPPED_FLASH) || defined(CONFIG_IN_EXTERNAL_FLASH)
|
||||
configureQuadSPIBusses();
|
||||
configureOctoSPIBusses();
|
||||
initFlags |= QUAD_OCTO_SPI_BUSSES_INIT_ATTEMPTED;
|
||||
#endif
|
||||
|
||||
#ifndef USE_FLASH_CHIP
|
||||
#error "CONFIG_IN_EXTERNAL_FLASH requires USE_FLASH_CHIP to be defined."
|
||||
#error "CONFIG_IN_EXTERNAL_FLASH/CONFIG_IN_MEMORY_MAPPED_FLASH requires USE_FLASH_CHIP to be defined."
|
||||
#endif
|
||||
|
||||
bool haveFlash = flashInit(flashConfig());
|
||||
|
@ -386,7 +402,8 @@ void init(void)
|
|||
}
|
||||
initFlags |= FLASH_INIT_ATTEMPTED;
|
||||
|
||||
#endif // CONFIG_IN_EXTERNAL_FLASH
|
||||
#endif // CONFIG_IN_EXTERNAL_FLASH || CONFIG_IN_MEMORY_MAPPED_FLASH
|
||||
|
||||
|
||||
initEEPROM();
|
||||
|
||||
|
@ -588,10 +605,16 @@ void init(void)
|
|||
|
||||
#else
|
||||
|
||||
// Depending on compilation options SPI/QSPI initialisation may already be done.
|
||||
if (!(initFlags & SPI_AND_QSPI_INIT_ATTEMPTED)) {
|
||||
configureSPIAndQuadSPI();
|
||||
initFlags |= SPI_AND_QSPI_INIT_ATTEMPTED;
|
||||
// Depending on compilation options SPI/QSPI/OSPI initialisation may already be done.
|
||||
if (!(initFlags & SPI_BUSSES_INIT_ATTEMPTED)) {
|
||||
configureSPIBusses();
|
||||
initFlags |= SPI_BUSSES_INIT_ATTEMPTED;
|
||||
}
|
||||
|
||||
if (!(initFlags & QUAD_OCTO_SPI_BUSSES_INIT_ATTEMPTED)) {
|
||||
configureQuadSPIBusses();
|
||||
configureOctoSPIBusses();
|
||||
initFlags |= QUAD_OCTO_SPI_BUSSES_INIT_ATTEMPTED;
|
||||
}
|
||||
|
||||
#if defined(USE_SDCARD_SDIO) && !defined(CONFIG_IN_SDCARD) && defined(STM32H7)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue