From 2cbd4239088b6a539401ee1152ffd96962ba9240 Mon Sep 17 00:00:00 2001 From: davide schiavone Date: Fri, 13 Oct 2023 15:04:06 +0200 Subject: [PATCH] trying fixing the LMA VMA offset in spi applications --- sw/applications/example_spi_host/main.c | 15 ++++++++++++++- sw/linker/link_flash_load.ld.tpl | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sw/applications/example_spi_host/main.c b/sw/applications/example_spi_host/main.c index c2436489d..2182f52bc 100644 --- a/sw/applications/example_spi_host/main.c +++ b/sw/applications/example_spi_host/main.c @@ -41,6 +41,7 @@ volatile int8_t spi_intr_flag; spi_host_t spi_host; uint32_t flash_data[8]; uint32_t flash_original[8] = {1}; +extern uint32_t* _lma_vma_data_offset; #ifndef USE_SPI_FLASH void fic_irq_spi(void) @@ -60,12 +61,24 @@ void fic_irq_spi_flash(void) } #endif +uint32_t * get_data_address_lma(uint32_t* data_address_vma){ + + uint32_t* flash_original_lma = (uint32_t*) ((uint32_t)(_lma_vma_data_offset) + (uint32_t)(data_address_vma)); + //set MS 8 bits to 0 as the flash only uses 24b + flash_original_lma = (uint32_t*) ((uint32_t)(flash_original_lma) & 0x00FFFFFF); + return flash_original_lma; +} + int main(int argc, char *argv[]) { + soc_ctrl_t soc_ctrl; soc_ctrl.base_addr = mmio_region_from_addr((uintptr_t)SOC_CTRL_START_ADDRESS); - uint32_t read_byte_cmd = ((REVERT_24b_ADDR(flash_original) << 8) | 0x03); // The address bytes sent through the SPI to the Flash are in reverse order + + uint32_t* flash_original_lma = get_data_address_lma(flash_original); + + uint32_t read_byte_cmd = ((REVERT_24b_ADDR(flash_original_lma) << 8) | 0x03); // The address bytes sent through the SPI to the Flash are in reverse order if ( get_spi_flash_mode(&soc_ctrl) == SOC_CTRL_SPI_FLASH_MODE_SPIMEMIO ) { diff --git a/sw/linker/link_flash_load.ld.tpl b/sw/linker/link_flash_load.ld.tpl index 61637a15f..594234661 100644 --- a/sw/linker/link_flash_load.ld.tpl +++ b/sw/linker/link_flash_load.ld.tpl @@ -88,6 +88,7 @@ SECTIONS { . = ALIGN(4); _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ _lma_data_end = _lma_data_start + SIZEOF(.data); + _lma_vma_data_offset = _lma_data_start - __data_start; .power_manager : ALIGN(4096) {