From 891f18cac7a36d1bb63cd4c140411f25d5c00146 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 2 Nov 2024 19:27:54 +0100 Subject: [PATCH] CS7000P: enabled NVM storage --- meson.build | 4 +++- platform/drivers/NVM/nvmem_CS7000.c | 28 +++++++++++++++++++++++++ platform/targets/CS7000-PLUS/hwconfig.c | 1 + platform/targets/CS7000-PLUS/hwconfig.h | 4 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 8f8ac86e..11496614 100644 --- a/meson.build +++ b/meson.build @@ -514,7 +514,9 @@ cs7000_def += openrtx_def + stm32f405_def ## ## Connect Systems CS70000-PLUS ## -cs7000p_src = ['platform/drivers/stubs/nvmem_stub.c', +cs7000p_src = ['platform/drivers/NVM/nvmem_CS7000.c', + 'platform/drivers/NVM/W25Qx.c', + 'platform/drivers/NVM/eeep.c', 'platform/drivers/stubs/cps_io_stub.c', 'platform/drivers/stubs/radio_stub.c', 'platform/drivers/stubs/audio_stub.c', diff --git a/platform/drivers/NVM/nvmem_CS7000.c b/platform/drivers/NVM/nvmem_CS7000.c index 798d68c2..ec80214b 100644 --- a/platform/drivers/NVM/nvmem_CS7000.c +++ b/platform/drivers/NVM/nvmem_CS7000.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,12 @@ static const struct W25QxCfg cfg = .cs = { FLASH_CS } }; +#ifdef PLATFORM_CS7000P +W25Qx_DEVICE_DEFINE(eflash, cfg, 0x2000000) // 32 MB, 256 Mbit +#else W25Qx_DEVICE_DEFINE(eflash, cfg, 0x1000000) // 16 MB, 128 Mbit +#endif + EEEP_DEVICE_DEFINE(eeep) const struct nvmPartition memPartitions[] = @@ -42,6 +48,16 @@ const struct nvmPartition memPartitions[] = .offset = 0x0000, // First partition, calibration and other OEM data .size = 32768 // 32kB }, +#ifdef PLATFORM_CS7000P + { + .offset = 0x1000000,// Second partition EEEP storage + .size = 16384 // 16kB + }, + { + .offset = 0x1000C000,// Third partition, available memory + .size = 0xFF4000 + } +#else { .offset = 0x8000, // Second partition EEEP storage .size = 16384 // 16kB @@ -50,6 +66,7 @@ const struct nvmPartition memPartitions[] = .offset = 0xC000, // Third partition, available memory .size = 0xFF4000 } +#endif }; static const struct nvmDescriptor extMem[] = @@ -73,7 +90,14 @@ static uint16_t vfoCrc; void nvm_init() { +#ifdef PLATFORM_CS7000P + gpio_setMode(FLASH_CLK, ALTERNATE | ALTERNATE_FUNC(5)); + gpio_setMode(FLASH_SDI, ALTERNATE | ALTERNATE_FUNC(5)); + gpio_setMode(FLASH_SDO, ALTERNATE | ALTERNATE_FUNC(5)); + spiStm32_init(&flash_spi, 25000000, 0); +#else spiBitbang_init(&flash_spi); +#endif W25Qx_init(&eflash); eeep_init(&eeep, 0, 1); } @@ -82,7 +106,11 @@ void nvm_terminate() { eeep_terminate(&eeep); W25Qx_terminate(&eflash); +#ifdef PLATFORM_CS7000P + spiStm32_terminate(&flash_spi); +#else spiBitbang_terminate(&flash_spi); +#endif } const struct nvmDescriptor *nvm_getDesc(const size_t index) diff --git a/platform/targets/CS7000-PLUS/hwconfig.c b/platform/targets/CS7000-PLUS/hwconfig.c index 051b369e..e4be2e59 100644 --- a/platform/targets/CS7000-PLUS/hwconfig.c +++ b/platform/targets/CS7000-PLUS/hwconfig.c @@ -70,5 +70,6 @@ static const struct gpioPin shiftRegStrobe = { GPIOEXT_STR }; static pthread_mutex_t adc1Mutex; SPI_CUSTOM_DEVICE_DEFINE(spiSr, spiSr_func, NULL, NULL) +SPI_STM32_DEVICE_DEFINE(flash_spi, SPI4, NULL) GPIO_SHIFTREG_DEVICE_DEFINE(extGpio, (const struct spiDevice *) &spiSr, shiftRegStrobe, 24) ADC_STM32_DEVICE_DEFINE(adc1, ADC1, &adc1Mutex, ADC_COUNTS_TO_UV(3300000, 16)) diff --git a/platform/targets/CS7000-PLUS/hwconfig.h b/platform/targets/CS7000-PLUS/hwconfig.h index b8d03177..2c5e7e05 100644 --- a/platform/targets/CS7000-PLUS/hwconfig.h +++ b/platform/targets/CS7000-PLUS/hwconfig.h @@ -43,6 +43,7 @@ enum AdcChannels extern const struct Adc adc1; extern const struct spiCustomDevice spiSr; +extern const struct spiDevice flash_spi; extern const struct gpioDev extGpio; extern const struct ak2365a detector; extern const struct sky73210 pll; @@ -66,6 +67,9 @@ extern const struct sky73210 pll; /* Device has a GPS chip */ // #define CONFIG_GPS +/* Use extended addressing for external flash memory */ +#define CONFIG_W25Qx_EXT_ADDR + #ifdef __cplusplus } #endif