Stack Overflow from creating freeRTOS task after device configuration auto generated code for FLL

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
stna_4831036
Level 1
Level 1
10 sign-ins First like received First reply posted

Hello,
I use the CYBLE-416045-02 with Modus Toolbox.

I use the device configurator to configure the FLL so that CLK_FAST and CLK_SLOW have 50MHz. I call the generated function init_cycfg_all(); and then I start creating my tasks for freeRTOS. Even with configMINIMAL_STACK_SIZE (128) I get a stack overflow error at the first task.

Before I used the device configurator, I tested everything without the FLL configuration and it worked with a stack size of 1024 for the first task. Therefore, it is clearly the auto-generated code.

How can I solve this?

Greetings

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

stna,

Here's my understanding of PSoC resource allocation and management.  If my understanding is correct, the following might shed some light on your issue.

There are 3 methods to allocated and manage resources on the PSoC.

Device Configuration

This is the method closest to the TopDesign schematic entry process used in PSoC Creator.

It is a high-level tool provided by Infineon to make configuring all IO and internal peripherals theoretically easier.

It is intended as design-time tool.   In other words, at the time of the design and development the HW and FW application designers define what resources are needed by the application including what pins are to be used to match the PCB layout requirements.

This method is generally considered "hard-coding" the assignments since dynamically reassigning fixed peripheral resources at run-time can be complicated (but not impossible).   Because of the "hard-coding" at design-time, it makes this method the easiest and lowest maintenance in the cost as long as the peripherals and IO do not need to be dynamically reassigned. 

To start this configuration in main() is usually just one function call.  Simple.

HAL API calls

The HAL (Hardware Application Layer) calls are the lowest level access of all peripherals and IO pins.  It has as a part of infrastructure knowledge of what PSoC resources are available.  Any attempts to to allocate/deallocate resources not available will yield error codes.  These error codes need to be monitored and  handled properly to avoid failures of running the application.

With HAL calls, resources are allocated and can be deallocated as needed.  This makes dynamic run-time reconfiguration of the PSoC possible and more reliable.

PDL API calls

The PDL (Peripheral Device Library) calls are one-level higher than the HAL calls.   It is intended to provide the advantages of the HAL configuration flexibility while making the calls to the resources easier by commonly grouping peripheral and IO assignments in fewer API calls.

Generally, the user is encouraged to use PDL calls instead of HAL calls if possible.   PDL calls internally call the needed HAL calls for the resources needed without the developer needing to know all the details needed at the HAL-level.

As with the HAL, the PDL has the flexibility of dynamically reallocation of resources at run-time.

Additionally, the error codes returned in the PDL functions should be acted on appropriately and should not be ignored.

What method is best to use?

In general, Device Configuration is the simplest and most straightforward.  However the design intent of the resources are only available using the Device Configuration utility.  Therefore this method works best if the resources are only defined at design-time.

Both the PDL and HAL methods allow you to define the design intentions as comments in the source code at the location of the allocation/and reallocation code sections.  Because resource allocation is explicit in the application code, this allows for "better?" conditional compiling of resource allocation based on compile #defines.

Note:  It is possible to use ALL the 3 methods in your code.  To do so, you show be more aware of how each method manages the resources.

It might be said by others with more experience here that using RTOSs the PDL/HAL methods might be more preferred.  This may be because the peripheral resources used by a task are allocated when the task is started.  This may allow for lower current consumption because resources are started when needed and stopped when not needed.

Back to your issue with the stack

As you indicated your code worked prior to using Device "Configuration" method.

It is possible that the init_cycfg_all() call uses more stack because it is allocating the resource defined in the tool.

This might be the reason the use of the stack is larger.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

3 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

stna,

Here's my understanding of PSoC resource allocation and management.  If my understanding is correct, the following might shed some light on your issue.

There are 3 methods to allocated and manage resources on the PSoC.

Device Configuration

This is the method closest to the TopDesign schematic entry process used in PSoC Creator.

It is a high-level tool provided by Infineon to make configuring all IO and internal peripherals theoretically easier.

It is intended as design-time tool.   In other words, at the time of the design and development the HW and FW application designers define what resources are needed by the application including what pins are to be used to match the PCB layout requirements.

This method is generally considered "hard-coding" the assignments since dynamically reassigning fixed peripheral resources at run-time can be complicated (but not impossible).   Because of the "hard-coding" at design-time, it makes this method the easiest and lowest maintenance in the cost as long as the peripherals and IO do not need to be dynamically reassigned. 

To start this configuration in main() is usually just one function call.  Simple.

HAL API calls

The HAL (Hardware Application Layer) calls are the lowest level access of all peripherals and IO pins.  It has as a part of infrastructure knowledge of what PSoC resources are available.  Any attempts to to allocate/deallocate resources not available will yield error codes.  These error codes need to be monitored and  handled properly to avoid failures of running the application.

With HAL calls, resources are allocated and can be deallocated as needed.  This makes dynamic run-time reconfiguration of the PSoC possible and more reliable.

PDL API calls

The PDL (Peripheral Device Library) calls are one-level higher than the HAL calls.   It is intended to provide the advantages of the HAL configuration flexibility while making the calls to the resources easier by commonly grouping peripheral and IO assignments in fewer API calls.

Generally, the user is encouraged to use PDL calls instead of HAL calls if possible.   PDL calls internally call the needed HAL calls for the resources needed without the developer needing to know all the details needed at the HAL-level.

As with the HAL, the PDL has the flexibility of dynamically reallocation of resources at run-time.

Additionally, the error codes returned in the PDL functions should be acted on appropriately and should not be ignored.

What method is best to use?

In general, Device Configuration is the simplest and most straightforward.  However the design intent of the resources are only available using the Device Configuration utility.  Therefore this method works best if the resources are only defined at design-time.

Both the PDL and HAL methods allow you to define the design intentions as comments in the source code at the location of the allocation/and reallocation code sections.  Because resource allocation is explicit in the application code, this allows for "better?" conditional compiling of resource allocation based on compile #defines.

Note:  It is possible to use ALL the 3 methods in your code.  To do so, you show be more aware of how each method manages the resources.

It might be said by others with more experience here that using RTOSs the PDL/HAL methods might be more preferred.  This may be because the peripheral resources used by a task are allocated when the task is started.  This may allow for lower current consumption because resources are started when needed and stopped when not needed.

Back to your issue with the stack

As you indicated your code worked prior to using Device "Configuration" method.

It is possible that the init_cycfg_all() call uses more stack because it is allocating the resource defined in the tool.

This might be the reason the use of the stack is larger.

Len
"Engineering is an Art. The Art of Compromise."

Firstly, thanks a lot for this really good summary of PSoC resource usage methods!

Especially this: "This may allow for lower current consumption because resources are started when needed and stopped when not needed."
I think I will invest more time and completely write everything myself. These tools seem convenient, but thinking about how much time I already invested to resolve problems with auto-generated code, I don't think it's worth it.

Thanks again and have a nice weekend!
Stefan

 

0 Likes

Stefan,

You're welcome.

Starting and stopping resources to save on power consumption can be accomplished using any of the 3 methods.  Doing using using "Device Configuration" is just a little trickier since the way to eliminate 90% of the current consumed by the resource is to disconnect the clock source to it.

The Device Configuration tool asks what clock is connected to the resource so that it can assign the clock routing and the init_cycfg_all() completes the initialization including the connecting the clocks to each resource.  Under most circumstances there is a way to disconnect the clock after the fact.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes