diff --git a/meson.build b/meson.build index 5c8620ea..ee0987e8 100644 --- a/meson.build +++ b/meson.build @@ -350,9 +350,9 @@ md3x0_def += openrtx_def + stm32f405_def + miosix_cm4f_def ## ## TYT MD-UV380 ## -mduv3x0_src = ['platform/drivers/NVM/spiFlash_MD3x.c', - 'platform/drivers/CPS/cps_io_native_MDUV3x0.c', +mduv3x0_src = ['platform/drivers/CPS/cps_io_native_MDUV3x0.c', 'platform/targets/MD-UV3x0/platform.c', + 'platform/targets/MD-UV3x0/hwconfig.c', 'platform/drivers/keyboard/keyboard_MD3x.c', 'platform/drivers/display/HX8353_MD3x.cpp', 'platform/drivers/backlight/backlight_MDx.c', diff --git a/platform/drivers/CPS/cps_io_native_MDUV3x0.c b/platform/drivers/CPS/cps_io_native_MDUV3x0.c index e55090ea..1cf7d2cc 100644 --- a/platform/drivers/CPS/cps_io_native_MDUV3x0.c +++ b/platform/drivers/CPS/cps_io_native_MDUV3x0.c @@ -20,12 +20,15 @@ #include #include +#include #include #include #include #include "cps_data_MDUV3x0.h" #include "W25Qx.h" +extern const struct nvmDevice eflash; + static const uint32_t zoneBaseAddr = 0x149E0; /**< Base address of zones */ static const uint32_t zoneExtBaseAddr = 0x31000; /**< Base address of zone extensions */ static const uint32_t chDataBaseAddr = 0x110000; /**< Base address of channel data */ @@ -34,17 +37,18 @@ static const uint32_t maxNumChannels = 3000; /**< Maximum number of chan static const uint32_t maxNumZones = 250; /**< Maximum number of zones and zone extensions 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); +} /** * Used to read channel data from SPI flash into a channel_t struct */ static int _readChannelAtAddress(channel_t *channel, uint32_t addr) { - W25Qx_wakeup(); - delayUs(5); mduv3x0Channel_t chData; W25Qx_readData(addr, ((uint8_t *) &chData), sizeof(mduv3x0Channel_t)); - W25Qx_sleep(); // Check if the channel is empty #pragma GCC diagnostic ignored "-Waddress-of-packed-member" @@ -169,9 +173,6 @@ int cps_readBankHeader(bankHdr_t *b_header, uint16_t pos) { if(pos >= maxNumZones) return -1; - W25Qx_wakeup(); - delayUs(5); - mduv3x0Zone_t zoneData; mduv3x0ZoneExt_t zoneExtData; // Note: pos is 1-based to be consistent with channels @@ -179,7 +180,6 @@ int cps_readBankHeader(bankHdr_t *b_header, uint16_t pos) uint32_t zoneExtAddr = zoneExtBaseAddr + pos * sizeof(mduv3x0ZoneExt_t); W25Qx_readData(zoneAddr, ((uint8_t *) &zoneData), sizeof(mduv3x0Zone_t)); W25Qx_readData(zoneExtAddr, ((uint8_t *) &zoneExtData), sizeof(mduv3x0ZoneExt_t)); - W25Qx_sleep(); // Check if zone is empty #pragma GCC diagnostic ignored "-Waddress-of-packed-member" @@ -200,16 +200,12 @@ int cps_readBankData(uint16_t bank_pos, uint16_t ch_pos) { if(bank_pos >= maxNumZones) return -1; - W25Qx_wakeup(); - delayUs(5); - mduv3x0Zone_t zoneData; mduv3x0ZoneExt_t zoneExtData; uint32_t zoneAddr = zoneBaseAddr + bank_pos * sizeof(mduv3x0Zone_t); uint32_t zoneExtAddr = zoneExtBaseAddr + bank_pos * sizeof(mduv3x0ZoneExt_t); W25Qx_readData(zoneAddr, ((uint8_t *) &zoneData), sizeof(mduv3x0Zone_t)); W25Qx_readData(zoneExtAddr, ((uint8_t *) &zoneExtData), sizeof(mduv3x0ZoneExt_t)); - W25Qx_sleep(); // Check if zone is empty #pragma GCC diagnostic ignored "-Waddress-of-packed-member" @@ -226,14 +222,10 @@ int cps_readContact(contact_t *contact, uint16_t pos) { if(pos >= maxNumContacts) return -1; - W25Qx_wakeup(); - delayUs(5); - mduv3x0Contact_t contactData; // Note: pos is 1-based to be consistent with channels uint32_t contactAddr = contactBaseAddr + pos * sizeof(mduv3x0Contact_t); W25Qx_readData(contactAddr, ((uint8_t *) &contactData), sizeof(mduv3x0Contact_t)); - W25Qx_sleep(); // Check if contact is empty if(wcslen((wchar_t *) contactData.name) == 0) return -1; diff --git a/platform/drivers/NVM/spiFlash_MD3x.c b/platform/drivers/NVM/spiFlash_MD3x.c deleted file mode 100644 index e07c9753..00000000 --- a/platform/drivers/NVM/spiFlash_MD3x.c +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2020 - 2023 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 - -/* - * Implementation of external flash SPI interface for MDx devices. - */ - -uint8_t spiFlash_SendRecv(uint8_t val) -{ - SPI1->DR = val; - while((SPI1->SR & SPI_SR_RXNE) == 0) ; - return SPI1->DR; -} - -void spiFlash_init() -{ - gpio_setMode(FLASH_CLK, ALTERNATE | ALTERNATE_FUNC(5)); - gpio_setMode(FLASH_SDO, ALTERNATE | ALTERNATE_FUNC(5)); - gpio_setMode(FLASH_SDI, ALTERNATE | ALTERNATE_FUNC(5)); - - RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; - __DSB(); - - SPI1->CR1 = SPI_CR1_SSM /* Software managment of nCS */ - | SPI_CR1_SSI /* Force internal nCS */ - | SPI_CR1_BR_2 /* Fclock: 84MHz/64 = 1.3MHz */ - | SPI_CR1_BR_0 - | SPI_CR1_MSTR /* Master mode */ - | SPI_CR1_SPE; /* Enable peripheral */ -} - -void spiFlash_terminate() -{ - RCC->APB2ENR &= ~RCC_APB2ENR_SPI1EN; - __DSB(); - - gpio_setMode(FLASH_CLK, INPUT); - gpio_setMode(FLASH_SDO, INPUT); - gpio_setMode(FLASH_SDI, INPUT); -} diff --git a/platform/targets/MD-UV3x0/hwconfig.c b/platform/targets/MD-UV3x0/hwconfig.c new file mode 100644 index 00000000..d956b831 --- /dev/null +++ b/platform/targets/MD-UV3x0/hwconfig.c @@ -0,0 +1,24 @@ +/*************************************************************************** + * 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 + +SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL) diff --git a/platform/targets/MD-UV3x0/hwconfig.h b/platform/targets/MD-UV3x0/hwconfig.h index 18ce5423..a3f7a707 100644 --- a/platform/targets/MD-UV3x0/hwconfig.h +++ b/platform/targets/MD-UV3x0/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-UV3x0/pinmap.h b/platform/targets/MD-UV3x0/pinmap.h index bcfb3f63..7be31347 100644 --- a/platform/targets/MD-UV3x0/pinmap.h +++ b/platform/targets/MD-UV3x0/pinmap.h @@ -79,7 +79,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