How to configure K60 to big-endian?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to configure K60 to big-endian?

2,767 次查看
admin
Specialist II

Anyone knows how to configure K60 to big-endian? I am running an application on TWRK60120F120M evaluation system and trying to have the application built with Big endian option. Seems I couldn't chose Big Endian via CodeWarrior 10.5. The Project Settings->C/C++ Build->Sttings shows Endiannes selection but it is default to Little Endian (-mlittle-endian) and is not selectable.

Other than using Codewarrior tool, is there anyway to configure K60 endian through MQX BSP configuration?

0 项奖励
回复
6 回复数

1,624 次查看
BitBangerB
Contributor II

In trying to find a way do deal with endianess issues I found this thread.  Subsequently came to find these little gems that are built into GNU C:

uint16_t __builtin_bswap16 (uint16 t x) [Built-in Function]

Returns x with the order of the bytes reversed; for example, 0xaabb becomes 0xbbaa.

Byte here always means exactly 8 bits.

uint32_t __builtin_bswap32 (uint32 t x) [Built-in Function]

Similar to __builtin_bswap16, except the argument and return types are 32 bit.

uint64_t __builtin_bswap64 (uint64 t x) [Built-in Function]

Similar to __builtin_bswap32, except the argument and return types are 64 bit.

I verified for the 32-bit case that the compiler generates the ARM 'REV' instruction.

0 项奖励
回复

1,624 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

more information,

CW10 can view both endians in view. See below:

http://mcuoneclipse.com/2012/02/19/a-little-or-big-indian-a-plea-for-peace/

we don't have other converters in CodeWarrior.

hope this helps!

1,624 次查看
carlos_neri
NXP Employee
NXP Employee

Ronda,

The core endianness can't change on runtime. In this case, the Cortex M4 is configured for Little endian. Here is a link to ARM documentation (this is for M3 but the same applies for M4):

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka13381.html

Regarding MQX endianness, this is configured as little endian to ensure proper behavior.

May I ask why you need to change the core endianness?

1,624 次查看
carlos_neri
NXP Employee
NXP Employee

I'm afraid the SW must handle byte swapping for your Modbus layer.

You could create a set of inline functions to add ASM instructions to ease this process using CM4 byte reversal instructions and add those in your code. I understand  will be difficult to find where is needed, but so far, is the solution I find on porting a code from big to little endian.

0 项奖励
回复

1,624 次查看
egoodii
Senior Contributor III

FYI, 'intrinsic functions' in IAR make that simple:

lwrd_lend = __REV(lwrd);   //Make from big-endian

These intrinsic functions 'know' about the ongoing register usage and can insert exactly the single machine instruction (where optimizable).

0 项奖励
回复

1,624 次查看
admin
Specialist II

Carlos,

Thanks for the answer. We are trying to port a large application which originally developed for ColdFire based system, so the code is big endian supported. Now we run the application on K60 and found the data transferred over a Modbus TCP is byte swapped. We thought it is may be easier to change the core endianness to big endian for making the whole porting work. We thought K60 is endianness configurable. 

0 项奖励
回复