Skip to content

Commit 2454b25

Browse files
author
Cruz Monrreal
authored
Merge pull request #9092 from mprse/stack_unification_sec_try
Interrupt stack size unification + test
2 parents 12980f4 + ef681bf commit 2454b25

File tree

445 files changed

+3177
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

445 files changed

+3177
-596
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019-2019 ARM Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#include "mbed.h"
19+
#include "greentea-client/test_env.h"
20+
#include "unity.h"
21+
#include "utest.h"
22+
23+
#ifdef TARGET_RENESAS
24+
#error [NOT_SUPPORTED] Cortex-A target not supported for this test
25+
#endif
26+
27+
using namespace utest::v1;
28+
29+
extern osThreadAttr_t _main_thread_attr;
30+
extern uint32_t mbed_stack_isr_size;
31+
32+
/* Exception for Nordic boards - BLE requires 2KB ISR stack. */
33+
#if defined(TARGET_NRF5x)
34+
#define EXPECTED_ISR_STACK_SIZE (2048)
35+
#else
36+
#define EXPECTED_ISR_STACK_SIZE (1024)
37+
#endif
38+
39+
#if defined(TARGET_NUCLEO_F070RB) || defined(TARGET_NANO100) || defined(TARGET_STM32F072RB) || defined(TARGET_TMPM46B) || defined(TARGET_TMPM066)
40+
#define EXPECTED_MAIN_THREAD_STACK_SIZE (3072)
41+
#else
42+
#define EXPECTED_MAIN_THREAD_STACK_SIZE (4096)
43+
#endif
44+
45+
#define EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE (4096)
46+
47+
/* Test sizes of ISR stack, main thread stack, default user thread stack.
48+
*
49+
* On some platforms with lower RAM size (e.g. NUCLEO_F070RB - 16 KB RAM) it is impossible
50+
* to create thread with default stack size to check its size, that is why we will
51+
* check only macro which specifies default user thread stack.
52+
*
53+
*/
54+
void stack_size_unification_test()
55+
{
56+
TEST_ASSERT_EQUAL(EXPECTED_ISR_STACK_SIZE, mbed_stack_isr_size);
57+
TEST_ASSERT_EQUAL(EXPECTED_MAIN_THREAD_STACK_SIZE, _main_thread_attr.stack_size);
58+
TEST_ASSERT_EQUAL(EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE, OS_STACK_SIZE);
59+
}
60+
61+
utest::v1::status_t test_setup(const size_t number_of_cases)
62+
{
63+
GREENTEA_SETUP(10, "default_auto");
64+
return verbose_test_setup_handler(number_of_cases);
65+
}
66+
67+
Case cases[] = {
68+
Case("Stack size unification test", stack_size_unification_test)
69+
};
70+
71+
Specification specification(test_setup, cases);
72+
73+
int main()
74+
{
75+
return !Harness::run(specification);
76+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019-2019 ARM Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/** \addtogroup hal_rtc_tests
20+
* @{
21+
*/
22+
23+
#ifndef MBED_STACK_SIZE_UNIFICATION_H
24+
#define MBED_STACK_SIZE_UNIFICATION_H
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/** Test sizes of ISR stack, main thread stack, default user thread stack.
31+
*
32+
* Given is Mbed OS configuration.
33+
* When ISR stack, main thread stack, default user thread stack sizes are defined.
34+
* Then ISR stack size is equal to 1 KB,
35+
* main thread stack size is equal to 4 KB,
36+
* default user thread stack size is equal to 4 KB.
37+
*
38+
* NOTE:
39+
* It is impossible to verify RTOS-less thread stack size since all tests are build with RTOS.
40+
*/
41+
void stack_size_unification_test(void);
42+
43+
/**@}*/
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif
50+
51+
/** @}*/

rtos/TARGET_CORTEX/TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ extern uint32_t __initial_sp[];
2525
extern uint32_t __heap_base[];
2626
extern uint32_t __heap_limit[];
2727

28+
#if !defined(ISR_STACK_SIZE)
29+
#define ISR_STACK_SIZE ((uint32_t)1024)
30+
#endif
31+
2832
/*
2933
* mbed entry point for the MICROLIB toolchain
3034
*

rtos/TARGET_CORTEX/TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@
2727
__value_in_regs struct __argc_argv __rt_lib_init(unsigned heapbase, unsigned heaptop);
2828
void _platform_post_stackheap_init(void);
2929

30+
#if !defined(ISR_STACK_SIZE)
31+
#if (defined(__CC_ARM))
32+
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
33+
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Length[];
34+
#define ISR_STACK_START ((unsigned char*)Image$$ARM_LIB_STACK$$ZI$$Base)
35+
#define ISR_STACK_SIZE ((uint32_t)Image$$ARM_LIB_STACK$$ZI$$Length)
36+
#endif
37+
#endif
38+
3039
#if !defined(HEAP_START)
3140
/* Defined by linker script */
3241
extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
3342
#define HEAP_START ((unsigned char*)Image$$RW_IRAM1$$ZI$$Limit)
34-
#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START))
43+
#define HEAP_SIZE ((uint32_t)((uint32_t)ISR_STACK_START - (uint32_t)HEAP_START))
3544
#endif
3645

3746
/*

rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ static osMutexId_t env_mutex_id;
2929
static mbed_rtos_storage_mutex_t env_mutex_obj;
3030
static osMutexAttr_t env_mutex_attr;
3131

32+
#if !defined(ISR_STACK_SIZE)
33+
#if (defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC_VERSION))
34+
extern uint32_t __StackLimit;
35+
extern uint32_t __StackTop;
36+
#define ISR_STACK_START ((unsigned char*)&__StackLimit)
37+
#define ISR_STACK_SIZE ((uint32_t)((uint32_t)&__StackTop - (uint32_t)&__StackLimit))
38+
#endif
39+
#endif
40+
3241
#if !defined(HEAP_START)
3342
/* Defined by linker script */
3443
extern uint32_t __end__[];
3544
#define HEAP_START ((unsigned char*)__end__)
36-
#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START))
45+
#define HEAP_SIZE ((uint32_t)((uint32_t)ISR_STACK_START - (uint32_t)HEAP_START))
3746
#endif
3847

3948
extern void __libc_init_array(void);

rtos/TARGET_CORTEX/mbed_boot.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ extern "C" {
5050
* @{
5151
*/
5252

53-
/* Define stack sizes if they haven't been set already */
54-
#if !defined(ISR_STACK_SIZE)
55-
#define ISR_STACK_SIZE ((uint32_t)1024)
56-
#endif
57-
5853
/* Heap limits - only used if set */
5954
extern unsigned char *mbed_heap_start;
6055
extern uint32_t mbed_heap_size;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0/device/TOOLCHAIN_GCC_ARM/MPS2.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include "../memory_zones.h"
3232
#include "../cmsis_nvic.h"
3333

34+
#if !defined(MBED_BOOT_STACK_SIZE)
35+
#define MBED_BOOT_STACK_SIZE 0x400
36+
#endif
37+
3438
MEMORY
3539
{
3640
VECTORS (rx) : ORIGIN = MAPPABLE_START, LENGTH = MAPPABLE_SIZE
@@ -66,7 +70,7 @@ MEMORY
6670
*/
6771
ENTRY(Reset_Handler)
6872

69-
STACK_SIZE = 0x400;
73+
STACK_SIZE = MBED_BOOT_STACK_SIZE;
7074

7175
/* Size of the vector table in SRAM */
7276
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0/device/TOOLCHAIN_IAR/MPS2.icf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4848

4949
/*-Sizes-*/
5050
/* Heap and Stack size */
51+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
52+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
53+
}
5154
define symbol __ICFEDIT_size_heap__ = 0x200000;
52-
define symbol __ICFEDIT_size_cstack__ = 0x400;
55+
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
5356
/**** End of ICF editor section. ###ICF###*/
5457

5558
define memory mem with size = 4G;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_ARM_STD/MPS2.sct

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
#include "../memory_zones.h"
3838
#include "../cmsis_nvic.h"
3939

40+
#if !defined(MBED_BOOT_STACK_SIZE)
41+
#define MBED_BOOT_STACK_SIZE 0x400
42+
#endif
43+
4044
#if (defined(__stack_size__))
4145
#define STACK_SIZE __stack_size__
4246
#else
43-
#define STACK_SIZE 0x0400
47+
#define STACK_SIZE MBED_BOOT_STACK_SIZE
4448
#endif
4549

4650
; The vector table is loaded at address 0x00000000 in Flash memory region.
@@ -56,7 +60,7 @@ LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
5660
.ANY (+RO)
5761
}
5862
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
59-
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
63+
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE - STACK_SIZE) { ; RW data
6064
.ANY (+RW +ZI)
6165
}
6266
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_GCC_ARM/MPS2.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ MEMORY
6666
*/
6767
ENTRY(Reset_Handler)
6868

69-
STACK_SIZE = 0x400;
69+
#if !defined(MBED_BOOT_STACK_SIZE)
70+
#define MBED_BOOT_STACK_SIZE 0x400
71+
#endif
72+
73+
STACK_SIZE = MBED_BOOT_STACK_SIZE;
7074

7175
/* Size of the vector table in SRAM */
7276
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M0P/device/TOOLCHAIN_IAR/MPS2.icf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4848

4949
/*-Sizes-*/
5050
/* Heap and Stack size */
51+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
52+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
53+
}
5154
define symbol __ICFEDIT_size_heap__ = 0x200000;
52-
define symbol __ICFEDIT_size_cstack__ = 0x400;
55+
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
5356
/**** End of ICF editor section. ###ICF###*/
5457

