Skip to content

Interrupt stack size unification + test #9092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1739d7e
Define heap/stack start and size based on linker script symbols for A…
mprse Dec 20, 2018
01ca844
Add stack size unification test
mprse Dec 5, 2018
55b1c66
[ARM_FM] Support boot stack size configuration option
mprse Dec 17, 2018
0111f5d
[ARM_SSG] Support boot stack size configuration option
mprse Dec 17, 2018
f0ab08a
[Analog_Devices] Support boot stack size configuration option
mprse Dec 17, 2018
5b065c5
[Atmel] Support boot stack size configuration option
mprse Dec 17, 2018
8f230b6
[Cypress] Support boot stack size configuration option
mprse Dec 17, 2018
08004e1
[Freescale] Support boot stack size configuration option
mprse Dec 17, 2018
6d1d08b
[Maxim] Support boot stack size configuration option
mprse Dec 17, 2018
3b17011
[NXP] Support boot stack size configuration option
mprse Dec 17, 2018
c5a67c9
[ONSEMI] Support boot stack size configuration option
mprse Dec 18, 2018
36ff053
[RDA] Support boot stack size configuration option
mprse Dec 18, 2018
3525f6b
[Realtek] Support boot stack size configuration option
mprse Dec 18, 2018
58f6bf7
[STM] Support boot stack size configuration option
mprse Dec 18, 2018
d30a14e
[Silicon_Labs] Support boot stack size configuration option
mprse Dec 18, 2018
9fe7e36
[TOSHIBA] Support boot stack size configuration option
mprse Dec 18, 2018
f74f3c1
[WIZNET] Support boot stack size configuration option
mprse Dec 18, 2018
4a113d2
[ublox] Support boot stack size configuration option
mprse Dec 18, 2018
888f49d
[NORDIC] Support boot stack size configuration option
mprse Dec 21, 2018
4ee9378
[GigaDevice] Support boot stack size configuration option
mprse Dec 21, 2018
d97c4d5
[TT] Support boot stack size configuration option
mprse Jan 3, 2019
ef681bf
Add SPDX-License-Identifier and Copyright in new files
mprse Jan 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
76 changes: 76 additions & 0 deletions TESTS/mbed_hal/stack_size_unification/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* mbed Microcontroller Library
* Copyright (c) 2019-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"

#ifdef TARGET_RENESAS
#error [NOT_SUPPORTED] Cortex-A target not supported for this test
#endif

using namespace utest::v1;

extern osThreadAttr_t _main_thread_attr;
extern uint32_t mbed_stack_isr_size;

/* Exception for Nordic boards - BLE requires 2KB ISR stack. */
#if defined(TARGET_NRF5x)
#define EXPECTED_ISR_STACK_SIZE (2048)
#else
#define EXPECTED_ISR_STACK_SIZE (1024)
#endif

#if defined(TARGET_NUCLEO_F070RB) || defined(TARGET_NANO100) || defined(TARGET_STM32F072RB) || defined(TARGET_TMPM46B) || defined(TARGET_TMPM066)
#define EXPECTED_MAIN_THREAD_STACK_SIZE (3072)
#else
#define EXPECTED_MAIN_THREAD_STACK_SIZE (4096)
#endif

#define EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE (4096)

/* Test sizes of ISR stack, main thread stack, default user thread stack.
*
* On some platforms with lower RAM size (e.g. NUCLEO_F070RB - 16 KB RAM) it is impossible
* to create thread with default stack size to check its size, that is why we will
* check only macro which specifies default user thread stack.
*
*/
void stack_size_unification_test()
{
TEST_ASSERT_EQUAL(EXPECTED_ISR_STACK_SIZE, mbed_stack_isr_size);
TEST_ASSERT_EQUAL(EXPECTED_MAIN_THREAD_STACK_SIZE, _main_thread_attr.stack_size);
TEST_ASSERT_EQUAL(EXPECTED_USER_THREAD_DEFAULT_STACK_SIZE, OS_STACK_SIZE);
}

utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("Stack size unification test", stack_size_unification_test)
};

Specification specification(test_setup, cases);

