How to change endianess settings in cortex m3?

2.6k views Asked by At

I found two statements in cortex m3 guide(red book)

  1. Cortex m3 supports both Little as well as big endianness.
  2. After reset endianness cannot be changed dynamically.

So indirectly it is telling change endianness settings in reset handler, is it so?

If yes, then how to change endianness? Which register need to configuring and where to configure (in reset or in exception handler)

I understand it is not actually good idea to change endianness. But still as a curiosity I wanted to see whether a cortex m3 really supports to both endianness or not?

2

There are 2 answers

4
AudioBubble On BEST ANSWER

The Cortex-M architecture can be configured to support either big-endian or little-endian operation.

However, a specific Cortex-M implementation can only support one endianness -- it's hard-wired into the silicon, and cannot be changed. Every implementation I'm aware of has chosen little-endian.

1
old_timer On

You need to be reading the ARM documentation directly. The Technical Reference Manual touches on things like this. If you actually had the source to the cortex-m3 when building it into a chip then you would see the outer layers and or config options that you can touch.

From the cortex-m3 TRM

SETEND always faults. A configuration pin selects Cortex-M3 endianness.

And then we have it in another hit:

The processor contains a configuration pin, BIGEND, that enables you to select either the little-endian or BE-8 big-endian format. This configuration pin is sampled on reset. You cannot change endianness when out of reset.

Technically it would be possible to build a chip where you could choose, it could be designed with an external strap connected to BIGEND, it could be some fuse or other non-volatile thing that you can touch and then pop reset on the ARM core, could have some other processor or logic that manages the booting of the ARM core and you talk to or program that before releasing reset on the ARM core.

In general it is a bad idea to go against the grain on default endianness for an architecture. ARM in particular now that there are two flavors and the latter (BE-8) being more painful (than BE-32). Granted there are other toolchains than gcc, but even with those the vast majority of the users, the vast majority of the indirect testing is in the native (little-endian) mode. Would even wonder how truly tested the logic is, does anyone outside ARMs design verification actually push that mode? Did they test it hard enough?

Have you tried actually building big endian cortex-m3 code? Since the cortex-m is a 16 bit instruction set (with thumb2 extensions) how does that affect BE-8. With BE-8 on a full sized ARM with ARM instructions the 32 bit data swaps but the 32 bit instructions do not. Perhaps this is in the TRM and I should read more, but does that work the same way on the cortex-m? The 16 bit instructions do not swap but the data does? What about on a full sized arm with thumb instructions? And does the toolchain match what the hardware expects?

BTW what that implies is there is a signal named BIGEND in the logic that you interface when you are building a chip around the cortex-m3 and you can go into that logic and change the default setting for BIGEND (I assume they have provided one) or as I have mentioned above you can add logic in your chip to make it a runtime option rather than compile time.