5

is there a reason for stm32F103C8xx to be big endian and is it possible to change to little endian?

I have a 16bit oriented addressing scheme that I need to send over wire and other side expects MSB first. Any other sugguestion?

To answer how I am doing it, here is the method (which doesn't answer the question of course).

typedef union ___address{
    uint16_t address;
    uint8_t addr_byte[2] ;

} my_addr;

Just use it as two times 8 bit in reverse order, my_addr.addr_byte[1] then my_addr.addr_byte[0].

user505160
  • 1,010
  • 5
  • 16
  • 26

2 Answers2

9

The STM32F103 uses a little-endian format in the memory as explained in the programming manual on page 30. This is also my experience as I didn't have to switch around bytes when exchanging numbers with my PC (which is a little endian machine of course).

Also as explained on the ARM Knowledge page the Cortex M3 does not support dynamic endianness switching, so you are stuck with whatever the manufacturer deemed right.

You can check the AIRCR.ENDIANNESS bit, just to be 100% sure. If it reads 0 it's a little-endian memory, if it's 1 it uses big-endian.

If you are hitting performance problems because of the byte swapping, you might be able to get around those with the use of REV, REV16 and REVSH assembler instructions (don't know if your compiler does this by itself already).

Arsenal
  • 17,464
  • 1
  • 32
  • 59
6

All STM32 MCUs (and, indeed, most ARM Cortex-M MCUs in general) are little-endian.