Skip to content

Commit 24857d0

Browse files
authored
Merge pull request #5285 from c1728p9/minimum_requirements_test
Update devices to have minimum 2K RAM and heap, also added test
2 parents 4c3b3f0 + 37bfc9e commit 24857d0

File tree

17 files changed

+267
-49
lines changed

17 files changed

+267
-49
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "utest/utest.h"
18+
#include "unity/unity.h"
19+
#include "greentea-client/test_env.h"
20+
21+
#include "mbed.h"
22+
23+
using namespace utest::v1;
24+
25+
/**
26+
* This test is intended to gate devices that do not have enough RAM to run
27+
* Mbed os. Devices passing this test should have enough RAM to run all
28+
* other Mbed OS tests.
29+
*
30+
* If your device does not pass this test, then you should determine the
31+
* cause of high memory usage and fix it. If you cannot free enough memory,
32+
* then you should turn off Mbed OS support for this device.
33+
*/
34+
35+
#define MIN_HEAP_SIZE 2048
36+
#define MIN_DATA_SIZE 2048
37+
38+
volatile uint8_t test_buffer[MIN_DATA_SIZE];
39+
40+
static void minimum_heap_test()
41+
{
42+
void *mem = malloc(MIN_HEAP_SIZE);
43+
TEST_ASSERT_NOT_EQUAL(NULL, mem);
44+
free(mem);
45+
}
46+
47+
static void minimum_data_test()
48+
{
49+
// Use test buffer so it is not optimized away
50+
for (int i = 0; i < MIN_DATA_SIZE; i++) {
51+
test_buffer[i] = i & 0xFF;
52+
}
53+
}
54+
55+
56+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
57+
{
58+
GREENTEA_SETUP(30, "default_auto");
59+
return greentea_test_setup_handler(number_of_cases);
60+
}
61+
62+
Case cases[] = {
63+
Case("Minimum heap test", minimum_heap_test),
64+
Case("Minimum data test", minimum_data_test),
65+
};
66+
67+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
68+
69+
int main() {
70+
Harness::run(specification);
71+
}

targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/device/TOOLCHAIN_IAR/MKL25Z4.icf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ define symbol __ICFEDIT_region_NVIC_end__ = 0x1ffff0bf;
1111
define symbol __ICFEDIT_region_RAM_start__ = 0x1ffff0c0;
1212
define symbol __ICFEDIT_region_RAM_end__ = 0x1fffffff;
1313
/*-Sizes-*/
14-
/*Heap 1/4 of ram and stack 1/8*/
15-
define symbol __ICFEDIT_size_cstack__ = 0x800;
16-
define symbol __ICFEDIT_size_heap__ = 0x1000;
14+
define symbol __ICFEDIT_size_cstack__ = 0x400;
15+
define symbol __ICFEDIT_size_heap__ = 0xC00;
1716
/**** End of ICF editor section. ###ICF###*/
1817

1918
define symbol __region_RAM2_start__ = 0x20000000;

targets/TARGET_NUVOTON/TARGET_NANO100/device/TOOLCHAIN_IAR/NANO130.icf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ define symbol __ICFEDIT_region_ROM_end__ = 0x00020000 - 1;
99
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
1010
define symbol __ICFEDIT_region_IRAM_end__ = 0x20004000 - 1;
1111
/*-Sizes-*/
12-
define symbol __ICFEDIT_size_cstack__ = 0x600;
13-
define symbol __ICFEDIT_size_heap__ = 0xE00;
12+
define symbol __ICFEDIT_size_cstack__ = 0x400;
13+
define symbol __ICFEDIT_size_heap__ = 0xC00;
1414
/**** End of ICF editor section. ###ICF###*/
1515

1616

targets/TARGET_NUVOTON/mbed_rtx.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@
4545
#error "no toolchain defined"
4646
#endif
4747

48+
#if defined(TARGET_NANO100)
49+
#ifdef MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE
50+
#undef MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE
51+
#endif
52+
#define MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE 3072
53+
#endif
54+
4855
#endif // TARGET_NUVOTON
4956

5057
#endif // MBED_MBED_RTX_H

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/TOOLCHAIN_GCC_ARM/STM32F070XB.ld

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Linker script to configure memory regions. */
2+
StackSize = 0x400;
23
MEMORY
34
{
45
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128k
@@ -113,6 +114,20 @@ SECTIONS
113114

114115
} > RAM
115116

