Problem with changing main_stack_size and process_stack_size

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

Sinalco94
Posts: 7
Joined: Thu Jul 27, 2017 1:29 pm
Has thanked: 1 time

Problem with changing main_stack_size and process_stack_size

Postby Sinalco94 » Thu Aug 17, 2017 10:28 am

Hello everyone,

I have got a question. I tried to change the main_stack_size and the process_stack_size in my chibios project (with ugfx library) from 0x0400 to 0x0F00 to increase the main and the process stack size, because i have a overflow anywhere in my project.

I changed the STM32F407xG.ld (main_stack_size = 0x0F00, process_stack_size = 0x0F00) and my make file (also the main_stack_size and process_stack_size):

Code: Select all

#Makefile for UGFX Embest-STM32-DMSTF4BB

# Einstellungen
   # Unter $(GFXLIB)/tools/gmake_scripts/readme.txt Liste der Variablen
   OPT_OS               = chibios
   OPT_THUMB            = yes
   OPT_LINK_OPTIMIZE      = no
   OPT_CPU               = stm32m4

# uGFX Einstellungen
   # Unter $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk Liste der Variablen
   GFXLIB               = ../../ugfx
   GFXBOARD            = Embest-STM32-DMSTF4BB
   GFXDEMO               = modules/gdisp/basics

# ChibiOS Einstellungen
ifeq ($(OPT_OS),chibios)
   # Unter $(GFXLIB)/tools/gmake_scripts/os_chibios_x.mk Liste der Variablen
   CHIBIOS            = ../../chibios26
   CHIBIOS_VERSION      = 2
   CHIBIOS_BOARD      =
   CHIBIOS_PLATFORM   = STM32F4xx
   CHIBIOS_PORT      = GCC/ARMCMx/STM32F4xx
   CHIBIOS_LDSCRIPT   = STM32F407xG.ld
endif

##############################################################################################
# Weiteres für's Projekt
#

ARCH     = arm-none-eabi-
SRCFLAGS = -ggdb -O0
CFLAGS   =
CXXFLAGS = -fno-rtti
ASFLAGS  =
LDFLAGS  = -Wl,--defsym=__process_stack_size__=0x0F00 -Wl,--defsym=__main_stack_size__=0x0F00
SRC      =
OBJS     =
DEFS     =
LIBS     =
INCPATH  =
LIBPATH  =
LDSCRIPT =

#------------------------------------------------------------------------------
# Includes immer am Ende einbinden
#

include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk
include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk
include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk
# *** Ende ***


But when I compile everything the linker Options look like this:

Code: Select all

Linker Options........
arm-none-eabi-gcc -Wl,--defsym=__process_stack_size__=0x0F00 -Wl,--defsym=__main_stack_size__=0x0F00 -Wl,--defsym=__process_stack_size__=0x400 -Wl,--defsym=__main_stack_size__=0x400 -mcpu=cortex-m4 -falign-functions=16 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -nostartfiles -mthumb -T../../chibios26/os/ports/GCC/ARMCMx/STM32F4xx/ld/STM32F407xG.ld -lm .build/obj/fakethumbfile.o -o .build/PowerSupply.elf
.


There you can see that the process and main stack size is declerated two times (one with 0x0400 and one with 0xF00). Does anyone whats the reason for that? Do I have to change anything else?

I would be very happy if anyone could help me with this problem

Thank you in advance :)

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Problem with changing main_stack_size and process_stack_size

Postby Giovanni » Thu Aug 17, 2017 11:30 am

Hi,

You should not set the stack size in LDOPTS, there are specific variables in the Makefile.

Giovanni

Sinalco94
Posts: 7
Joined: Thu Jul 27, 2017 1:29 pm
Has thanked: 1 time

Re: Problem with changing main_stack_size and process_stack_size

Postby Sinalco94 » Thu Aug 17, 2017 1:48 pm

Ok, I replaced the .ld file with the origin (with 0x0400).
And the LDFLAGS Options are still on main_stack_size = 0x0F00 and process_stack_size = 0x0F00.

But the linker options still include to different stack sizes for main stack and process stack. One with 0x0F00 and one with 0x0400.

Is LDFLAGS the option in the makefile you meant?

Code: Select all

Linker Options........
arm-none-eabi-gcc -Wl,--defsym=__process_stack_size__=0x0F00 -Wl,--defsym=__main_stack_size__=0x0F00 -Wl,--defsym=__process_stack_size__=0x400 -Wl,--defsym=__main_stack_size__=0x400 -mcpu=cortex-m4 -falign-functions=16 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -nostartfiles -mthumb -T../../chibios26/os/ports/GCC/ARMCMx/STM32F4xx/ld/STM32F407xG.ld -lm .build/obj/fakethumbfile.o -o .build/PowerSupply.elf
.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Problem with changing main_stack_size and process_stack_size

Postby Giovanni » Thu Aug 17, 2017 3:21 pm

Hi,

Those makefiles are not the ones we provide with ChibiOS, you should ask to the author.

In ChibiOS the stack sizes are set in the makefile, in all demos.

Code: Select all

##############################################################################
# Architecture or project specific options
#

# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
  USE_PROCESS_STACKSIZE = 0x400
endif

# Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
  USE_EXCEPTIONS_STACKSIZE = 0x400
endif

# Enables the use of FPU (no, softfp, hard).
ifeq ($(USE_FPU),)
  USE_FPU = no
endif

#
# Architecture or project specific options
##############################################################################


Giovanni

Sinalco94
Posts: 7
Joined: Thu Jul 27, 2017 1:29 pm
Has thanked: 1 time

Re: Problem with changing main_stack_size and process_stack_size

Postby Sinalco94 » Wed Aug 23, 2017 5:00 pm

So I could solve the problem with the double stacksize declarations. It was a Problem with the ugfx library.

But I still have the Problem with the overflow. How can I found out which stack has an overflow or which thread has an overflow?

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Problem with changing main_stack_size and process_stack_size

Postby steved » Wed Aug 23, 2017 6:33 pm

Enable all the relevant debugging options in chconf.h, and the code will often go to the error loop - you may need to pause the code to see how it got there. (Stack overflows aren't always detected).
If you're using Chibistudio, it'll show you the amount of free stack on each thread (you need the latest update for that)

Or you can just use trial and error - increase the stack until the processor stops crashing, then decrease the sizes again.

(FYI, my uGfx project used USE_PROCESS_STACKSIZE = 0x600h, and the default USE_EXCEPTIONS_STACKSIZE = 0x400. So maybe your problem is more related to code than stack size)


Return to “STM32 Support”

Who is online

Users browsing this forum: Bing [Bot] and 53 guests