SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
The UCD3138 reference code provided along with the EVMs (UCD3138PFCEVM-026, UCD3138PSFBEVM-027, UCD3138LLCEVM-028, UCD3138HSFBEVM-029) is written in a way that the program executes mostly in user mode and switches to privileged modes only if it needs to change interrupt configuration or program the flash memory.
The reference code does not often switch between the ARM and Thumb mode. All parts of the code except for the interrupt service routines are executed in Thumb mode in order to save valuable program space.
The file load.asm contains the routines that are the very first part of the code getting executed when control switches from ROM boot-loader to program flash that contains the application firmware.
In order to switch into Thumb mode the following assembly code is included inside the file load.asm.
;*------------------------------------------------------
;* CHANGE TO 16 BIT STATE
;*------------------------------------------------------
ADD r0, pc, #1
BX r0
where BX stands for Branch and Exchange instruction set.
BX r0 assembly instruction derives the target state from bit[0] of r0:
When code is written in C language, the CCS compiler can be directed to build parts of the code in ARM or Thumb mode. This is done through utilization of “--code_state={16|32}” or “-mt“ compiler build options.
Therefore “--code_state=16” and “-mt” have identical effect. Figure 14-1 shows the build options for the entire project.
It can be seen that the “Code State Mode” is set to none, but the “–mt” compiler option is added in the long statement of all compiler built options shown in the upper editable field of the window.
The “–mt” option can be added by selecting the “16-bit State Code (-mt)” check box under the advanced category. This is illustrated in Figure 14-2.
It is preferred that the interrupt service routines run in ARM mode in order to minimize the ISR execution latencies. Interrupts all start out in ARM mode, the interrupt hardware changes the state to ARM mode. It is preferred to stay in ARM mode even when executing the functions called by any of the interrupt service routines. These functions are located in the file interrupt.c.
Figure 14-3 shows the “file specific” build options for the file interrupts.c which includes the interrupt service routines.
It can be seen that the “Code State Mode” is set to 32-BIS Mode (--code_state=32) and the –mt built option is not chosen. This means that the compiler will make sure that the generated assembly code will switch to ARM mode when executing this specific part of the code. And the ARM mode instruction set will be used to perform this section of the code.
For additional information, please refer to the following reference material:
The manuals above will be for the latest version of CCS. The CCS 3.3 manuals can be accessed via the Help button on the CCS window. They are installed with CCS 3.3.