5558
define memory mem with size = 4G;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M3/device/TOOLCHAIN_ARM_STD/MPS2.sct

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
#include "../memory_zones.h"
3838
#include "../cmsis_nvic.h"
3939

40+
#if !defined(MBED_BOOT_STACK_SIZE)
41+
#define MBED_BOOT_STACK_SIZE 0x400
42+
#endif
43+
4044
#if (defined(__stack_size__))
4145
#define STACK_SIZE __stack_size__
4246
#else
43-
#define STACK_SIZE 0x0400
47+
#define STACK_SIZE MBED_BOOT_STACK_SIZE
4448
#endif
4549

4650
; The vector table is loaded at address 0x00000000 in Flash memory region.
@@ -56,7 +60,7 @@ LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
5660
.ANY (+RO)
5761
}
5862
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
59-
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
63+
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE - STACK_SIZE) { ; RW data
6064
.ANY (+RW +ZI)
6165
}
6266
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M3/device/TOOLCHAIN_GCC_ARM/MPS2.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ MEMORY
6666
*/
6767
ENTRY(Reset_Handler)
6868

69-
STACK_SIZE = 0x400;
69+
#if !defined(MBED_BOOT_STACK_SIZE)
70+
#define MBED_BOOT_STACK_SIZE 0x400
71+
#endif
72+
73+
STACK_SIZE = MBED_BOOT_STACK_SIZE;
7074

