This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Hardfault

Hi. 

I just put this on my main code: 



uint32_t pg_size,* addr,pg_num,numero_guardado_memoria=0;

pg_size = NRF_FICR->CODEPAGESIZE;
pg_num = NRF_FICR->CODESIZE - 1;

addr= (uint32_t *)(pg_size * (pg_num+1));
if((uint32_t)*(addr)=='D'){
     addr=(uint32_t *)(pg_size * (pg_num + 2));
     numero_guardado_memoria=(uint32_t)*(addr);
}

to simply read what is stored in a memory position ... and ones i debug the program, just after the if.. it lauch me a hardfault...

i can't understand. 

please i need your help. 

Parents Reply
  • Your flash is from address 0 to (NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE - 1), there's no memory after it. If you need to allocate some area of flash for your data, you have to change code size in your project settings (that is IROM1 in Keil) . Decrease this value, for example, by (pagesize*2), and you'll have two pages for data at the end of flash: (pg_num-1) and (pg_num-2).

Children
  • Could you explain me a little bit what is a page and how big in it is ? 

    Thanks a lot Dmitry (really)

  • You can read documentation about how flash memory works.

    Flash page size depends on chip: nrf51 - 1024 bytes, nrf52 - 4096 bytes.

  • Hi Dmitry, i try this: 

    IROM1: 0x1B000 to 0x3F800 (2048 less than normally) 

    And in the code: 

    doing this, writing and reading is ok 

    pg_size = NRF_FICR->CODEPAGESIZE;
    pg_num = NRF_FICR->CODESIZE-1; // Use last page in flash
    //--------------------------------- 
    addr = (uint32_t *)(pg_size * pg_num); 
    flash_page_erase(addr); 
    patwr_32 = 'D'; 
    flash_word_write(addr, patwr_32); 
    nrf_delay_ms(10);


    doing this reading is ok: 

    pg_size = NRF_FICR->CODEPAGESIZE;
    pg_num = NRF_FICR->CODESIZE-1; // Use last page in flash
    //---------------------------------
    addr = (uint32_t *)(pg_size * pg_num)+1;

    if((uint32_t)*(addr)=='D'){ //renombro
    numero_guardado_memoria=(uint32_t)*(addr);
    }

    Doing this it crashes in flash_page_erase: 

    addr = (uint32_t *)(pg_size * pg_num)+1 ;
    flash_page_erase(addr); 
    patwr_32 = 'D';
    flash_word_write(addr, patwr_32); 
    nrf_delay_ms(10);

    And with this in word_write: 

    addr = (uint32_t *)(pg_size * (pg_num+1)) ;
    flash_page_erase(addr); 
    patwr_32 = 'D';
    flash_word_write(addr, patwr_32);
    nrf_delay_ms(10);





    And finally i do this manually: 

     addr=(uint32_t *)0x5A801;

    That is 0x1B000 + 0x3F800 +1

    ( I guess it is the next position in memory that the one dedicated for code ) 

    and ALSO it gives me a hardfault

  • Hi,

    Nasib said:

    And finally i do this manually: 

     addr=(uint32_t *)0x5A801;

    That is 0x1B000 + 0x3F800 +1

    ( I guess it is the next position in memory that the one dedicated for code ) 

    and ALSO it gives me a hardfault

    This is clearly an invalid address (since it is higher than 256*1024=0x4000, so the hardfault is expected. You cannot use memory that does not exist.

  • Hi..

    The Rom1 conf (in keil) was: from 0x1b000 to 0x40000

    So i guess that memory was just for code. so i reduce it in keil conf to: 01b000 to 0x3f800

    Then i expected that those 2048 bytes were free to be used for other purposes... 

    As i understood from your reply, what i configure in keil is going to be the total amount of memory i can use in my device ?? (code + other purposes) 


    What about the other problems? 

    I think the question is easy.. but i dont know how to solve it: 

    With this everything is ok : 

    pg_size = NRF_FICR->CODEPAGESIZE;
    pg_num = NRF_FICR->CODESIZE-1; // Use last page in flash
    //--------------------------------- 
    addr = (uint32_t *)(pg_size * pg_num); 
    flash_page_erase(addr); 
    patwr_32 = 'D'; 
    flash_word_write(addr, patwr_32); 
    nrf_delay_ms(10);

    But i dont know how to store other 32bit words without having hardfaults... 




Related