mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-21 06:13:41 +00:00
Partial source calibration dialog
This commit is contained in:
parent
6f717de0f1
commit
875f3b0170
28 changed files with 784 additions and 33 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "main.h"
|
||||
#include "FPGA_HAL.hpp"
|
||||
#include <complex>
|
||||
#include "HW_HAL.hpp"
|
||||
|
||||
#define LOG_LEVEL LOG_LEVEL_DEBUG
|
||||
#define LOG_MODULE "FPGA"
|
||||
|
|
@ -33,7 +34,7 @@ void FPGA::WriteRegister(FPGA::Reg reg, uint16_t value) {
|
|||
}
|
||||
}
|
||||
|
||||
bool FPGA::Configure(Flash *f, uint32_t start_address, uint32_t bitstream_size) {
|
||||
bool FPGA::Configure(uint32_t start_address, uint32_t bitstream_size) {
|
||||
if(!PROGRAM_B.gpio) {
|
||||
LOG_WARN("PROGRAM_B not defined, assuming FPGA configures itself in master configuration");
|
||||
// wait too allow enough time for FPGA configuration
|
||||
|
|
@ -64,7 +65,7 @@ bool FPGA::Configure(Flash *f, uint32_t start_address, uint32_t bitstream_size)
|
|||
}
|
||||
// TODO this part might be doable with the DMA instead of the buffer
|
||||
// get chunk of bitstream from flash...
|
||||
f->read(start_address, size, buf);
|
||||
HWHAL::flash.read(start_address, size, buf);
|
||||
// ... and pass it on to FPGA
|
||||
HAL_SPI_Transmit(&CONFIGURATION_SPI, buf, size, 100);
|
||||
bitstream_size -= size;
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ enum class Window {
|
|||
Flattop = 0x03,
|
||||
};
|
||||
|
||||
bool Configure(Flash *f, uint32_t start_address, uint32_t bitstream_size);
|
||||
bool Configure(uint32_t start_address, uint32_t bitstream_size);
|
||||
|
||||
using HaltedCallback = void(*)(void);
|
||||
bool Init(HaltedCallback cb = nullptr);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ void Flash::read(uint32_t address, uint16_t length, void *dest) {
|
|||
CS(true);
|
||||
}
|
||||
|
||||
bool Flash::write(uint32_t address, uint16_t length, uint8_t *src) {
|
||||
bool Flash::write(uint32_t address, uint16_t length, void *src) {
|
||||
if((address & 0xFF) != 0 || length%256 != 0) {
|
||||
// only writes to complete pages allowed
|
||||
LOG_ERR("Invalid write address/size: %lu/%u", address, length);
|
||||
|
|
@ -49,7 +49,7 @@ bool Flash::write(uint32_t address, uint16_t length, uint8_t *src) {
|
|||
// issue read command
|
||||
HAL_SPI_Transmit(spi, cmd, 4, 100);
|
||||
// write data
|
||||
HAL_SPI_Transmit(spi, src, 256, 1000);
|
||||
HAL_SPI_Transmit(spi, (uint8_t*) src, 256, 1000);
|
||||
CS(true);
|
||||
if(!WaitBusy(20)) {
|
||||
LOG_ERR("Write timed out");
|
||||
|
|
@ -78,16 +78,66 @@ void Flash::EnableWrite() {
|
|||
}
|
||||
|
||||
bool Flash::eraseChip() {
|
||||
LOG_INFO("Erasing...");
|
||||
LOG_INFO("Erasing chip...");
|
||||
EnableWrite();
|
||||
CS(false);
|
||||
// enable write latch
|
||||
uint8_t chip_erase = 0x60;
|
||||
HAL_SPI_Transmit(spi, &chip_erase, 1, 100);
|
||||
CS(true);
|
||||
return WaitBusy(25000);
|
||||
}
|
||||
|
||||
bool Flash::eraseSector(uint32_t address) {
|
||||
// align address with sector address
|
||||
address -= address % SectorSize;
|
||||
LOG_INFO("Erasing sector at %lu", address);
|
||||
EnableWrite();
|
||||
CS(false);
|
||||
uint8_t cmd[4] = {
|
||||
0x20,
|
||||
(uint8_t) (address >> 16) & 0xFF,
|
||||
(uint8_t) (address >> 8) & 0xFF,
|
||||
(uint8_t) (address & 0xFF),
|
||||
};
|
||||
HAL_SPI_Transmit(spi, cmd, 4, 100);
|
||||
CS(true);
|
||||
return WaitBusy(25000);
|
||||
}
|
||||
|
||||
bool Flash::erase32Block(uint32_t address) {
|
||||
// align address with block address
|
||||
address -= address % Block32Size;
|
||||
LOG_INFO("Erasing 32kB block at %lu", address);
|
||||
EnableWrite();
|
||||
CS(false);
|
||||
uint8_t cmd[4] = {
|
||||
0x52,
|
||||
(uint8_t) (address >> 16) & 0xFF,
|
||||
(uint8_t) (address >> 8) & 0xFF,
|
||||
(uint8_t) (address & 0xFF),
|
||||
};
|
||||
HAL_SPI_Transmit(spi, cmd, 4, 100);
|
||||
CS(true);
|
||||
return WaitBusy(25000);
|
||||
}
|
||||
|
||||
bool Flash::erase64Block(uint32_t address) {
|
||||
// align address with block address
|
||||
address -= address % Block64Size;
|
||||
LOG_INFO("Erasing 64kB block at %lu", address);
|
||||
EnableWrite();
|
||||
CS(false);
|
||||
uint8_t cmd[4] = {
|
||||
0xD8,
|
||||
(uint8_t) (address >> 16) & 0xFF,
|
||||
(uint8_t) (address >> 8) & 0xFF,
|
||||
(uint8_t) (address & 0xFF),
|
||||
};
|
||||
HAL_SPI_Transmit(spi, cmd, 4, 100);
|
||||
CS(true);
|
||||
return WaitBusy(25000);
|
||||
}
|
||||
|
||||
void Flash::initiateRead(uint32_t address) {
|
||||
address &= 0x00FFFFFF;
|
||||
CS(false);
|
||||
|
|
@ -120,3 +170,38 @@ bool Flash::WaitBusy(uint32_t timeout) {
|
|||
LOG_ERR("Timeout occured");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Flash::eraseRange(uint32_t start, uint32_t len) {
|
||||
if(start % SectorSize != 0) {
|
||||
LOG_ERR("Start address of range has to be sector aligned (is %lu)", start);
|
||||
return false;
|
||||
}
|
||||
if(len % SectorSize != 0) {
|
||||
LOG_ERR("Length of range has to be multiple of sector size (is %lu)", len);
|
||||
return false;
|
||||
}
|
||||
uint32_t erased_len = 0;
|
||||
while(erased_len < len) {
|
||||
uint32_t remaining = len - erased_len;
|
||||
if(remaining >= Block64Size && start % Block64Size == 0) {
|
||||
erase64Block(start);
|
||||
erased_len += Block64Size;
|
||||
start += Block64Size;
|
||||
continue;
|
||||
}
|
||||
if(remaining >= Block32Size && start % Block32Size == 0) {
|
||||
erase32Block(start);
|
||||
erased_len += Block32Size;
|
||||
start += Block32Size;
|
||||
continue;
|
||||
}
|
||||
if(remaining >= SectorSize && start % SectorSize == 0) {
|
||||
eraseSector(start);
|
||||
erased_len += SectorSize;
|
||||
start += SectorSize;
|
||||
continue;
|
||||
}
|
||||
// Should never get here
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,12 @@ public:
|
|||
|
||||
bool isPresent();
|
||||
void read(uint32_t address, uint16_t length, void *dest);
|
||||
bool write(uint32_t address, uint16_t length, uint8_t *src);
|
||||
bool write(uint32_t address, uint16_t length, void *src);
|
||||
bool eraseChip();
|
||||
bool eraseSector(uint32_t address);
|
||||
bool erase32Block(uint32_t address);
|
||||
bool erase64Block(uint32_t address);
|
||||
bool eraseRange(uint32_t start, uint32_t len);
|
||||
// Starts the reading process without actually reading any bytes
|
||||
void initiateRead(uint32_t address);
|
||||
const SPI_HandleTypeDef* const getSpi() const {
|
||||
|
|
@ -26,6 +30,9 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
static constexpr uint32_t SectorSize = 4096;
|
||||
static constexpr uint32_t Block32Size = 32768;
|
||||
static constexpr uint32_t Block64Size = 65536;
|
||||
void CS(bool high) {
|
||||
if(high) {
|
||||
CS_gpio->BSRR = CS_pin;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue