How to relocate tables from RAM to Flash memory

I am programming the STM32fM4 Discovery board with a Cortex M4F ARM CPU.
I have two large tables, which, after the initialization, are just read-only.
I would like to place them in Flash memory, to free some RAM.

I tried this :

float sintab[8192]  __attribute__((at(0x08010000)));
float costab[8192]  __attribute__((at(0x08018000)));

but the linker complains with this error message :

Error: L6985E: Unable to automatically place AT section main.o(.ARM.__AT_0x08010000) with required base address 0x08010000.
Please manually place in the scatter file using the --no_autoat option.


I am not particularly expert of this compiler/linker, so the above message is not much clear to me. Could please somebody explains how to accomplish what I want ? I don't know what a scatter file is, nor how to code one to relocate in Flash memory my two tables.

Thanks

Parents
  • Some more effort and error handling involved, but along the lines of

      FLASH_Status status = FLASH_COMPLETE;
    
      FLASH_Unlock();
    
      // Clear any pending status
    
      status = FLASH_WaitForLastOperation(); /* Wait for last operation to be completed */
    
      status = FLASH_EraseSector(FLASH_Sector_4, VoltageRange_3);   // 64 KB @ 0x8010000
    
      status = FLASH_WaitForLastOperation(); /* Wait for last operation to be completed */
    
      if (status == FLASH_COMPLETE)
      {
        FLASH->CR &= CR_PSIZE_MASK;
        FLASH->CR |= FLASH_PSIZE_WORD;
        FLASH->CR |= FLASH_CR_PG;
    
        i = 0x08010000; // Flash table base
    
    { // some table generation loop for sin/cos
          *(__IO uint32_t*)i = Data; // Write to Flash 32-bit word
    
          status = FLASH_WaitForLastOperation(); /* Wait for last operation to be completed */
    
          if (status != FLASH_COMPLETE)
            break;
    
          i += 4;
    } // end of table gen loop
    
        FLASH->CR &= (~FLASH_CR_PG);
      }
    
      FLASH_Lock();
    

Reply
  • Some more effort and error handling involved, but along the lines of

      FLASH_Status status = FLASH_COMPLETE;
    
      FLASH_Unlock();
    
      // Clear any pending status
    
      status = FLASH_WaitForLastOperation(); /* Wait for last operation to be completed */
    
      status = FLASH_EraseSector(FLASH_Sector_4, VoltageRange_3);   // 64 KB @ 0x8010000
    
      status = FLASH_WaitForLastOperation(); /* Wait for last operation to be completed */
    
      if (status == FLASH_COMPLETE)
      {
        FLASH->CR &= CR_PSIZE_MASK;
        FLASH->CR |= FLASH_PSIZE_WORD;
        FLASH->CR |= FLASH_CR_PG;
    
        i = 0x08010000; // Flash table base
    
    { // some table generation loop for sin/cos
          *(__IO uint32_t*)i = Data; // Write to Flash 32-bit word
    
          status = FLASH_WaitForLastOperation(); /* Wait for last operation to be completed */
    
          if (status != FLASH_COMPLETE)
            break;
    
          i += 4;
    } // end of table gen loop
    
        FLASH->CR &= (~FLASH_CR_PG);
      }
    
      FLASH_Lock();
    

Children
More questions in this forum