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

flashwrite example

Hi, I am a bit confused from the example, in the specs it is said that writing the flash is word allign, and even so the example does something strange:

    do
    {
        NRF_LOG_INFO("Enter char to write to flash\r\n");
        NRF_LOG_FLUSH();
        // Read char from uart, and write it to flash:
        patwr = NRF_LOG_GETCHAR();

        if (patold != patwr)
        {
            patold = patwr;
            flash_word_write(addr, (uint32_t)patwr);
            ++addr;
            i += sizeof(patwr);
            NRF_LOG_INFO("'%c' was written to flash\r\n", patwr);
        }
        // Read from flash the last written data and send it back:
        patrd = (uint8_t)*(addr - 1);
        NRF_LOG_INFO("'%c' was read from flash\r\n\r\n", patrd);
        NRF_LOG_FLUSH();
    }
    while (i < pg_size);

every iteration i is incremented by sizeof(patwr), which is 8 and not 32, and addr is incremented by 32(++addr) which can result in an overflow.

Did I miss anything and it should work fine?

Parents
  • nRF51 and nRF52 SoC is built around a 32-bit ARMRegistered Cortex. Cortex ARM is a 32 bit processor. 32 bit equal to one word. One word is 4 bytes. sizeof(patwr) equal to 1 byte. ++addr equal to ++4 bytes. (uint32_t)patwr equal to 4 bytes of data, just first 3 bytes will be 0. Word aligned mean that it should be 4 bytes data length and also should be word-aligned address.

Reply
  • nRF51 and nRF52 SoC is built around a 32-bit ARMRegistered Cortex. Cortex ARM is a 32 bit processor. 32 bit equal to one word. One word is 4 bytes. sizeof(patwr) equal to 1 byte. ++addr equal to ++4 bytes. (uint32_t)patwr equal to 4 bytes of data, just first 3 bytes will be 0. Word aligned mean that it should be 4 bytes data length and also should be word-aligned address.

Children
Related