mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion] Add configuration for Flash of N0101 and N0100
This commit is contained in:
@@ -20,7 +20,8 @@ namespace Config {
|
||||
|
||||
using namespace Regs;
|
||||
|
||||
constexpr static uint32_t QSPIBaseAddress = 0;
|
||||
constexpr static uint32_t StartAddress = 0xFFFFFFFF;
|
||||
constexpr static uint32_t EndAddress = 0xFFFFFFFF;
|
||||
constexpr static int NumberOfSectors = 0;
|
||||
constexpr static AFGPIOPin Pins[] = {};
|
||||
|
||||
|
||||
26
ion/src/device/n0100/drivers/config/flash.h
Normal file
26
ion/src/device/n0100/drivers/config/flash.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef ION_DEVICE_N0100_CONFIG_FLASH_H
|
||||
#define ION_DEVICE_N0100_CONFIG_FLASH_H
|
||||
|
||||
#include <regs/regs.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Device {
|
||||
namespace Flash {
|
||||
namespace Config {
|
||||
|
||||
constexpr static uint32_t StartAddress = 0x08000000;
|
||||
constexpr static uint32_t EndAddress = 0x08100000;
|
||||
constexpr static int NumberOfSectors = 12;
|
||||
constexpr static uint32_t SectorAddresses[NumberOfSectors+1] = {
|
||||
0x08000000, 0x08004000, 0x08008000, 0x0800C000,
|
||||
0x08010000, 0x08020000, 0x08040000, 0x08060000,
|
||||
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000,
|
||||
0x08100000
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,8 @@ namespace Config {
|
||||
|
||||
using namespace Regs;
|
||||
|
||||
constexpr static uint32_t QSPIBaseAddress = 0x90000000;
|
||||
constexpr static uint32_t StartAddress = 0x90000000;
|
||||
constexpr static uint32_t EndAddress = 0x90800000;
|
||||
constexpr static int NumberOfSectors = 128;
|
||||
constexpr static AFGPIOPin Pins[] = {
|
||||
AFGPIOPin(GPIOB, 2, GPIO::AFR::AlternateFunction::AF9, GPIO::PUPDR::Pull::None, GPIO::OSPEEDR::OutputSpeed::High),
|
||||
|
||||
24
ion/src/device/n0101/drivers/config/flash.h
Normal file
24
ion/src/device/n0101/drivers/config/flash.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef ION_DEVICE_N0101_CONFIG_FLASH_H
|
||||
#define ION_DEVICE_N0101_CONFIG_FLASH_H
|
||||
|
||||
#include <regs/regs.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Device {
|
||||
namespace Flash {
|
||||
namespace Config {
|
||||
|
||||
constexpr static uint32_t StartAddress = 0x08000000;
|
||||
constexpr static uint32_t EndAddress = 0x08010000;
|
||||
constexpr static int NumberOfSectors = 4;
|
||||
constexpr static uint32_t SectorAddresses[NumberOfSectors+1] = {
|
||||
0x08000000, 0x08004000, 0x08008000, 0x0800C000,
|
||||
0x08010000
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "flash.h"
|
||||
#include <drivers/cache.h>
|
||||
#include <drivers/config/flash.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Ion {
|
||||
@@ -212,14 +213,8 @@ static void flash_memcpy(uint8_t * destination, uint8_t * source, size_t length)
|
||||
}
|
||||
|
||||
int SectorAtAddress(uint32_t address) {
|
||||
uint32_t sectorAddresses[NumberOfSectors+1] = {
|
||||
0x08000000, 0x08004000, 0x08008000, 0x0800C000,
|
||||
0x08010000, 0x08020000, 0x08040000, 0x08060000,
|
||||
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000,
|
||||
0x08100000
|
||||
};
|
||||
for (int i=0; i<NumberOfSectors; i++) {
|
||||
if (address >= sectorAddresses[i] && address < sectorAddresses[i+1]) {
|
||||
if (address >= Config::SectorAddresses[i] && address < Config::SectorAddresses[i+1]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Flash {
|
||||
|
||||
void MassErase();
|
||||
|
||||
constexpr int NumberOfSectors = 12;
|
||||
constexpr int NumberOfSectors = 4;
|
||||
int SectorAtAddress(uint32_t address);
|
||||
void EraseSector(int i);
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "dfu_interface.h"
|
||||
#include <drivers/config/external_flash.h>
|
||||
#include <string.h>
|
||||
#include "../drivers/flash.h"
|
||||
#include "../drivers/external_flash.h"
|
||||
#include <drivers/flash.h>
|
||||
#include <drivers/external_flash.h>
|
||||
#include <drivers/config/flash.h>
|
||||
#include <drivers/config/external_flash.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Device {
|
||||
@@ -177,7 +179,7 @@ void DFUInterface::eraseCommand(uint8_t * transferBuffer, uint16_t transferBuffe
|
||||
|
||||
if (transferBufferLength == 1) {
|
||||
// Mass erase
|
||||
m_erasePage = Flash::NumberOfSectors + ExternalFlash::Config::NumberOfSectors;
|
||||
m_erasePage = Flash::Config::NumberOfSectors + ExternalFlash::Config::NumberOfSectors;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,10 +191,10 @@ void DFUInterface::eraseCommand(uint8_t * transferBuffer, uint16_t transferBuffe
|
||||
+ (transferBuffer[3] << 16)
|
||||
+ (transferBuffer[4] << 24);
|
||||
|
||||
if (eraseAddress >= k_flashStartAddress && eraseAddress <= k_flashEndAddress) {
|
||||
if (eraseAddress >= Flash::Config::StartAddress && eraseAddress <= Flash::Config::EndAddress) {
|
||||
m_erasePage = Flash::SectorAtAddress(eraseAddress);
|
||||
} else if (eraseAddress >= k_externalFlashStartAddress && eraseAddress <= k_externalFlashEndAddress) {
|
||||
m_erasePage = Flash::NumberOfSectors + ExternalFlash::SectorAtAddress(eraseAddress - k_externalFlashStartAddress);
|
||||
} else if (eraseAddress >= ExternalFlash::Config::StartAddress && eraseAddress <= ExternalFlash::Config::EndAddress) {
|
||||
m_erasePage = Flash::Config::NumberOfSectors + ExternalFlash::SectorAtAddress(eraseAddress - ExternalFlash::Config::StartAddress);
|
||||
} else {
|
||||
// Unrecognized sector
|
||||
m_state = State::dfuERROR;
|
||||
@@ -207,13 +209,13 @@ void DFUInterface::eraseMemoryIfNeeded() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_erasePage == Flash::NumberOfSectors + ExternalFlash::Config::NumberOfSectors) {
|
||||
if (m_erasePage == Flash::Config::NumberOfSectors + ExternalFlash::Config::NumberOfSectors) {
|
||||
Flash::MassErase();
|
||||
ExternalFlash::MassErase();
|
||||
} else if (m_erasePage < Flash::NumberOfSectors) {
|
||||
} else if (m_erasePage < Flash::Config::NumberOfSectors) {
|
||||
Flash::EraseSector(m_erasePage);
|
||||
} else {
|
||||
ExternalFlash::EraseSector(m_erasePage - Flash::NumberOfSectors);
|
||||
ExternalFlash::EraseSector(m_erasePage - Flash::Config::NumberOfSectors);
|
||||
}
|
||||
|
||||
/* Put an out of range value in m_erasePage to indicate that no erase is
|
||||
@@ -224,15 +226,15 @@ void DFUInterface::eraseMemoryIfNeeded() {
|
||||
}
|
||||
|
||||
void DFUInterface::writeOnMemory() {
|
||||
if (m_writeAddress >= k_flashStartAddress && m_writeAddress <= k_flashEndAddress) {
|
||||
if (m_writeAddress >= Flash::Config::StartAddress && m_writeAddress <= Flash::Config::EndAddress) {
|
||||
// Write to the Flash memory
|
||||
Flash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress), m_largeBuffer, m_largeBufferLength);
|
||||
} else if (m_writeAddress >= k_sramStartAddress && m_writeAddress <= k_sramEndAddress) {
|
||||
// Write on SRAM
|
||||
// FIXME We should check that we are not overriding the current instructions.
|
||||
memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength);
|
||||
} else if (m_writeAddress >= k_externalFlashStartAddress && m_writeAddress <= k_externalFlashEndAddress) {
|
||||
ExternalFlash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress) - k_externalFlashStartAddress, m_largeBuffer, m_largeBufferLength);
|
||||
} else if (m_writeAddress >= ExternalFlash::Config::StartAddress && m_writeAddress <= ExternalFlash::Config::EndAddress) {
|
||||
ExternalFlash::WriteMemory(reinterpret_cast<uint8_t *>(m_writeAddress) - ExternalFlash::Config::StartAddress, m_largeBuffer, m_largeBufferLength);
|
||||
} else {
|
||||
// Invalid write address
|
||||
m_largeBufferLength = 0;
|
||||
|
||||
@@ -126,12 +126,8 @@ private:
|
||||
|
||||
/* The Flash and SRAM addresses are in flash.ld. However, dfu_interface is
|
||||
* linked with dfu.ld, so we cannot access the values. */
|
||||
constexpr static uint32_t k_flashStartAddress = 0x08000000;
|
||||
constexpr static uint32_t k_flashEndAddress = 0x08100000;
|
||||
constexpr static uint32_t k_sramStartAddress = 0x20000000;
|
||||
constexpr static uint32_t k_sramEndAddress = 0x20040000;
|
||||
constexpr static uint32_t k_externalFlashStartAddress = 0x90000000;
|
||||
constexpr static uint32_t k_externalFlashEndAddress = 0x90800000;
|
||||
|
||||
// Download and upload
|
||||
bool processDownloadRequest(uint16_t wLength, uint16_t * transferBufferLength);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// Choose some not too uniform data to program and test the external flash memory with.
|
||||
|
||||
static inline uint8_t expected_value_at(uint8_t * ptr) {
|
||||
uint32_t address = reinterpret_cast<uint32_t>(ptr) - Ion::ExternalFlash::Device::QSPIBaseAddress;
|
||||
uint32_t address = reinterpret_cast<uint32_t>(ptr) - Ion::ExternalFlash::Device::StartAddress;
|
||||
return (address / 0x10000) + (address / 0x100) + address;
|
||||
// Example: the value expected at the address 0x123456 is 0x12 + 0x34 + 0x56.
|
||||
}
|
||||
@@ -31,8 +31,8 @@ static inline void check(volatile T * p, int repeat) {
|
||||
|
||||
template <typename T>
|
||||
void test(int accessType, int repeat) {
|
||||
uint8_t * start = reinterpret_cast<uint8_t *>(Ion::ExternalFlash::Device::QSPIBaseAddress);
|
||||
uint8_t * end = reinterpret_cast<uint8_t *>(Ion::ExternalFlash::Device::QSPIBaseAddress + Ion::ExternalFlash::Device::FlashAddressSpaceSize);
|
||||
uint8_t * start = reinterpret_cast<uint8_t *>(Ion::ExternalFlash::Device::StartAddress);
|
||||
uint8_t * end = reinterpret_cast<uint8_t *>(Ion::ExternalFlash::Device::StartAddress + Ion::ExternalFlash::Device::FlashAddressSpaceSize);
|
||||
|
||||
// Forward sequential access
|
||||
if (accessType == 0) {
|
||||
@@ -52,10 +52,10 @@ void test(int accessType, int repeat) {
|
||||
|
||||
// Random access
|
||||
if (accessType == 2) {
|
||||
T * endT = reinterpret_cast<T *>(Ion::ExternalFlash::Device::QSPIBaseAddress + Ion::ExternalFlash::Device::FlashAddressSpaceSize);
|
||||
T * endT = reinterpret_cast<T *>(Ion::ExternalFlash::Device::StartAddress + Ion::ExternalFlash::Device::FlashAddressSpaceSize);
|
||||
for (size_t i=0; i<Ion::ExternalFlash::Device::FlashAddressSpaceSize; i++) {
|
||||
uint32_t randomAddr = Ion::random() >> (32 - Ion::ExternalFlash::Device::NumberOfAddressBitsInChip);
|
||||
volatile T * q = reinterpret_cast<T *>(randomAddr + Ion::ExternalFlash::Device::QSPIBaseAddress);
|
||||
volatile T * q = reinterpret_cast<T *>(randomAddr + Ion::ExternalFlash::Device::StartAddress);
|
||||
if (q <= endT - 1) {
|
||||
check(q, repeat);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ QUIZ_CASE(ion_ext_flash_program) {
|
||||
for (int page = 0; page < (1<<15); page++) {
|
||||
uint8_t buffer[256];
|
||||
for (int byte = 0; byte < 256; byte++) {
|
||||
buffer[byte] = expected_value_at(reinterpret_cast<uint8_t *>(Ion::ExternalFlash::Device::QSPIBaseAddress + page * 256 + byte));
|
||||
buffer[byte] = expected_value_at(reinterpret_cast<uint8_t *>(Ion::ExternalFlash::Device::StartAddress + page * 256 + byte));
|
||||
}
|
||||
Ion::ExternalFlash::Device::WriteMemory(reinterpret_cast<uint8_t *>(page * 256), buffer, 256);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user