mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +03:00
Merge pull request #3590 from martinbudden/bf_flash_config
Configurable FLASH
This commit is contained in:
commit
94e3273415
3 changed files with 32 additions and 25 deletions
|
@ -30,4 +30,5 @@ typedef struct flashGeometry_s {
|
||||||
|
|
||||||
typedef struct flashConfig_s {
|
typedef struct flashConfig_s {
|
||||||
ioTag_t csTag;
|
ioTag_t csTag;
|
||||||
|
uint8_t spiDevice;
|
||||||
} flashConfig_t;
|
} flashConfig_t;
|
||||||
|
|
|
@ -51,8 +51,11 @@
|
||||||
#define JEDEC_ID_WINBOND_W25Q128 0xEF4018
|
#define JEDEC_ID_WINBOND_W25Q128 0xEF4018
|
||||||
#define JEDEC_ID_MACRONIX_MX25L25635E 0xC22019
|
#define JEDEC_ID_MACRONIX_MX25L25635E 0xC22019
|
||||||
|
|
||||||
#define DISABLE_M25P16 IOHi(m25p16CsPin); __NOP()
|
#define DISABLE_M25P16 IOHi(bus->busdev_u.spi.csnPin); __NOP()
|
||||||
#define ENABLE_M25P16 __NOP(); IOLo(m25p16CsPin)
|
#define ENABLE_M25P16 __NOP(); IOLo(bus->busdev_u.spi.csnPin)
|
||||||
|
|
||||||
|
static busDevice_t busInstance;
|
||||||
|
static busDevice_t *bus;
|
||||||
|
|
||||||
// The timeout we expect between being able to issue page program instructions
|
// The timeout we expect between being able to issue page program instructions
|
||||||
#define DEFAULT_TIMEOUT_MILLIS 6
|
#define DEFAULT_TIMEOUT_MILLIS 6
|
||||||
|
@ -63,8 +66,6 @@
|
||||||
|
|
||||||
static flashGeometry_t geometry = {.pageSize = M25P16_PAGESIZE};
|
static flashGeometry_t geometry = {.pageSize = M25P16_PAGESIZE};
|
||||||
|
|
||||||
static IO_t m25p16CsPin = IO_NONE;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Whether we've performed an action that could have made the device busy for writes.
|
* Whether we've performed an action that could have made the device busy for writes.
|
||||||
*
|
*
|
||||||
|
@ -79,7 +80,7 @@ static void m25p16_performOneByteCommand(uint8_t command)
|
||||||
{
|
{
|
||||||
ENABLE_M25P16;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
spiTransferByte(M25P16_SPI_INSTANCE, command);
|
spiTransferByte(bus->busdev_u.spi.instance, command);
|
||||||
|
|
||||||
DISABLE_M25P16;
|
DISABLE_M25P16;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,7 @@ static uint8_t m25p16_readStatus(void)
|
||||||
|
|
||||||
ENABLE_M25P16;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, command, in, sizeof(command));
|
spiTransfer(bus->busdev_u.spi.instance, command, in, sizeof(command));
|
||||||
|
|
||||||
DISABLE_M25P16;
|
DISABLE_M25P16;
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ static bool m25p16_readIdentification(void)
|
||||||
|
|
||||||
ENABLE_M25P16;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, out, in, sizeof(out));
|
spiTransfer(bus->busdev_u.spi.instance, out, in, sizeof(out));
|
||||||
|
|
||||||
// Clearing the CS bit terminates the command early so we don't have to read the chip UID:
|
// Clearing the CS bit terminates the command early so we don't have to read the chip UID:
|
||||||
DISABLE_M25P16;
|
DISABLE_M25P16;
|
||||||
|
@ -216,20 +217,23 @@ bool m25p16_init(const flashConfig_t *flashConfig)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bus = &busInstance;
|
||||||
|
bus->bustype = BUSTYPE_SPI;
|
||||||
|
spiBusSetInstance(bus, spiInstanceByDevice(SPI_CFG_TO_DEV(flashConfig->spiDevice)));
|
||||||
if (flashConfig->csTag) {
|
if (flashConfig->csTag) {
|
||||||
m25p16CsPin = IOGetByTag(flashConfig->csTag);
|
bus->busdev_u.spi.csnPin = IOGetByTag(flashConfig->csTag);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOInit(m25p16CsPin, OWNER_FLASH_CS, 0);
|
IOInit(bus->busdev_u.spi.csnPin, OWNER_FLASH_CS, 0);
|
||||||
IOConfigGPIO(m25p16CsPin, SPI_IO_CS_CFG);
|
IOConfigGPIO(bus->busdev_u.spi.csnPin, SPI_IO_CS_CFG);
|
||||||
|
|
||||||
DISABLE_M25P16;
|
DISABLE_M25P16;
|
||||||
|
|
||||||
#ifndef M25P16_SPI_SHARED
|
#ifndef M25P16_SPI_SHARED
|
||||||
//Maximum speed for standard READ command is 20mHz, other commands tolerate 25mHz
|
//Maximum speed for standard READ command is 20mHz, other commands tolerate 25mHz
|
||||||
spiSetDivisor(M25P16_SPI_INSTANCE, SPI_CLOCK_FAST);
|
spiSetDivisor(bus->busdev_u.spi.instance, SPI_CLOCK_FAST);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return m25p16_readIdentification();
|
return m25p16_readIdentification();
|
||||||
|
@ -248,7 +252,7 @@ void m25p16_eraseSector(uint32_t address)
|
||||||
|
|
||||||
ENABLE_M25P16;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, out, NULL, sizeof(out));
|
spiTransfer(bus->busdev_u.spi.instance, out, NULL, sizeof(out));
|
||||||
|
|
||||||
DISABLE_M25P16;
|
DISABLE_M25P16;
|
||||||
}
|
}
|
||||||
|
@ -272,12 +276,12 @@ void m25p16_pageProgramBegin(uint32_t address)
|
||||||
|
|
||||||
ENABLE_M25P16;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, command, NULL, sizeof(command));
|
spiTransfer(bus->busdev_u.spi.instance, command, NULL, sizeof(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
void m25p16_pageProgramContinue(const uint8_t *data, int length)
|
void m25p16_pageProgramContinue(const uint8_t *data, int length)
|
||||||
{
|
{
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, data, NULL, length);
|
spiTransfer(bus->busdev_u.spi.instance, data, NULL, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void m25p16_pageProgramFinish(void)
|
void m25p16_pageProgramFinish(void)
|
||||||
|
@ -327,8 +331,8 @@ int m25p16_readBytes(uint32_t address, uint8_t *buffer, int length)
|
||||||
|
|
||||||
ENABLE_M25P16;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, command, NULL, sizeof(command));
|
spiTransfer(bus->busdev_u.spi.instance, command, NULL, sizeof(command));
|
||||||
spiTransfer(M25P16_SPI_INSTANCE, NULL, buffer, length);
|
spiTransfer(bus->busdev_u.spi.instance, NULL, buffer, length);
|
||||||
|
|
||||||
DISABLE_M25P16;
|
DISABLE_M25P16;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "config/parameter_group_ids.h"
|
#include "config/parameter_group_ids.h"
|
||||||
|
|
||||||
#include "drivers/accgyro/accgyro.h"
|
#include "drivers/accgyro/accgyro.h"
|
||||||
|
#include "drivers/bus_spi.h"
|
||||||
#include "drivers/compass/compass.h"
|
#include "drivers/compass/compass.h"
|
||||||
#include "drivers/inverter.h"
|
#include "drivers/inverter.h"
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
|
@ -168,16 +169,17 @@ PG_REGISTER_WITH_RESET_FN(ppmConfig_t, ppmConfig, PG_PPM_CONFIG, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FLASHFS
|
#ifdef USE_FLASHFS
|
||||||
PG_REGISTER_WITH_RESET_TEMPLATE(flashConfig_t, flashConfig, PG_FLASH_CONFIG, 0);
|
PG_REGISTER_WITH_RESET_FN(flashConfig_t, flashConfig, PG_FLASH_CONFIG, 0);
|
||||||
#ifdef M25P16_CS_PIN
|
|
||||||
#define FLASH_CONFIG_CSTAG IO_TAG(M25P16_CS_PIN)
|
|
||||||
#else
|
|
||||||
#define FLASH_CONFIG_CSTAG IO_TAG_NONE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PG_RESET_TEMPLATE(flashConfig_t, flashConfig,
|
void pgResetFn_flashConfig(flashConfig_t *flashConfig)
|
||||||
.csTag = FLASH_CONFIG_CSTAG
|
{
|
||||||
);
|
#ifdef M25P16_CS_PIN
|
||||||
|
flashConfig->csTag = IO_TAG(M25P16_CS_PIN);
|
||||||
|
#else
|
||||||
|
flashConfig->csTag = IO_TAG_NONE;
|
||||||
|
#endif
|
||||||
|
flashConfig->spiDevice = SPI_DEV_TO_CFG(spiDeviceByInstance(M25P16_SPI_INSTANCE));
|
||||||
|
}
|
||||||
#endif // USE_FLASH_FS
|
#endif // USE_FLASH_FS
|
||||||
|
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue