This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

failing while doing the flashwrite example

hello, i am doing flash read and write in nrf51.for which i have used the C:\nRF5_SDK_12.2.0_f012efa\examples\peripheral\flashwrite\pca10028\blank\arm4 this exampl. but while doing this my nrf51-DK borad stopped response and it showing errors while programming

i have just executed this code , void main() { uint32_t * addr; uint8_t patwr; uint8_t patrd; uint8_t patold; uint32_t i; uint32_t pg_size; uint32_t pg_num;

uint32_t err_code;

err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);

NRF_LOG_INFO("Flashwrite example\r\n");
patold  = 0;
pg_size = NRF_FICR->CODEPAGESIZE;
pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash

while (true)
{
    // Start address:
    addr = (uint32_t *)(pg_size * pg_num);
    // Erase page:
    flash_page_erase(addr);
    i = 0;
    NRF_LOG_INFO("'%p' is the address",(unsigned int)addr);
		  NRF_LOG_INFO("'%d' is the page size",pg_size);
			NRF_LOG_INFO("'%d' is the page number",pg_num);

}} after that it shows the errors can not write on address 0x4000..

can anyone please tell me from which address i have to write data on the flash the default starting page mentioned is 255 and the comment is given in example use last page. i want to ask what pages i can use for saving the data on the flash?

  • FormerMember
    0 FormerMember

    Do you mean that you cannot write to address 0x40000, if so, that's because of the amount of flash on the nRF51822, 256 kB.

    256 kB = 0x40000 bytes

    You can save data in any flash page, as long as it is not used by anything else.

  • thank you sir, i also want to ask that in flashwrite code it is given that pg_size = NRF_FICR->CODEPAGESIZE; pg_num = NRF_FICR->CODESIZE - 1; // Use last page in flash

    //while (true)
    

    // { // Start address: addr = (unsigned int *)(pg_size * pg_num); here it is commented for page no use last page.how can i use first page of flash for writing values pg_num = NRF_FICR->CODESIZE - 1; // Use last page in flash. insted on 1 what is the value for writing data on flash memories first page.

    sir in above msg you told that , "You can save data in any flash page, as long as it is not used by anything else." it means you are saying that all 256 kb memory is available for writing?

    if it is then, i have one question that is,we write the source code what memory nrf51822 uses for strorage of code.is it different from flash memory. or tell me if there is slots of flash for user and for storage suource code ?means i jast want to ask that is the 256 kbytes of flash is divided in between code and for storage of data ?

  • FormerMember
    0 FormerMember in reply to FormerMember

    Yes, the flash is shared between the source code, so the 256 kB is the total amount of flash for both the source code and "application stored data". The source code starts (by default) at address 0x00, and is written continuously from there. After the "end of" the source code, the application can use the rest.

Related