• AVR Freaks

Hot!Read Data FLASH = Data Bus Error Exception

Author
Paul PortSol
Super Member
  • Total Posts : 426
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
2019/01/30 09:15:54 (permalink)
0

Read Data FLASH = Data Bus Error Exception

What causes a "Data Bus Error" Exception when I try to read my data previously stored in FLASH that isn't define using const? Is there some "memory management" that tells what flash regions are valid/invalid?
How do I add pages to the "acceptable flash regions"?
 
-----------
 
I've been experimenting with the Harmony "generated application code" for flash, this seems to work fine.
 
Now I'm looking at how can I define a data block in flash (DataFLASH) that won't be overwritten when bootloading or when programming with ICD3.
 
It seems I have to have the object defined in FLASH:
  const uint8_t puDataFlashInit[D_DataFLASH_Len] __attribute__((address(D_DataFLASH_Add))) = { 0x22, 0x33 };//Init Data
and then set "Preserve Project Properties" in Project's ICD3 settings.
But really I'd rather not have the data initted with const so it isn't loaded by ICD3 or bootloader.
I tried attribute "NoLoad" but that seemed to cause weird effects (messed with printf's)
 
If I only define a pointer to the data, and use the pointer only for reading the DataFLASH, then 
a) I get a "Data Bus Error" exception if I only use a pointer to try and read the DataFLASH(no const definition and init data)
b) its OK if defined the data with the const (I can read data using same pointer as in 'a' above)
 
It seems there is something saying "This is valid/invalid flash address space", and it is being set when I do the const line above to allow that address range. How is that accessed in MHC/Harmony/PLIB/other?
 
Using:
PIC32mX370F512H,
DataFLASH @0x9d07e000~0x9d07ffff (2pages = 8Kbytes)
 
Paul
#1

6 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17231
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Read Data FLASH = Data Bus Error Exception 2019/01/30 10:36:00 (permalink)
    0
    Is the Data properly aligned?  32bit access on a 32 bit boundary? 16bit access on a 16 bit boundary?
     
    const uint8_t puDataFlashInit[D_DataFLASH_Len] __attribute__((address(D_DataFLASH_Add))) = { 0x22, 0x33 }
    That is not aligned.
    #2
    Paul PortSol
    Super Member
    • Total Posts : 426
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Read Data FLASH = Data Bus Error Exception 2019/01/30 11:02:51 (permalink)
    0
    Yes.
    It is simply removing the const line that causes the issue.
    There must be something in the build that tells the PIC that that FLASH region exists when const line is there, and is a bus error when the const line isn't there declaring the FLASH data.
     
     
    #3
    muellernick
    Super Member
    • Total Posts : 466
    • Reward points : 0
    • Joined: 2015/01/06 23:58:23
    • Location: Germany
    • Status: offline
    Re: Read Data FLASH = Data Bus Error Exception 2019/01/31 03:48:04 (permalink)
    0
    Hmmm ...
     
    I do have a key-value-store ("persistent memory") in flash (PIC32MX575F256H, but should work on other PIC32MX).
    I didn't reserve any memory in flash, I have to pay attention to avoid overlaps (keep my memory layout in some project header, together with some safeguards). I just define the address like:
    #define APP_KVStoreAddress 0x9D03FC00
    Writing is done through #include "driver/flash/drv_flash.h"
    like:       DRV_FLASH_WriteWord(kvTask->drvHandle, (int32_t) kvTask->kvStore.addrInROM, sentinel);
    Reading through direct access to the FLASH. But the access-functions all work with RAM, so they do a memcopy from FLASH to RAM when reading.

    Keeping stuff aligned (it is a pointer linked list) in memory needs some attention. But you know that already.
     
    That kv-store is wiped when a new firmware is flashed with ICD3. But I don't think you can clear only part of the flash from outside (means a programmer), as this would open doors to crack security. From the firmware running on the PIC, you can erase page-wise, no problem.
     
    Not sure if that helped. :-/
     
    Nick
    #4
    Paul PortSol
    Super Member
    • Total Posts : 426
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Read Data FLASH = Data Bus Error Exception 2019/01/31 05:28:30 (permalink)
    0
    Hi Nick,
    a) You can set a block of flash to be saved and restored after programming using the projects ICD3 setting "Preserve Program Memory". But this is a copy and restore, so it should be security safe according to the PICs cfg bit settings.
     
    b) Don't know why but my PIC32MX370F512H is giving a "data bus error" exception when try to read addresses 0x9d07E000~0x9d07FFFF using just pointers, unless I have a const data defined in that area.
    Maybe there is some PIC memory setting that says "top valid FLASH address" and it is different between our processors, or maybe your flash data is in the middle of the allowed area (code before and after?) so it doesn't get blocked out.
    I can try moving my DataFLASH to middle of code, but I'd prefer to understand what is happening to avoid issues in future.
     
    Paul 
     
     
    #5
    muellernick
    Super Member
    • Total Posts : 466
    • Reward points : 0
    • Joined: 2015/01/06 23:58:23
    • Location: Germany
    • Status: offline
    Re: Read Data FLASH = Data Bus Error Exception 2019/01/31 07:32:38 (permalink)
    0
    Hi Paul!
     
    No, there is just code before that block. And yes, it is "in the middle", but just because there is more persistent data following the kv-store. I do have other data that is defined as const (and thus flashed as defined; data is just some default configuration), but still, it is overwritten at a later time when the device is finally configured.
    I looked at my kv-store, as this isn't const and without any data that is flashed by the ICE3. After programming, the kv-store is empty (detected by a sentinel).
     
    But as far as I remember, picking the right address might be picky. There's cached/non-cached memory?
    If you look at your PIC's data sheet memory-layout and my PIC and my address, this might help you. If not, sorry for wasting your time. Have no idea why this shouldn't work on lower numbered PIC32MX.
     
    Nick
    #6
    Paul PortSol
    Super Member
    • Total Posts : 426
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: Read Data FLASH = Data Bus Error Exception 2019/01/31 12:10:16 (permalink)
    0
    I made a fresh project and now it works (that drives me nuts).
    Not sure where but I guess a glitch got in either the Project settings or the MHC settings cause its the same source code.
     
    Thank you for your help.
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5