117+
/* .stack section doesn't contains any symbols. It is only
118+
* used for linker to reserve space for the main stack section
119+
*/
120+
.stack (NOLOAD):
121+
{
122+
__StackLimit = .;
123+
*(.stack*);
124+
. += StackSize - (. - __StackLimit);
125+
} > RAM
126+
__StackTop = ADDR(.stack) + SIZEOF(.stack);
127+
_estack = __StackTop;
128+
__StackLimit = ADDR(.stack);
129+
PROVIDE(__stack = __StackTop);
130+
116131
.bss :
117132
{
118133
. = ALIGN(8);
@@ -129,25 +144,13 @@ SECTIONS
129144
{
130145
__end__ = .;
131146
end = __end__;
132-
*(.heap*)
147+
*(.heap*);
148+
. += (ORIGIN(RAM) + LENGTH(RAM) - .);
133149
__HeapLimit = .;
134150
} > RAM
135151

136-
/* .stack_dummy section doesn't contains any symbols. It is only
137-
* used for linker to calculate size of stack sections, and assign
138-
* values to stack symbols later */
139-
.stack_dummy (COPY):
140-
{
141-
*(.stack*)
142-
} > RAM
143-
144-
/* Set stack top to end of RAM, and stack limit move down by
145-
* size of stack_dummy section */
146-
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
147-
_estack = __StackTop;
148-
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
149-
PROVIDE(__stack = __StackTop);
152+
PROVIDE(__heap_size = SIZEOF(.heap));
153+
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
154+
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
150155

151-
/* Check if data + heap + stack exceeds RAM limit */
152-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
153156
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018, STMicroelectronics
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
#include <errno.h>
29+
#include "stm32f0xx.h"
30+
extern uint32_t __mbed_sbrk_start;
31+
extern uint32_t __mbed_krbs_start;
32+
33+
/* Support heap with two-region model
34+
*
35+
* The default implementation of _sbrk() (in mbed_retarget.cpp) for GCC_ARM requires one-region
36+
* model (heap and stack share one region), which doesn't fit two-region model (heap and stack
37+
* are two distinct regions)
38+
* Hence, override _sbrk() here to support heap with two-region model.
39+
*/
40+
void *_sbrk(int incr)
41+
{
42+
static uint32_t heap_ind = (uint32_t) &__mbed_sbrk_start;
43+
uint32_t heap_ind_old = heap_ind;
44+
uint32_t heap_ind_new = heap_ind_old + incr;
45+
46+
if (heap_ind_new > (uint32_t) &__mbed_krbs_start) {
47+
errno = ENOMEM;
48+
return (void *) -1;
49+
}
50+
51+
heap_ind = heap_ind_new;
52+
53+
return (void *) heap_ind_old;
54+
}

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/TOOLCHAIN_IAR/stm32f070xb.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__ = 0x200000C0;
1010
define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF;
1111
/*-Sizes-*/
1212
define symbol __ICFEDIT_size_cstack__ = 0x400;
13-
define symbol __ICFEDIT_size_heap__ = 0x1000;
13+
define symbol __ICFEDIT_size_heap__ = 0xC00;
1414
/**** End of ICF editor section. ###ICF###*/
1515

1616
define memory mem with size = 4G;

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/TOOLCHAIN_GCC_ARM/STM32F072XB.ld

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Linker script to configure memory regions. */
2+
StackSize = 0x400;
23
MEMORY
34
{
45
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128k
@@ -113,6 +114,20 @@ SECTIONS
113114

114115
} > RAM
115116

117+
/* .stack section doesn't contains any symbols. It is only
118+
* used for linker to reserve space for the main stack section
119+
*/
120+
.stack (NOLOAD):
121+
{
122+
__StackLimit = .;
123+
*(.stack*);
124+
. += StackSize - (. - __StackLimit);
125+
} > RAM
126+
__StackTop = ADDR(.stack) + SIZEOF(.stack);
127+
_estack = __StackTop;
128+
__StackLimit = ADDR(.stack);
129+
PROVIDE(__stack = __StackTop);
130+
116131
.bss :
117132
{
118133
. = ALIGN(8);
@@ -129,25 +144,13 @@ SECTIONS
129144
{
130145
__end__ = .;
131146
end = __end__;
132-
*(.heap*)
147+
*(.heap*);
148+
. += (ORIGIN(RAM) + LENGTH(RAM) - .);
133149
__HeapLimit = .;
134150
} > RAM
135151

136-
/* .stack_dummy section doesn't contains any symbols. It is only
137-
* used for linker to calculate size of stack sections, and assign
138-
* values to stack symbols later */
139-
.stack_dummy (COPY):
140-
{
141-
*(.stack*)
142-
} > RAM
143-
144-
/* Set stack top to end of RAM, and stack limit move down by
145-
* size of stack_dummy section */
146-
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
147-
_estack = __StackTop;
148-
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
149-
PROVIDE(__stack = __StackTop);
152+
PROVIDE(__heap_size = SIZEOF(.heap));
153+
PROVIDE(__mbed_sbrk_start = ADDR(.heap));
154+
PROVIDE(__mbed_krbs_start = ADDR(.heap) + SIZEOF(.heap));
150155

151-
/* Check if data + heap + stack exceeds RAM limit */
152-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
153156
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018, STMicroelectronics
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
#include <errno.h>
29+
#include "stm32f0xx.h"
30+
extern uint32_t __mbed_sbrk_start;
31+
extern uint32_t __mbed_krbs_start;
32+
33+
/* Support heap with two-region model
34+
*
35+
* The default implementation of _sbrk() (in mbed_retarget.cpp) for GCC_ARM requires one-region
36+
* model (heap and stack share one region), which doesn't fit two-region model (heap and stack
37+
* are two distinct regions)
38+
* Hence, override _sbrk() here to support heap with two-region model.
39+
*/
40+
void *_sbrk(int incr)
41+
{
42+
static uint32_t heap_ind = (uint32_t) &__mbed_sbrk_start;
43+
uint32_t heap_ind_old = heap_ind;
44+
uint32_t heap_ind_new = heap_ind_old + incr;
45+
46+
if (heap_ind_new > (uint32_t) &__mbed_krbs_start) {
47+
errno = ENOMEM;
48+
return (void *) -1;
49+
}
50+
51+
heap_ind = heap_ind_new;
52+
53+
return (void *) heap_ind_old;
54+
}

targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/TOOLCHAIN_IAR/stm32f072xb.icf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define symbol __ICFEDIT_region_RAM_start__ = 0x200000C0;
1010
define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF;
1111
/*-Sizes-*/
1212
define symbol __ICFEDIT_size_cstack__ = 0x400;
13-
define symbol __ICFEDIT_size_heap__ = 0x1000;
13+
define symbol __ICFEDIT_size_heap__ = 0xC00;
1414
/**** End of ICF editor section. ###ICF###*/
1515

1616
define memory mem with size = 4G;

targets/TARGET_STM/mbed_rtx.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,23 @@ extern uint32_t __HeapLimit[];
138138
#define ISR_STACK_SIZE ((uint32_t)((uint32_t)__StackTop - (uint32_t)__StackLimit))
139139
#endif
140140

141+
#if (defined(TARGET_STM32F070RB) || defined(TARGET_STM32F072RB))
142+
#if (defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC_VERSION))
143+
extern uint32_t __StackLimit;
144+
extern uint32_t __StackTop;
145+
extern uint32_t __end__;
146+
extern uint32_t __HeapLimit;
147+
#define HEAP_START ((unsigned char*) &__end__)
148+
#define HEAP_SIZE ((uint32_t)((uint32_t) &__HeapLimit - (uint32_t) HEAP_START))
149+
#define ISR_STACK_START ((unsigned char*) &__StackLimit)
150+
#define ISR_STACK_SIZE ((uint32_t)((uint32_t) &__StackTop - (uint32_t) &__StackLimit))
151+
#endif
152+
153+
#ifdef MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE
154+
#undef MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE
155+
#endif
156+
#define MBED_CONF_RTOS_MAIN_THREAD_STACK_SIZE 3072
157+
158+
#endif
159+
141160
#endif // MBED_MBED_RTX_H

targets/TARGET_TOSHIBA/TARGET_TMPM066/device/TOOLCHAIN_IAR/tmpm066fwug.icf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ define symbol __ICFEDIT_region_ROM_end__ = 0x0001FFFF;
99
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
1010
define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF;
1111
/*-Sizes-*/
12-
define symbol __ICFEDIT_size_cstack__ = 0x200;
13-
define symbol __ICFEDIT_size_heap__ = 0x1400;
12+
define symbol __ICFEDIT_size_cstack__ = 0x400;
13+
define symbol __ICFEDIT_size_heap__ = 0xC00;
1414
/**** End of ICF editor section. ###ICF###*/
1515

1616

0 commit comments

Comments
 (0)