Skip to content

Commit

Permalink
trying fixing the LMA VMA offset in spi applications
Browse files Browse the repository at this point in the history
  • Loading branch information
davideschiavone committed Oct 13, 2023
1 parent f4f05dc commit 2cbd423
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sw/applications/example_spi_host/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions sw/linker/link_flash_load.ld.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 2cbd423

Please sign in to comment.