int main()
{
return !Harness::run(specification);
}
51 changes: 51 additions & 0 deletions TESTS/mbed_hal/stack_size_unification/stack_size_unification.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* mbed Microcontroller Library
* Copyright (c) 2019-2019 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** \addtogroup hal_rtc_tests
* @{
*/

#ifndef MBED_STACK_SIZE_UNIFICATION_H
#define MBED_STACK_SIZE_UNIFICATION_H

#ifdef __cplusplus
extern "C" {
#endif

/** Test sizes of ISR stack, main thread stack, default user thread stack.
*
* Given is Mbed OS configuration.
* When ISR stack, main thread stack, default user thread stack sizes are defined.
* Then ISR stack size is equal to 1 KB,
* main thread stack size is equal to 4 KB,
* default user thread stack size is equal to 4 KB.
*
* NOTE:
* It is impossible to verify RTOS-less thread stack size since all tests are build with RTOS.
*/
void stack_size_unification_test(void);

/**@}*/

#ifdef __cplusplus
}
#endif

#endif

/** @}*/
4 changes: 4 additions & 0 deletions rtos/TARGET_CORTEX/TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ extern uint32_t __initial_sp[];
extern uint32_t __heap_base[];
extern uint32_t __heap_limit[];

#if !defined(ISR_STACK_SIZE)
#define ISR_STACK_SIZE ((uint32_t)1024)
#endif

/*
* mbed entry point for the MICROLIB toolchain
*
Expand Down
11 changes: 10 additions & 1 deletion rtos/TARGET_CORTEX/TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@
__value_in_regs struct __argc_argv __rt_lib_init(unsigned heapbase, unsigned heaptop);
void _platform_post_stackheap_init(void);

#if !defined(ISR_STACK_SIZE)
#if (defined(__CC_ARM))
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[];
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Length[];
#define ISR_STACK_START ((unsigned char*)Image$$ARM_LIB_STACK$$ZI$$Base)
#define ISR_STACK_SIZE ((uint32_t)Image$$ARM_LIB_STACK$$ZI$$Length)
#endif
#endif

#if !defined(HEAP_START)
/* Defined by linker script */
extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
#define HEAP_START ((unsigned char*)Image$$RW_IRAM1$$ZI$$Limit)
#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START))
#define HEAP_SIZE ((uint32_t)((uint32_t)ISR_STACK_START - (uint32_t)HEAP_START))
#endif

/*
Expand Down
11 changes: 10 additions & 1 deletion rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ static osMutexId_t env_mutex_id;
static mbed_rtos_storage_mutex_t env_mutex_obj;
static osMutexAttr_t env_mutex_attr;

#if !defined(ISR_STACK_SIZE)
#if (defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC_VERSION))
extern uint32_t __StackLimit;
extern uint32_t __StackTop;
#define ISR_STACK_START ((unsigned char*)&__StackLimit)
#define ISR_STACK_SIZE ((uint32_t)((uint32_t)&__StackTop - (uint32_t)&__StackLimit))
#endif
#endif

#if !defined(HEAP_START)
/* Defined by linker script */
extern uint32_t __end__[];
#define HEAP_START ((unsigned char*)__end__)
#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START))
#define HEAP_SIZE ((uint32_t)((uint32_t)ISR_STACK_START - (uint32_t)HEAP_START))
#endif

extern void __libc_init_array(void);
Expand Down
5 changes: 0 additions & 5 deletions rtos/TARGET_CORTEX/mbed_boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ extern "C" {
* @{
*/

/* Define stack sizes if they haven't been set already */
#if !defined(ISR_STACK_SIZE)
#define ISR_STACK_SIZE ((uint32_t)1024)
#endif

/* Heap limits - only used if set */
extern unsigned char *mbed_heap_start;
extern uint32_t mbed_heap_size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "../memory_zones.h"
#include "../cmsis_nvic.h"

#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

MEMORY
{
VECTORS (rx) : ORIGIN = MAPPABLE_START, LENGTH = MAPPABLE_SIZE
Expand Down Expand Up @@ -66,7 +70,7 @@ MEMORY
*/
ENTRY(Reset_Handler)

STACK_SIZE = 0x400;
STACK_SIZE = MBED_BOOT_STACK_SIZE;

/* Size of the vector table in SRAM */
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE

/*-Sizes-*/
/* Heap and Stack size */
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
define symbol MBED_BOOT_STACK_SIZE = 0x400;
}
define symbol __ICFEDIT_size_heap__ = 0x200000;
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
#include "../memory_zones.h"
#include "../cmsis_nvic.h"

#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

#if (defined(__stack_size__))
#define STACK_SIZE __stack_size__
#else
#define STACK_SIZE 0x0400
#define STACK_SIZE MBED_BOOT_STACK_SIZE
#endif

; The vector table is loaded at address 0x00000000 in Flash memory region.
Expand All @@ -56,7 +60,7 @@ LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
.ANY (+RO)
}
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE - STACK_SIZE) { ; RW data
.ANY (+RW +ZI)
}
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ MEMORY
*/
ENTRY(Reset_Handler)

STACK_SIZE = 0x400;
#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

STACK_SIZE = MBED_BOOT_STACK_SIZE;

/* Size of the vector table in SRAM */
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE

/*-Sizes-*/
/* Heap and Stack size */
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
define symbol MBED_BOOT_STACK_SIZE = 0x400;
}
define symbol __ICFEDIT_size_heap__ = 0x200000;
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
#include "../memory_zones.h"
#include "../cmsis_nvic.h"

