Difference between revisions of "Using embOS with STM32CubeMX"

From SEGGER Wiki
Jump to: navigation, search
m (Integrating embOS)
Line 1: Line 1:
  +
'''[[embOS]] for Cortex-M''' was granted the '''MadeForSTM32''' label. As part of that, SEGGER offers an '''embOS expansion for STM32CubeMX''' that allows users to generate and configure embOS projects for virtually all STM32 devices and various IDEs. This article provides further information on its usage.
This article describes how '''embOS''' may be used with '''STM32CubeMX'''.
 
   
 
== MadeForSTM32 ==
 
== MadeForSTM32 ==
''MadeForSTM32'' is a new quality label delivered by ST and is granted after an extended evaluation process. It helps engineers identify software solutions with the highest level of integration and quality for the STM32 microcontrollers’ ecosystem.
+
''MadeForSTM32'' is a new quality label delivered by ST and is granted after an extended evaluation process. It helps engineers identify software solutions with the highest level of integration and quality for the STM32 microcontrollers' ecosystem.
   
''embOS'' was one of the first solutions to receive the ''MadeForSTM32 (v1)'' label in an advanced collaboration of ''SEGGER'' and ''ST Microelectronics''. As a result, ''SEGGER'' has published the official ''I-CUBE-EMBOS expansion for STM32CubeMX'', which may be used to generate ready-to-go embOS projects for use with ST's STM32F746G-Discovery board and various IDEs. Furthermore, it may also be used as a starting point for creating further ''embOS'' projects for different evaluation boards and devices.
+
''embOS'' was one of the first solutions to receive the ''MadeForSTM32'' (v1) label in an advanced collaboration of ''SEGGER'' and ''ST Microelectronics'' and has since been certified to ''MadeForSTM32'' (v2) as well. As a result, ''SEGGER'' has published the official ''I-CUBE-EMBOS expansion for STM32CubeMX'', which may be used to generate ready-to-go embOS projects for virtually all Cortex-M devices and various IDEs.
   
