From 3b877d20dfb3fcf8846e6b26667a69a31692ee43 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sun, 22 Sep 2024 16:28:13 +0200 Subject: [PATCH] MD3x0: updated nvm driver --- meson.build | 8 +++---- platform/drivers/CPS/cps_io_native_MD3x0.c | 24 +++++++------------ platform/targets/MD-3x0/hwconfig.c | 27 ++++++++++++++++++++++ platform/targets/MD-3x0/hwconfig.h | 2 ++ platform/targets/MD-3x0/pinmap.h | 2 +- 5 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 platform/targets/MD-3x0/hwconfig.c diff --git a/meson.build b/meson.build index e7f2a717..5c8620ea 100644 --- a/meson.build +++ b/meson.build @@ -154,9 +154,7 @@ openrtx_def += {'GIT_VERSION': git_version} ## TYT MDx family ## -mdx_src = ['openrtx/src/core/xmodem.c', - 'openrtx/src/core/backup.c', - 'platform/drivers/ADC/ADC1_MDx.c', +mdx_src = ['platform/drivers/ADC/ADC1_MDx.c', 'platform/drivers/GPS/GPS_MDx.cpp', 'platform/drivers/NVM/W25Qx.c', 'platform/drivers/NVM/nvmem_settings_MDx.c', @@ -333,14 +331,14 @@ endif ## TYT MD-3x0 family ## md3x0_src = ['platform/drivers/CPS/cps_io_native_MD3x0.c', - 'platform/drivers/NVM/spiFlash_MD3x.c', 'platform/drivers/baseband/SKY72310.c', 'platform/drivers/baseband/radio_MD3x0.cpp', 'platform/drivers/baseband/HR_C5000_MDx.cpp', 'platform/drivers/keyboard/keyboard_MD3x.c', 'platform/drivers/display/HX8353_MD3x.cpp', 'platform/drivers/backlight/backlight_MDx.c', - 'platform/targets/MD-3x0/platform.c'] + 'platform/targets/MD-3x0/platform.c', + 'platform/targets/MD-3x0/hwconfig.c'] md3x0_inc = ['platform/targets/MD-3x0'] md3x0_def = {'PLATFORM_MD3x0': '', 'timegm': 'mktime'} diff --git a/platform/drivers/CPS/cps_io_native_MD3x0.c b/platform/drivers/CPS/cps_io_native_MD3x0.c index cb0216d3..feaa870e 100644 --- a/platform/drivers/CPS/cps_io_native_MD3x0.c +++ b/platform/drivers/CPS/cps_io_native_MD3x0.c @@ -20,12 +20,15 @@ #include #include +#include #include #include #include #include "cps_data_MD3x0.h" #include "W25Qx.h" +extern const struct nvmDevice eflash; + static const uint32_t zoneBaseAddr = 0x149e0; /**< Base address of zones */ static const uint32_t chDataBaseAddr = 0x1ee00; /**< Base address of channel data */ static const uint32_t contactBaseAddr = 0x05f80; /**< Base address of contacts */ @@ -33,6 +36,11 @@ static const uint32_t maxNumChannels = 1000; /**< Maximum number of channel static const uint32_t maxNumZones = 250; /**< Maximum number of zones in memory */ static const uint32_t maxNumContacts = 10000; /**< Maximum number of contacts in memory */ +static inline void W25Qx_readData(uint32_t addr, void *buf, size_t len) +{ + nvm_devRead(&eflash, addr, buf, len); +} + /** * This function does not apply to address-based codeplugs @@ -66,13 +74,9 @@ int cps_readChannel(channel_t *channel, uint16_t pos) memset(channel, 0x00, sizeof(channel_t)); - W25Qx_wakeup(); - delayUs(5); - md3x0Channel_t chData; uint32_t readAddr = chDataBaseAddr + pos * sizeof(md3x0Channel_t); W25Qx_readData(readAddr, ((uint8_t *) &chData), sizeof(md3x0Channel_t)); - W25Qx_sleep(); channel->mode = chData.channel_mode; channel->bandwidth = (chData.bandwidth == 0) ? 0 : 1; // Consider 20kHz as 25kHz @@ -145,13 +149,9 @@ int cps_readBankHeader(bankHdr_t *b_header, uint16_t pos) { if(pos >= maxNumZones) return -1; - W25Qx_wakeup(); - delayUs(5); - md3x0Zone_t zoneData; uint32_t zoneAddr = zoneBaseAddr + pos * sizeof(md3x0Zone_t); W25Qx_readData(zoneAddr, ((uint8_t *) &zoneData), sizeof(md3x0Zone_t)); - W25Qx_sleep(); // Check if zone is empty #pragma GCC diagnostic ignored "-Waddress-of-packed-member" @@ -172,13 +172,9 @@ int cps_readBankData(uint16_t bank_pos, uint16_t ch_pos) { if(bank_pos >= maxNumZones) return -1; - W25Qx_wakeup(); - delayUs(5); - md3x0Zone_t zoneData; uint32_t zoneAddr = zoneBaseAddr + bank_pos * sizeof(md3x0Zone_t); W25Qx_readData(zoneAddr, ((uint8_t *) &zoneData), sizeof(md3x0Zone_t)); - W25Qx_sleep(); // Check if zone is empty #pragma GCC diagnostic ignored "-Waddress-of-packed-member" @@ -193,14 +189,10 @@ int cps_readContact(contact_t *contact, uint16_t pos) { if(pos >= maxNumContacts) return -1; - W25Qx_wakeup(); - delayUs(5); - md3x0Contact_t contactData; // Note: pos is 1-based to be consistent with channels uint32_t contactAddr = contactBaseAddr + pos * sizeof(md3x0Contact_t); W25Qx_readData(contactAddr, ((uint8_t *) &contactData), sizeof(md3x0Contact_t)); - W25Qx_sleep(); // Check if contact is empty #pragma GCC diagnostic ignored "-Waddress-of-packed-member" diff --git a/platform/targets/MD-3x0/hwconfig.c b/platform/targets/MD-3x0/hwconfig.c new file mode 100644 index 00000000..42b7c397 --- /dev/null +++ b/platform/targets/MD-3x0/hwconfig.c @@ -0,0 +1,27 @@ +/*************************************************************************** + * Copyright (C) 2024 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Frederik Saraci IU2NRO, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include +#include +#include + +SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL) diff --git a/platform/targets/MD-3x0/hwconfig.h b/platform/targets/MD-3x0/hwconfig.h index 32cf9737..eafa5577 100644 --- a/platform/targets/MD-3x0/hwconfig.h +++ b/platform/targets/MD-3x0/hwconfig.h @@ -27,6 +27,8 @@ extern "C" { #endif +extern const struct spiDevice nvm_spi; + /* Device has a working real time clock */ #define CONFIG_RTC diff --git a/platform/targets/MD-3x0/pinmap.h b/platform/targets/MD-3x0/pinmap.h index da7fe628..fc593744 100644 --- a/platform/targets/MD-3x0/pinmap.h +++ b/platform/targets/MD-3x0/pinmap.h @@ -81,7 +81,7 @@ #define BEEP_OUT GPIOC,8 /* CTCSS tone */ /* External flash */ -#define FLASH_CS GPIOD,7 +#define FLASH_CS &GpioD,7 #define FLASH_CLK GPIOB,3 #define FLASH_SDO GPIOB,4 #define FLASH_SDI GPIOB,5