Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Arm Cortex M3 Port Questions - Observations

Posted by Todd on August 30, 2012
I'm fairly new to the Cortex M3 assembly language, but also new to FreeRTOS and was having a look at the function:

void vPortStartFirstTask( void )
{
__asm volatile(
" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
" ldr r0, [r0] \n"
" ldr r0, [r0] \n"
" msr msp, r0\n" /* Set the msp back to the start of the stack. */
" cpsie i\n" /* Globally enable interrupts. */
" svc 0\n" /* System call to start first task. */
" nop\n"
);
}

I liked the idea of using the vector table location to grab the original stack location (and plan to use this in my fault handlers to try and set the stack back to something useful).

I'm wondering why [R0] is read twice in this function. Is that a typo? Or was there a purpose? Because I'm learning the assembly language and processor, this line confused me and I'm just wondering if there's a subtle point about the processor I'm missing that might require the memory to be read twice (or some timing thing going on).

Second question (or maybe this is just a comment) is about the "cpsie i" instruction. I was surprised to find out that the default for this bit is that interrupts are enabled. (Most processors come up with interrupts blocked, and it surprised me that i and f are both unmasked). All the ports I took a look at set this even though it appears the power-on default is enabled for this bit and it's not needed (unless, I suppose, some user code might have disabled it early on).

Finally, the comments that goes along with the functions __enable_fault_irq() and __disable_fault_irq() (which enable/disable the FAULTMASK) I found are probably cut/paste errors from another Arm port perhaps? The comments mention FIQ, which the Cortex doesn't have but as I remember other Arm processors do have.

Minor issues, but as I'm new and learning, I was interested in seeing if I have something wrong.

Thanks.

RE: Arm Cortex M3 Port Questions - Observations

Posted by Todd on August 30, 2012
I realize now why there are two "ldr r0, [r0]"

It's kind of obvious if I'd thought about it longer.

Sorry!

RE: Arm Cortex M3 Port Questions - Observations

Posted by MEdwards on August 31, 2012
Calling FreeRTOS API functions before the scheduler has started will deliberately leave interrupts disabled to make sure interrupts don't use the scheduler functionality before it is ready. It does not use the global interrupt mask though, only basepri. Calling SVC with global interrupts disabled will cause a fault though, so I guess the cpsie instruction just ensures the application or start up code has not disabled interrupts before it calls svc.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists