Newbie question on memory access and exceptions on HCS12X

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

Newbie question on memory access and exceptions on HCS12X

Jump to solution
1,207 Views
holder
Contributor I

Hi Folks,

  I am new to the HCS12x and have a question regarding memory access and exceptions. If this is FAQ my apology upfront.

 

Setup

CodeWarrior 5.1, target is mc9s12xdt512 and FCS.

 

My question:

What happens to a memory write to a variable in a C program that is const and placed in onboard flash (READ_ONLY) segment C000? Does the program continue running or will it raise an exception and halt?

 

When I run the program on the target hardware it seems to run ok. But when I run it under the Full Chip Simulator (FCS) the simulator halts the program at the write call with error message "Protected at XXXX".

 

On x86 Windows/Linux a bad write like this would cause global protection fault/segmentation fault and core dump.

Will the physical mc9s12xdt512 allow/ignore this bad write but the simulator will stop and alert me?

 

thank you

bob

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
901 Views
kef
Specialist I
  • What happens to a memory write to a variable in a C program that is const and placed in onboard flash (READ_ONLY) segment C000? Does the program continue running or will it raise an exception and halt? 

It is uncommon to write to RO memory. On target S12XD program will continue running. But simulator can help you detecting reads from not initialized memory and writes to read only memories. Simulator allows to modify or create your own memory layout in which all or parts of the flash can be made RW and you won't see those write access errors.

 

S12XE has memory protection unit (MPU), which allows to restrict accesses to read and execute, read and write, or only read. On S12XD there's no MPU, you can only restrict write accesses to RAM, but not to flash.

View solution in original post

0 Kudos
Reply
2 Replies
902 Views
kef
Specialist I
  • What happens to a memory write to a variable in a C program that is const and placed in onboard flash (READ_ONLY) segment C000? Does the program continue running or will it raise an exception and halt? 

It is uncommon to write to RO memory. On target S12XD program will continue running. But simulator can help you detecting reads from not initialized memory and writes to read only memories. Simulator allows to modify or create your own memory layout in which all or parts of the flash can be made RW and you won't see those write access errors.

 

S12XE has memory protection unit (MPU), which allows to restrict accesses to read and execute, read and write, or only read. On S12XD there's no MPU, you can only restrict write accesses to RAM, but not to flash.

0 Kudos
Reply
901 Views
holder
Contributor I

Agreed. Writing to RO segment in flash is not what we want and most likely a bug.

You answered my question - specifically that the physical processor will continue running but the sim will halt.

Thank you for the help.

bob

 

0 Kudos
Reply