This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cortex M3 - how to enter Privileged Mode?

Note: This was originally posted on 15th July 2009 at http://forums.arm.com

Hi,

I try to get an implementation that disables all interrupts up to an specific level. I use the BASEPRI for this.
However the disabling doesnt work, all interrupts are passing through like before.

At the moment of entering the disabling function the CONTROL register is "0x00".
Now what means 0x00? The Cortex TRM says
CONTROL[0] = 0 is user mode and
CONTROL[0] = 1 is privileged mode.
And the book "The Definitive Guide to the Arm Cortex-M3" says it mixed up:
CONTROL[0] = 1 is user mode and
CONTROL[0] = 0 is privileged mode.

I expect the information in the TRM is the right... is it?

I wonder why my debugger is showing the CONTROL = 0x00 at reset of the device. Should not normally the device start in privileged mode?
Does anyone work with a Cortex M3 and can confirm that?
Parents
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    Hi Ssss,

    CONTROL[0] = 0 is privileged mode
    CONTROL[0] = 1 is user mode

    Could you tell me which page in TRM you are referring to?
    (and which revision of the TRM).

    From page 2-3 of Cortex-M3 revision 2 TRM:
    "Thread mode is privileged out of reset, but you can change it to user or unprivileged by
    setting the CONTROL[0] bit using the MSR instruction."

    That's why the CONTROL register is 0x00 out of reset (privileged).
    Setting CONTROL[0] to 1 will change it to user mode.

    To use BASEPRI, you need to set it to a non-zero value.  For example,
    if 16 priority levels are available, it will be 0x10, 0x20, ... 0xF0.
    If you set it to 0x00, the BASEPRI masking function is disabled.

    However, by default all interrupts are at priority level 0. So they are higher
    priority than any BASEPRI value. As a result, no matter what value you
    set BASEPRI to, the interrupts will still get through.  Therefore, BASEPRI
    can only mask a interrupt if the priority level of the interrupt is not set to 0.

    To mask interrupts with priority level 0, you need to use PRIMASK.
    The easiest way to set PRIMASK is using (in assembly)
       CPSID  i
    or in C:
      __disable_irq();

    regards,
    Joseph
Reply
  • Note: This was originally posted on 15th July 2009 at http://forums.arm.com

    Hi Ssss,

    CONTROL[0] = 0 is privileged mode
    CONTROL[0] = 1 is user mode

    Could you tell me which page in TRM you are referring to?
    (and which revision of the TRM).

    From page 2-3 of Cortex-M3 revision 2 TRM:
    "Thread mode is privileged out of reset, but you can change it to user or unprivileged by
    setting the CONTROL[0] bit using the MSR instruction."

    That's why the CONTROL register is 0x00 out of reset (privileged).
    Setting CONTROL[0] to 1 will change it to user mode.

    To use BASEPRI, you need to set it to a non-zero value.  For example,
    if 16 priority levels are available, it will be 0x10, 0x20, ... 0xF0.
    If you set it to 0x00, the BASEPRI masking function is disabled.

    However, by default all interrupts are at priority level 0. So they are higher
    priority than any BASEPRI value. As a result, no matter what value you
    set BASEPRI to, the interrupts will still get through.  Therefore, BASEPRI
    can only mask a interrupt if the priority level of the interrupt is not set to 0.

    To mask interrupts with priority level 0, you need to use PRIMASK.
    The easiest way to set PRIMASK is using (in assembly)
       CPSID  i
    or in C:
      __disable_irq();

    regards,
    Joseph
Children
No data