This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

User Mode and Supervisor mode

The documentation says that: "By default, threads run in supervisor mode and allow access to privileged CPU instructions, the entire memory address space, and peripherals. User mode threads have a reduced set of privileges."

Also, these two modes are related to macros K_KERNEL_STACK and K_THREAD_STACK. In my CoAP(with Open-Thread) example that is provided from NRf-SDK, K_THREAD_STACK_SIZEOF is used. I think, this example choose user-mode threads. 

What is the reason? Can I choose supervisior mode? Documentation says that it is more efficient with using memory and has privileged access to memory space.    

Parents
  • Hi,

    What sample are you looking at, and what version of NCS are you using?

    User mode is only enabled if CONFIG_USERSPACE is defined.

    In the coap_client sample, CONFIG_USERSPACE is not defined (you can check this for yourself by searching for CONFIG_USERSPACE in <your build folder>/zephyr/.config).

     

    In my CoAP(with Open-Thread) example that is provided from NRf-SDK, K_THREAD_STACK_SIZEOF is used.

     I could not find K_THREAD_STACK_SIZEOF being used in any of the Thread samples in NCS v1.5.0. Where did you find it?

    Anyway, I expect it was used because it works for both kernel and user threads.

    Best regards,

    Didrik

  • k_thread_create(&receive_thread_data, receive_stack_area,
    K_THREAD_STACK_SIZEOF(receive_stack_area),
    (k_thread_entry_t)coap_receive, NULL, NULL, NULL,
    /* Lowest priority cooperative thread */
    K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1), 0,
    K_NO_WAIT);

    It is written in this function. This function is called in coap_init function which is located in coap_utils.c

Reply Children
Related