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

NRF52832 crashing when writing to an array

Hi Everyone,

I am having problems writing to an array in NRF52832 without causing the program crashing at run time.

I declare the array to be 512 uint8_t long 

static uint8_t badBlockTable[512];

then I copy data into the array using FlashPageRead, which reads a page from the NAND flash at a particular address and copies it into the array. 

do {
    for (uint8_t i = 0; i < 2; i++) {
        Build_Address(block_tmp, page_tmp, col_tmp, & addr_tmp);
        err = FlashPageRead(addr_tmp, & badBlockTable[200 * i], 200); //copy data straight to array
        col_tmp += 200;
    }
    Build_Address(block_tmp, page_tmp, col_tmp, & addr_tmp);
    err = FlashPageRead(addr_tmp, & badBlockTable[400], 112); //copy data straight to array
    j++;
    if (j >= 4) {
        NRF_LOG_INFO("Error reading bad block table");
        NRF_LOG_FLUSH();
        break;
    }
    block_tmp = bbt_addr[j];
    col_tmp = 0;
} while (err != 0);

From the code above you can see I call FlashPageRead three times to first copy 2*200 bytes of data then the last 112 bytes of data. 

However when I do this the program would crash from what I suspect to be memory out of bounds exception, if I increase the allocation of array to 520 instead of 512

then the program would run fine.

Does anyone know what's causing this?

Thanks for the help!

Parents
  • I suspect to be memory out of bounds exception

    So what debugging have you done to verify if that actually is the case ?

    Are you using an RTOS or something? There isn't a "memory out of bounds exception" as such on the Cortex-M4.

    But you could be causing a buffer overrun, leading to memory corruption - which, in turn, could cause stuff to crash.

    If you use a 'Debug' build configuration, do you get any useful logs ?

Reply
  • I suspect to be memory out of bounds exception

    So what debugging have you done to verify if that actually is the case ?

    Are you using an RTOS or something? There isn't a "memory out of bounds exception" as such on the Cortex-M4.

    But you could be causing a buffer overrun, leading to memory corruption - which, in turn, could cause stuff to crash.

    If you use a 'Debug' build configuration, do you get any useful logs ?

Children
  • I am not using RTOS, but just J-Link RTT which doesnt seem to give any errors, not too sure if there is an option related to system errors that I could enable, can only see peripheral related debugging. 

    To verify the error, I changed the array size one by one till I got the system to work. I tried debugging it but I couldn't get anything useful out of it. The debugger just hangs on the while( err != 0 ); line as shown by the CMP in disassembly, even though its value is 0. 

  • Hi,

    There is not much information to go on here. You write that your code is stuck in the loop waiting for err to be 0, and that is returned from a function called FlashPageRead() which you have not posted. Please provide more information and code so that we can better understand what is happening.

Related