7175
/* Size of the vector table in SRAM */
7276
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M3/device/TOOLCHAIN_IAR/MPS2.icf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4848

4949
/*-Sizes-*/
5050
/* Heap and Stack size */
51+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
52+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
53+
}
5154
define symbol __ICFEDIT_size_heap__ = 0x200000;
52-
define symbol __ICFEDIT_size_cstack__ = 0x400;
55+
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
5356
/**** End of ICF editor section. ###ICF###*/
5457

5558
define memory mem with size = 4G;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M4/device/TOOLCHAIN_ARM_STD/MPS2.sct

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
#include "../memory_zones.h"
3838
#include "../cmsis_nvic.h"
3939

40+
#if !defined(MBED_BOOT_STACK_SIZE)
41+
#define MBED_BOOT_STACK_SIZE 0x400
42+
#endif
43+
4044
#if (defined(__stack_size__))
4145
#define STACK_SIZE __stack_size__
4246
#else
43-
#define STACK_SIZE 0x0400
47+
#define STACK_SIZE MBED_BOOT_STACK_SIZE
4448
#endif
4549

4650
; The vector table is loaded at address 0x00000000 in Flash memory region.
@@ -56,7 +60,7 @@ LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
5660
.ANY (+RO)
5761
}
5862
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
59-
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
63+
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE - STACK_SIZE) { ; RW data
6064
.ANY (+RW +ZI)
6165
}
6266
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M4/device/TOOLCHAIN_GCC_ARM/MPS2.ld

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include "../memory_zones.h"
3232
#include "../cmsis_nvic.h"
3333

34+
#if !defined(MBED_BOOT_STACK_SIZE)
35+
#define MBED_BOOT_STACK_SIZE 0x400
36+
#endif
37+
3438
MEMORY
3539
{
3640
VECTORS (rx) : ORIGIN = MAPPABLE_START, LENGTH = MAPPABLE_SIZE
@@ -66,7 +70,7 @@ MEMORY
6670
*/
6771
ENTRY(Reset_Handler)
6872

69-
STACK_SIZE = 0x400;
73+
STACK_SIZE = MBED_BOOT_STACK_SIZE;
7074

7175
/* Size of the vector table in SRAM */
7276
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/TARGET_FVP_MPS2_M4/device/TOOLCHAIN_IAR/MPS2.icf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE
4848

4949
/*-Sizes-*/
5050
/* Heap and Stack size */
51+
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
52+
define symbol MBED_BOOT_STACK_SIZE = 0x400;
53+
}
5154
define symbol __ICFEDIT_size_heap__ = 0x200000;
52-
define symbol __ICFEDIT_size_cstack__ = 0x400;
55+
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
5356
/**** End of ICF editor section. ###ICF###*/
5457

5558
define memory mem with size = 4G;

0 commit comments

Comments
 (0)