DaveTonyCook

Cant run code from Flash MCF52xx

Discussion created by DaveTonyCook on Sep 30, 2013
Latest reply on Mar 10, 2014 by DaveTonyCook

Hi,

I have found that the code programmed into the internal FLASH of the MCF5216 processor will not run when the code footprint exceeds a specific flash block boundary.

 

The project runs without problem until I increase the executable code size past the 0x40000 mark. The processor will run if I run up to the call and then step over, then continue.  The processor throws an exception if it executes at full speed.

 

I set the project up to have a file named bloat.c and added code until the .text section grew past the 0x00040000.  The code added did nothing eg foo_n(1); where void foo1(int x){switch(x){case 0:break;...so on}} and repeat 'ad nauseum'. Adding calls at 75 bytes/call until my app reached the required address to show up the issue.

'

512k flash part

CW 6.4

Code generation details:

Far code

Far data

compact memory model

 

I have double checked my LCF and it appearers to be without fault.

 

I set up two examples:

1. Below is the function check_memory() which makes a call to subroutine strcmp(). The address’s shown have been recorded from the .map file and show that the call made by the check_memory() is made across the flash block boundary of 0x0004_0000. This code throws an exception. The exception makes no sense. Please see stack frame below

 

Address in FLASH

Function name Called

Source Module

Memory Section

0000_3000

 

 

 

0001_EF5C

 

 

 

0004_006C

an_other_function()

.

.

.

check_memory()

.

.

.

strcmp()

 

an_other_module.c

.

.

.

  1. utility.c
...C_4i_CF_MSL.a
.text....text .text

2. below shows the function check_memory() which makes a call to subroutine strcmp(). The address’s shown have been recorded from the .map file and shows that the call made by check_memory() does not make the call across the flash block boundary of 0x0004_0000. This code runs correctly.

 

Address in FLASHFunction name CalledSource ModuleMemory Section
0000_3000 0001_EF54 0003_FFF0an_other_function()...check_memory()...strcmp()an_other_module.c...
  1. utility.c

.

.

.

C_4i_CF_MSL.a

.text

.

.

.

.text

 

 

 

.text

 

Below is the ‘exception stack frame’ contents just after the exception has been generated by the processor.  The stack frame has been recorded from the stack frame contents captured during a debug cycle and reports the following information:

 

Stack frame

General Description

Value

Description under fault

Format

Records any long word stack pointer misalignment

0x04

?

Fault status

Fault code generated by processor

0x0F

Unsupported on V2 core

Vector

Identifies exception type

251

User interrupt

Program counter

Value just before fault

0x70001F40

Garbage (doesn’t exist)

 

Interestingly enough there is also a call to the sin() library routine that is located at > 0x0004_0000 and this does not cause an exception. I might hazard a guess that it has something to do with operations on memory?

 

Any help greatly received

 

Regards

 

David Cook

Outcomes