#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

#if (defined(__stack_size__))
#define STACK_SIZE __stack_size__
#else
#define STACK_SIZE 0x0400
#define STACK_SIZE MBED_BOOT_STACK_SIZE
#endif

; The vector table is loaded at address 0x00000000 in Flash memory region.
Expand All @@ -56,7 +60,7 @@ LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
.ANY (+RO)
}
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE - STACK_SIZE) { ; RW data
.ANY (+RW +ZI)
}
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ MEMORY
*/
ENTRY(Reset_Handler)

STACK_SIZE = 0x400;
#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

STACK_SIZE = MBED_BOOT_STACK_SIZE;

/* Size of the vector table in SRAM */
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE

/*-Sizes-*/
/* Heap and Stack size */
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
define symbol MBED_BOOT_STACK_SIZE = 0x400;
}
define symbol __ICFEDIT_size_heap__ = 0x200000;
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
#include "../memory_zones.h"
#include "../cmsis_nvic.h"

#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

#if (defined(__stack_size__))
#define STACK_SIZE __stack_size__
#else
#define STACK_SIZE 0x0400
#define STACK_SIZE MBED_BOOT_STACK_SIZE
#endif

; The vector table is loaded at address 0x00000000 in Flash memory region.
Expand All @@ -56,7 +60,7 @@ LR_IROM2 ZBT_SRAM1_START ZBT_SRAM1_SIZE { ; load region size_region
.ANY (+RO)
}
; NVIC_VECTORS_SIZE Total: 64 vectors = 256 bytes (0x100) to be reserved in RAM
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE) { ; RW data
RW_IRAM1 (ZBT_SRAM2_START + NVIC_VECTORS_SIZE) (ZBT_SRAM2_SIZE - NVIC_VECTORS_SIZE - STACK_SIZE) { ; RW data
.ANY (+RW +ZI)
}
ARM_LIB_STACK (ZBT_SRAM2_START + ZBT_SRAM2_SIZE) EMPTY - STACK_SIZE { ; Stack region growing down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "../memory_zones.h"
#include "../cmsis_nvic.h"

#if !defined(MBED_BOOT_STACK_SIZE)
#define MBED_BOOT_STACK_SIZE 0x400
#endif

MEMORY
{
VECTORS (rx) : ORIGIN = MAPPABLE_START, LENGTH = MAPPABLE_SIZE
Expand Down Expand Up @@ -66,7 +70,7 @@ MEMORY
*/
ENTRY(Reset_Handler)

STACK_SIZE = 0x400;
STACK_SIZE = MBED_BOOT_STACK_SIZE;

/* Size of the vector table in SRAM */
M_VECTOR_RAM_SIZE = NVIC_VECTORS_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ define symbol __ICFEDIT_region_RAM_end__ = ZBT_SRAM2_START + ZBT_SRAM2_SIZE

/*-Sizes-*/
/* Heap and Stack size */
if (!isdefinedsymbol(MBED_BOOT_STACK_SIZE)) {
define symbol MBED_BOOT_STACK_SIZE = 0x400;
}
define symbol __ICFEDIT_size_heap__ = 0x200000;
define symbol __ICFEDIT_size_cstack__ = 0x400;
define symbol __ICFEDIT_size_cstack__ = MBED_BOOT_STACK_SIZE;
/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;
Expand Down
Loading