Data bus error (solved)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data bus error (solved)

3,313 Views
Onemars
Contributor II

Hello,

on a FRDM-K64F demoboard I get an Hard Fault when reading the flash from 0xFE0C0 to 0xFE0CF and from 0xFF0C0 to 0xFF0CF, any other nearby byte can be read without errors. Reading a byte or a full word gives the same error.

From the CFSR register it seems the fault is caused by a "precise data bus error" and BFAR is at the location I'm trying to read.

This is the code, I'm using KDS with a new clean Kinetis SDK 2.x project:

static uint8_t* ptr;
static uint8_t b;
static uint8_t c[16];

int32_t main(void)
{
    BOARD_InitPins();
    BOARD_BootClockRUN();
    {
        // Ok:
        ptr = (uint8_t*)0xFE0BF;
        b = *ptr;
        c[0] = b;

        ptr = (uint8_t*)0xFE0D0;
        b = *ptr;
        c[1] = b;

        ptr = (uint8_t*)0xFF0BF;
        b = *ptr;
        c[2] = b;

        ptr = (uint8_t*)0xFF0D0;
        b = *ptr;
        c[3] = b;

        // Faults:
        ptr = (uint8_t*)0xFE0C0;
        b = *ptr;
        c[4] = b;

        ptr = (uint8_t*)0xFF0C0;
        b = *ptr;
        c[5] = b;
    }
    for(;;)
        __asm("NOP");
}

Am I doing something stupid or is my flash gone bad?

Thank you

Tags (2)
0 Kudos
4 Replies

2,182 Views
Onemars
Contributor II

Mark, problem solved! Thank you very much.
I was absorbed on OpenOCD and I've read your suggestion too late. By the way, good stuff! I'll try it asap.

About the flash erasing with OpenOCD, it is possible that the kinetis driver of OpenOCD is not able to automatically recognizes the second flash bank.
I'm not sure. I'll try to describe my experience, maybe it'll help somebody.

The chip on demoboard is a MK64FN1M0VLL12, it has 1M bytes flash in 2 blocks of 512K bytes.
This article from Erich Styger was very useful, especially the comment by Joakim Fernstad.
Following Erich's guide, to fill everything (except m_flash_config) with 0xFF we need to write:
.space 0x000FFBF0, 0xff
this compiles but gives an OpenOCD error, but if I change the length to 0x00080000 (512Kb) it works (unfortunately it is very slow).
After connecting with telnet to the debugger, you can list the banks:
> flash banks
#0 : kinetis.flash (kinetis) at 0x00000000, size 0x00080000, buswidth 0, chipwidth 0
So or this list is not updated after the automatic recognization or OpenOCD recognizes only the first 512Kb flash bank.

How to configure both the two banks of the FDRM-K64F (based on this):
- go to <KDS folder>\openocd\scripts
- make a copy of 'kinetis.cfg' and rename it to 'kinetis_k64.cfg'
- open the 'kinetis_k64.cfg' change:
# Flash size is detected automatically.
flash bank $_CHIPNAME.flash kinetis 0 0 0 0 $_TARGETNAME
to:
# Configure flash banks
flash bank $_CHIPNAME.flash1 kinetis 0 0x80000 0 0 $_TARGETNAME
flash bank $_CHIPNAME.flash2 kinetis 0x80000 0x80000 0 0 $_TARGETNAME

Test:
- go to <KDS folder>\openocd\bin
- launch the debugger with:
openocd.exe -f kinetis_k64.cfg
- the last line should be (with no errors):
Info : kinetis.cpu: hardware has 6 breakpoints, 4 watchpoints
- open telnet with (probably you need to install it first, see 'enable disable windows features' or use Putty):
telnet localhost 4444
- you should see:
Open On-Chip Debugger
>
- type 'flash bank'
> flash banks
#0 : kinetis.flash1 (kinetis) at 0x00000000, size 0x00080000, buswidth 0, chipwidth 0
#1 : kinetis.flash2 (kinetis) at 0x00080000, size 0x00080000, buswidth 0, chipwidth 0
- if everything is ok, open your project and in the 'Config options' of the OpenOCD debugger (Debug Configurations window) change '-f kinetis.cfg' to '-f kinetis_k64.cfg'

How to erase the second bank:
- in telnet type 'flash erase_sector 1 0 last':
> flash erase_sector 1 0 last
Probing flash info for bank 1
Any changes to flash configuration field will not take effect until next reset
erased sectors 0 through 127 on flash bank 1 in 3.601000s

Warning! If you erase the first bank, the MCU will be secured and you need to do a mass erase to unsecure it (or drag and drop a working .bin example on the MBED drive or use Mark's tools!).

On a side note, this has also solved my previous problem.

Best regards,

Gabriele

0 Kudos

2,182 Views
mjbcswitzerland
Specialist V

Hi

Do a complete erase of the flash and try again. Such corruption is due to incorrect programming at some point (eg. trying to write a phrase which has already bits in it programmed to '0'. Afterwards the line of Flash is corrupt and hard-faults. After a complete erase it will be OK again (until any bad operation take place again).

Regards

Mark

2,182 Views
Onemars
Contributor II

I think you are right on the mark!

Mass erase seems a bit complex on gdb but I'll try.

Thank you

0 Kudos

2,182 Views
mjbcswitzerland
Specialist V

Hi

If you have difficulties with erasing, load code from here to the board
http://www.utasker.com/kinetis/FRDM-K64F.html
and use its command line interface to erase sectors.
You can also experiment with reading, writing, erasing (and making errors in the process). See around 6:00 mark in this video to see the commands: https://www.youtube.com/watch?v=c9GRYXFs9LU

Regards

Mark

0 Kudos