For more information on ''MadeForSTM32'' and the ''I-CUBE-EMBOS'' expansion, please visit [https://www.segger.com/products/rtos/embos/tools/third-party-support/made-for-stm32/ SEGGER.com].
+
For more information on ''MadeForSTM32'', please visit [https://www.segger.com/products/rtos/embos/tools/third-party-support/made-for-stm32/ SEGGER.com].
   
== Creating projects from scratch ==
+
== embOS expansion for STM32CubeMX ==
  +
The '''embOS expansion for STM32CubeMX''' contains the '''embOS CMSIS-Pack''', which may also be used independently of STM32CubeMX.<br />
To use ''embOS'' with ''STM32CubeMX'', customers may either
 
  +
This article focuses on its usage in STM32CubeMX. For its independent usage, please refer to [[Using embOS in CMSIS-Pack projects]].
* use the ''I-CUBE-EMBOS expansion for STM32CubeMX'' and adapt it to their desired target hardware,
 
* generate a project in ''STM32CubeMX'' and subsequently add all generated HAL files and further sources to the shipped ''embOS'' start project for their desired target hardware, or
 
* generate a project in ''STM32CubeMX'' and subsequently add ''embOS'' to that generated project.
 
   
  +
=== Download ===
This article will walk readers through the latter approach. The described configuration of the target application in STM32CubeMX, however, applies to and must therefore be followed in either approach.
 
  +
The embOS expansion for STM32CubeMX may be obtained from [https://www.segger.com/downloads/embos/SEGGER.I-CUBE-embOS SEGGER.com].
   
  +
After download, the *.pack-file may be accessed or extracted like a *.zip-file and contains the following files and folders:
=== Steps to perform in CubeMX ===
 
  +
[[File:ICUBE FolderStructure.png|none|embOS I-CUBE folder structure]]
==== Creating the basic project ====
 
  +
<br />
Start ''STM32CubeMX'' and create a project for any specific target hardware. For this walk-through, we create a project for the ''32F429IDISCOVERY'' board, but chosing any different evaluation board or device will work as well. After the project was initialized, feel free to add clock configurations, GPIO settings, third-party middleware compontents and further settings as needed. The result should look similar to the screenshot below:
 
   
  +
{| class="seggertable"
[[File:CubeMX_InitialProject.png|800px]]
 
  +
|-
  +
! style="width: 25%;" | File / Folder || style="width: 70%;" | Description
  +
|-
  +
| ''Middlewares''\ || Contains the embOS documentation, pre-build libraries, include files and target source files for use with GNU, IAR and Keil toolchains
  +
|-
  +
| ''Projects''\ || Contains a pre-generated STM32CubeMX example project for the STM3240G-Eval board each for IAR Embedded Workbench, arm Keil µVision, and STM32CubeIDE
  +
|-
  +
| ''STM32CubeMX''\ || Contains additional source code templates for code generation using STM32CubeMX
  +
|-
  +
| License.txt || The license agreement under which this software pack is provided
  +
|-
  +
| ReadMe.txt || Trouble-shooting guide for this software pack (also available in [[#Trouble-shooting]])
  +
|-
  +
| SEGGER.I-CUBE-embOS.pdsc || The Pack description file for this software pack
  +
|}
   
  +
=== Installation ===
When done configuring the project, begin to adapt it for ''embOS'' along the guidelines given in the following sections.
 
  +
The embOS expansion for STM32CubeMX may be used as-is: it does not need to be extracted before installing it in STM32CubeMX.
  +
<br />
   
  +
To install it, the following steps should be taken:
==== Interrupt priorities for embOS ====
 
  +
# Upon starting STM32CubeMX, select ''Help -> Manage embedded software packages''
To prepare the project for use with ''embOS'', care needs to be taken of the required interrupt handlers for using ''embOS'' with [[Cortex-M]] devices. To do so, navigate to ''System Core'' in the menu outline and select ''NVIC''. In the editor window, select the ''NVIC'' tab and check the ''Enabled'' checkbox for both the ''Pendable request for system service'' and ''System tick timer'' as shown below:
 
  +
# Select ''From Local ...'' and specify the downloaded ''SEGGER.I-CUBE-embOS.1.2.0.pack'' (installs V1.2.0 of the pack, file name may differ for later versions)
   
  +
This will extract the pack to your local ''STM32Cube repository'' and make it available in the Packages Manager as shown below:
[[File:CubeMX_InterruptPriorities.png|800px]]
 
  +
[[File:embOS CMSIS Installed CubeMX.png|none|embOS expansion for STM32CubeMX installed in STM32CubeMX]]
   
  +
=== Usage ===
Please also note the column ''Preemption Priority''. With ''embOS'' for Cortex-M, specific rules for [[Interrupt prioritization]] apply:
 
  +
After sucessfull installation, the embOS expansion for STM32CubeMX can be used to generate various projects with embOS.
* embOS utilizes the ''Pendable request for system service'' to perform context switches; it must use the lowest priority in the entire system in all cases. Hence, it gets configured for a priority of ''15'' in this example.
 
  +
<br />
* embOS utilizes the ''System tick timer'' to generate a time base; it may use any valid priority for an embOS interrupt. Typically, however, using the second-to-lowest priority in the entire system is advised. In this example, it therefore gets configured for a priority of ''14''.
 
  +
Here, a project for the STM3240G-Eval board and the IAR Embedded Workbench is created, but the same steps should be applied when creating a project for any other evaluation board or device and/or any other IDE.
* In case your application utilizes further interrupts (that shall use embOS API), please ensure these are configured for [[Interrupt prioritization|valid embOS interrupt priorities]] as well.
 
   
==== Interrupt handler generation for embOS ====
+
==== Creating the basic project ====
  +
Start STM32CubeMX and create a project for the desired target hardware. After the project was initialized, feel free to add clock configurations, GPIO settings and further settings as needed. The result should resemble the screenshot below:
''STM32CubeMX'' may generate handlers for specific interrupt sources.
 
* Since ''embOS'' includes its own handler implementation for the ''Pendable request for system service'', that handler may not be generated by ''STM32CubeMX''. To disable its creation, switch to the ''Code generation'' tab and uncheck the ''Generate IRQ handler'' checbox for this specific handler.
 
* While ''embOS'' includes a handler implementation for the ''System tick timer'' as well, a seperate handler should be generated by ''STM32CubeMX''. It should call HAL API functions (enable via according checkbox), which we will later use to call embOS' own handler implementation as a callback.
 
* In case your application utilizes further interrupts, appropiate handlers for these may be generated as required.
 
 
[[File:CubeMX_ISRGeneration.png|800px]]
 
 
=== Steps to perform in the IDE and project files ===
 
==== Integrating embOS ====
 
After generating the project, open its location in the file system:
 
 
[[File:CubeMX_FileSystem.png|800px]]
 
 
This folder structure may be extended as needed. For the integration of embOS, for example, you may want to add a folder ''embOS'' with subfolders ''Inc'', ''Lib'', ''SEGGER'', and ''Setup''.
 
 
Subsequently, copy all relevant files from your shipment of embOS (or, alternatively, from an embOS evaluation version) to the created subfolders:
 
# To the ''Inc'' folder, copy all files from {SHIPMENT_ROOT}\Start\Inc\:
 
## BSP.h (optional)
 
## BSP_UART.h (optional)
 
## Global.h
 
## JLINKMEM.h
 
## OS_Config.h
 
## RTOS.h
 
# To the ''Lib'' folder, copy one appropriate library from {SHIPMENT_ROOT}\Start\Lib\:
 
#*e.g. for GCC-based projects:
 
#** libosT7VHLDP.a (debug & profiling build of embOS for ARMv7-M little-endian devices with FPU using the [[GCC floating-point options|hard floating-point ABI]])
 
#** libosT7VLDP.a (debug & profiling build of embOS for ARMv7-M little-endian devices with FPU using the [[GCC floating-point options|soft floating-point ABI]])
 
#** libosT7BR.a (release build of embOS for ARMv7-M big-endian devices without FPU)
 
#** libosT6BDP.a (debug & profiling build of embOS for ARMv6-M big-endian devices)
 
#*e.g. for IAR-based projects:
 
#** os7m_tlv_dp.a (debug & profiling build of embOS for ARMv7-M little-endian devices with FPU)
 
#** os7m_tb__r.a (release build of embOS for ARMv7-M big-endian devices without FPU)
 
#** os6m_tb__dp.a (debug & profiling build of embOS for ARMv6-M big-endian devices)
 
#*e.g. for Keil-based projects:
 
#** osT7VLDP.lib (debug & profiling build of embOS for ARMv7-M little-endian devices with FPU)
 
#** osT7BR.lib (release build of embOS for ARMv7-M big-endian devices without FPU)
 
#** osT6BDP.lib (debug & profiling build of embOS for ARMv6-M big-endian devices)
 
# To the ''SEGGER'' folder, copy all files from an appropriate board support package, e.g. from {SHIPMENT_ROOT}\Start\BoardSupport\ST\STM32F429_STM32F429I_Discovery\SEGGER\:
 
## SEGGER.h
 
## SEGGER_RTT.c
 
## SEGGER_RTT.h
 
## SEGGER_RTT_ASM_ARMv7M.S (with ARMv7-M devices only)
 
## SEGGER_RTT_Conf.h
 
## SEGGER_RTT_printf.c (optional)
 
## SEGGER_RTT_Syscalls_GCC.c (optional; GCC-specific source file: different name with embOS for IAR and embOS for Keil MDK)
 
## SEGGER_SYSVIEW.c
 
## SEGGER_SYSVIEW.h
 
## SEGGER_SYSVIEW_Conf.h
 
## SEGGER_SYSVIEW_ConfDefaults.h
 
## SEGGER_SYSVIEW_Config_embOS.c
 
## SEGGER_SYSVIEW_embOS.c
 
## SEGGER_SYSVIEW_embOS.h
 
## SEGGER_SYSVIEW_Int.h
 
# To the ''Setup'' folder, copy the following *.c-files from an appropriate board support package, e.g. from {SHIPMENT_ROOT}\Start\BoardSupport\ST\STM32F429_STM32F429I_Discovery\Setup\:
 
## BSP.c (optional)
 
## BSP_SDRAM.c (optional)
 
## JLINKMEM_Process.c
 
## OS_Error.c
 
## OS_MallockLock.c (GCC-specific source file: different name with embOS for IAR and embOS for Keil MDK)
 
## OS_Syscalls.c (GCC-specific source file: different name with embOS for IAR and embOS for Keil MDK)
 
## RTOSInit_STM32F4xx.c
 
 
Open the project and add the folders and files to it. The result should resemble the given example below (which uses the Eclipse-based STM32CubeIDE):
 
 
[[File:CubeMX_ProjectTree.png|800px]]
 
 
In the next step, configure the include paths for embOS header files:
 
 
[[File:CubeMX_Includes.png|800px]]
 
 
Configure the linker settings for the embOS library (required with Eclipse-based IDEs, but not with e.g. IAR):
 
 
[[File:CubeMX_Lib.png|800px]]
 
[[File:CubeMX_LibPath.png|800px]]
 
 
Configure the preprocessor options for your application (must match the chosen embOS library configuration):
 
 
[[File:CubeMX_PreProc.png|800px]]
 
 
After these configurations, embOS was fully integrated with the project.
 
 
==== Modifications to the linker file ====
 
embOS expects specific symbols in order to retrieve information about stack and heap in your project:
 
* __heap_end__
 
* __heap_start__
 
* __stack_end__
 
* __stack_start__
 
 
These symbols need to be added to the linker file, which is the generated *.ld-file in the project's root path, as shown below:
 
 
[[File:CubeMX_Linker.png|800px]]
 
   
  +
[[File:CubeMX GenericProject.png|none|Basic project for the STM3240G-Eval in STM32CubeMX]]
==== Merging the embOS tick with the generated SysTick_Handler() ====
 
Since ''STM32CubeMX'' already initializes the hardware timer and the ''SysTick'' interrupt, some configurations inside RTOSInit_*.c must be removed.
 
   
  +
==== Adding embOS to the project ====
Open RTOSInit_*.c and perform the following changes to ''OS_InitHW()'':
 
  +
Now, select ''Software Packs -> Select components'' and add embOS to the project. To do so, select the required components:
  +
* SEGGER.I-CUBE.embOS
  +
** RTOS embOS
  +
**# embOS API configuration
  +
**#* Native (allows usage of embOS native API only)
  +
**#* CMSIS-RTOS (allows usage of embOS native API and CMSIS-RTOS (v1) API)
  +
**#* CMSIS-RTOS2 (allows usage of embOS native API and CMSIS-RTOS (v2) API)
  +
**# [https://www.segger.com/doc/UM01001_embOS.html#Different_builds_of_embOS embOS kernel configuration]
  +
**#* Debug and Trace
  +
**#* Debug and Profiling
  +
**#* Debug
  +
**#* Stack check and Profiling
  +
**#* Stack check
  +
**#* Release
  +
**#* Extreme Release
   
  +
An optional embOS sample application may be added as well. However, we do not recommend adding one of these with STM32CubeMX, for this will result in duplicate implementations of ''main()''. Instead, we will customize a sample application in STM32CubeMX later on.
[[File:CubeMX_RTOSInit_InitHW.png|1200px]]
 
   
  +
For example, for a ''Debug and Profiling'' configuration using the native embOS API, the Component Selector window would look as shown below:
Furthermore, the ''SysTick_Handler()'' for embOS should now be used as a callback for the generated handler. To do so, apply the following modification to RTOSInit_*.c as well:
 
  +
[[File:embOS CMSIS Configured CubeMX.png|none|embOS CMSIS-Pack project configured in STM32CubeMX]]
   
  +
Feel free to add further components as desired.
[[File:CubeMX_RTOSInit_SysTick.png|1200px]]
 
  +
<br />
  +
After clsoing the component selector, the selected embOS components need to be activated in the ''Software Packs -> Mode'' view:
  +
[[File:embOS CMSIS Enabled CubeMX.png|none|embOS CMSIS-Pack project configured in STM32CubeMX]]
   
  +
==== Customizing the sample application ====
For the generated handler to actually call the callback function, add the following line to the generated SysTick_Handler() implementation, which can be found in stm32f*_it.c inside the ''Src'' folder of the generated project:
 
  +
Now, ''Software Packs -> Configuration'' may be used to customize the generation of ''main.c'' (i.e. the sample application) for demonstrating embOS' usage. A real-world application would need to modify the generated source code manually in order to fully customize the application, which is not possible with STM32CubeMX itself.
   
  +
In this example, we will implement one task body and create two extended tasks executing that body, and also implement and create one software timer. Hence, the ''Tasks'' tab would look like this:
[[File:CubeMX_SysTick_Handler.png|800px]]
 
  +
[[File:embOS_CubeMX_Tasks.png|none|Tasks tab]]
   
  +
The ''Software timer'' tab would like as follows:
==== Handle duplicate syscalls implementation ====
 
  +
[[File:embOS_CubeMX_Timer.png|none|Timers tab]]
The files syscalls.c and sysmem.c should be excluded from build in the project, since their contents are already implemented in OS_Syscalls.c with ''embOS''.
 
The files may be found in the ''Src'' folder:
 
   
  +
Feel free to add further embOS objects to your application as desired.
[[File:CubeMX_Excluded_Files.png|200px]]
 
   
==== Add an embOS application ====
+
==== Generating and executing the project ====
  +
The STM32CubeMX configuration may now be used to create a project for the desired IDE. In this example, we create a project for IAR Embedded Workbench. After creation, open the project which should resemble the following structure:
To use embOS in the project, main.c needs to be modified to include the following:
 
  +
[[File:embOS CubeMX compiled IAR.png|none|embOS CMSIS-Pack project compiled in IAR Embedded Workbench]]
# Inclusion of RTOS.h
 
# Declaration of task control block and task stack
 
# A function which will be run as the task
 
# embOS kernel and task initialization:
 
## ''OS_Init()''
 
## ''OS_InitHW()''
 
## ''OS_TASK_CREATE()'', with task control block, task name, priority, function name and task stack
 
## ''OS_Start()''
 
   
  +
Subsequently, the project may be compiled without warning or error and executed in hardware.
The resulting modifications to main.c should therefore resemble the following example:
 
  +
<br />
  +
Feel free to modify it and add your own application to the project.
   
  +
=== Trouble-shooting ===
[[File:CubeMX_Main_embOS.png|800px]]
 
  +
==== Linker Symbols with arm Keil µVision ====
  +
When creating projects for arm Keil µVision, manual modification may be required to the used start-up file (e.g. startup_stm32f407xx.s):
  +
<br />
  +
If the linker cannot find ''Stack_Mem'', an ''EXPORT'' directive for that symbol is missing in the start-up file. To resolve this, please add
  +
EXPORT Stack_Mem
  +
to the start-up file.
   
  +
==== Linker Symbols with GNU toolchains ====
Subsequently, the application may be compiled and executed in hardware.
 
  +
When creating projects for GNU toolchains, manual modification may be required to the used linker file (e.g. STM32F407IGHX_FLASH.ld):
From here, feel free to modify the initial task, to add further tasks, OS objects and interrupt service routines to create your own embOS application.
 
  +
<br />
  +
If the linker cannot find ''__stack_start__'' and/or ''__stack_end__'', these symbols are not defined in the linker file. To resolve this, please replace
  +
. = . + _Min_Stack_Size;
  +
by
  +
__stack_start__ = .;
  +
. = . + _Min_Stack_Size;
  +
__stack_end__ = .;
  +
in the linker file.

Revision as of 17:16, 9 June 2021

embOS for Cortex-M was granted the MadeForSTM32 label. As part of that, SEGGER offers an embOS expansion for STM32CubeMX that allows users to generate and configure embOS projects for virtually all STM32 devices and various IDEs. This article provides further information on its usage.

MadeForSTM32

MadeForSTM32 is a new quality label delivered by ST and is granted after an extended evaluation process. It helps engineers identify software solutions with the highest level of integration and quality for the STM32 microcontrollers' ecosystem.

embOS was one of the first solutions to receive the MadeForSTM32 (v1) label in an advanced collaboration of SEGGER and ST Microelectronics and has since been certified to MadeForSTM32 (v2) as well. As a result, SEGGER has published the official I-CUBE-EMBOS expansion for STM32CubeMX, which may be used to generate ready-to-go embOS projects for virtually all Cortex-M devices and various IDEs.

For more information on MadeForSTM32, please visit SEGGER.com.

embOS expansion for STM32CubeMX

The embOS expansion for STM32CubeMX contains the embOS CMSIS-Pack, which may also be used independently of STM32CubeMX.
This article focuses on its usage in STM32CubeMX. For its independent usage, please refer to Using embOS in CMSIS-Pack projects.

Download

The embOS expansion for STM32CubeMX may be obtained from SEGGER.com.

After download, the *.pack-file may be accessed or extracted like a *.zip-file and contains the following files and folders:

embOS I-CUBE folder structure


File / Folder Description
Middlewares\ Contains the embOS documentation, pre-build libraries, include files and target source files for use with GNU, IAR and Keil toolchains
Projects\ Contains a pre-generated STM32CubeMX example project for the STM3240G-Eval board each for IAR Embedded Workbench, arm Keil µVision, and STM32CubeIDE
STM32CubeMX\ Contains additional source code templates for code generation using STM32CubeMX
License.txt The license agreement under which this software pack is provided
ReadMe.txt Trouble-shooting guide for this software pack (also available in #Trouble-shooting)
SEGGER.I-CUBE-embOS.pdsc The Pack description file for this software pack

Installation

The embOS expansion for STM32CubeMX may be used as-is: it does not need to be extracted before installing it in STM32CubeMX.

To install it, the following steps should be taken:

  1. Upon starting STM32CubeMX, select Help -> Manage embedded software packages
  2. Select From Local ... and specify the downloaded SEGGER.I-CUBE-embOS.1.2.0.pack (installs V1.2.0 of the pack, file name may differ for later versions)

This will extract the pack to your local STM32Cube repository and make it available in the Packages Manager as shown below:

embOS expansion for STM32CubeMX installed in STM32CubeMX

Usage

After sucessfull installation, the embOS expansion for STM32CubeMX can be used to generate various projects with embOS.
Here, a project for the STM3240G-Eval board and the IAR Embedded Workbench is created, but the same steps should be applied when creating a project for any other evaluation board or device and/or any other IDE.

Creating the basic project

Start STM32CubeMX and create a project for the desired target hardware. After the project was initialized, feel free to add clock configurations, GPIO settings and further settings as needed. The result should resemble the screenshot below:

Basic project for the STM3240G-Eval in STM32CubeMX

Adding embOS to the project

Now, select Software Packs -> Select components and add embOS to the project. To do so, select the required components:

  • SEGGER.I-CUBE.embOS
    • RTOS embOS
      1. embOS API configuration
        • Native (allows usage of embOS native API only)
        • CMSIS-RTOS (allows usage of embOS native API and CMSIS-RTOS (v1) API)
        • CMSIS-RTOS2 (allows usage of embOS native API and CMSIS-RTOS (v2) API)
      2. embOS kernel configuration
        • Debug and Trace
        • Debug and Profiling
        • Debug
        • Stack check and Profiling
        • Stack check
        • Release
        • Extreme Release

An optional embOS sample application may be added as well. However, we do not recommend adding one of these with STM32CubeMX, for this will result in duplicate implementations of main(). Instead, we will customize a sample application in STM32CubeMX later on.

For example, for a Debug and Profiling configuration using the native embOS API, the Component Selector window would look as shown below:

embOS CMSIS-Pack project configured in STM32CubeMX

Feel free to add further components as desired.
After clsoing the component selector, the selected embOS components need to be activated in the Software Packs -> Mode view:

embOS CMSIS-Pack project configured in STM32CubeMX

Customizing the sample application

Now, Software Packs -> Configuration may be used to customize the generation of main.c (i.e. the sample application) for demonstrating embOS' usage. A real-world application would need to modify the generated source code manually in order to fully customize the application, which is not possible with STM32CubeMX itself.

In this example, we will implement one task body and create two extended tasks executing that body, and also implement and create one software timer. Hence, the Tasks tab would look like this:

Tasks tab

The Software timer tab would like as follows:

Timers tab

Feel free to add further embOS objects to your application as desired.

Generating and executing the project

The STM32CubeMX configuration may now be used to create a project for the desired IDE. In this example, we create a project for IAR Embedded Workbench. After creation, open the project which should resemble the following structure:

embOS CMSIS-Pack project compiled in IAR Embedded Workbench

Subsequently, the project may be compiled without warning or error and executed in hardware.
Feel free to modify it and add your own application to the project.

Trouble-shooting

Linker Symbols with arm Keil µVision

When creating projects for arm Keil µVision, manual modification may be required to the used start-up file (e.g. startup_stm32f407xx.s):
If the linker cannot find Stack_Mem, an EXPORT directive for that symbol is missing in the start-up file. To resolve this, please add

       EXPORT  Stack_Mem

to the start-up file.

Linker Symbols with GNU toolchains

When creating projects for GNU toolchains, manual modification may be required to the used linker file (e.g. STM32F407IGHX_FLASH.ld):
If the linker cannot find __stack_start__ and/or __stack_end__, these symbols are not defined in the linker file. To resolve this, please replace

       . = . + _Min_Stack_Size;

by

       __stack_start__ = .;
       . = . + _Min_Stack_Size;
       __stack_end__ = .;

in the linker file.