Skip to content

Commit

Permalink
[platform] Move heap into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Mar 25, 2020
2 parents 8c13eeb + 83e5374 commit b8648be
Show file tree
Hide file tree
Showing 63 changed files with 967 additions and 680 deletions.
30 changes: 15 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Check environment
command: |
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Examples STM32F0 Series
command: |
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Examples STM32F4 Series
command: |
Expand All @@ -133,7 +133,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Examples AVR Series
command: |
Expand All @@ -147,7 +147,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all AVRs
command: |
Expand All @@ -164,7 +164,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32F0
command: |
Expand All @@ -181,7 +181,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32F1
command: |
Expand All @@ -198,7 +198,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32F2
command: |
Expand All @@ -215,7 +215,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32F3
command: |
Expand All @@ -232,7 +232,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32F4
command: |
Expand All @@ -249,7 +249,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32F7
command: |
Expand All @@ -266,7 +266,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32L1
command: |
Expand All @@ -283,7 +283,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32L4
command: |
Expand All @@ -300,7 +300,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32G0
command: |
Expand All @@ -317,7 +317,7 @@ jobs:
- run:
name: Checkout code and update modm tools
command: |
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade modm & wait
(git submodule sync && git submodule update --init --jobs 8) & pip3 install --upgrade --upgrade-strategy=eager modm & wait
- run:
name: Compile HAL for all STM32G4
command: |
Expand Down
1 change: 1 addition & 0 deletions examples/avr/xpcc/receiver/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<module>modm:platform:clock</module>
<module>modm:platform:core</module>
<module>modm:platform:gpio</module>
<module>modm:platform:heap</module>
<module>modm:platform:spi.bitbang</module>
<module>modm:platform:uart:0</module>
<module>modm:build:scons</module>
Expand Down
1 change: 1 addition & 0 deletions examples/avr/xpcc/sender/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<module>modm:platform:clock</module>
<module>modm:platform:core</module>
<module>modm:platform:gpio</module>
<module>modm:platform:heap</module>
<module>modm:platform:spi.bitbang</module>
<module>modm:platform:uart:0</module>
<module>modm:build:scons</module>
Expand Down
1 change: 1 addition & 0 deletions examples/generic/ros/can_bridge/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<module>modm:communication:ros</module>
<module>modm:platform:can</module>
<module>modm:platform:uart:2</module>
<module>modm:platform:heap</module>
<module>modm:ros</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/generic/ros/environment/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<module>modm:processing:protothread</module>
<module>modm:platform:i2c:1</module>
<module>modm:build:scons</module>
<module>modm:platform:heap</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/generic/ros/sub_pub/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<module>modm:driver</module>
<module>modm:platform:i2c:1</module>
<module>modm:processing:timer</module>
<module>modm:platform:heap</module>
<module>modm:ros</module>
<module>modm:build:scons</module>
</modules>
Expand Down
1 change: 1 addition & 0 deletions examples/nucleo_f103rb/hard_fault/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:platform:fault</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_f103rb/rtos/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_f303k8/rtos/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_f411re/rtos/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
64 changes: 64 additions & 0 deletions examples/nucleo_g071rb/custom_allocator/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>

using namespace Board;

// Allocate giant array inside a NOLOAD heap section
// Play around with the array size and see effect it has on HeapTable!
modm_section(".heap1")
uint8_t heap_begin[30*1024]; // 31kB overflows the linkerscript
const uint8_t *const heap_end{heap_begin + sizeof(heap_begin)};
const uint8_t *heap_top{heap_begin};

extern "C" void __modm_initialize_memory()
{
// Initialize your specific allocator algorithm here
memset(heap_begin, 0xaa, sizeof(heap_begin));
}
extern "C" void* _sbrk_r(struct _reent *, ptrdiff_t size)
{
const uint8_t *const heap = heap_top;
heap_top += size;
if (heap_top >= heap_end) {
MODM_LOG_ERROR << "Heap overflowed!" << modm::endl;
while(1) ;
}
return (void*) heap;
}

// ----------------------------------------------------------------------------
int main()
{
Board::initialize();
LedD13::setOutput();

for (const auto [traits, start, end, size] : modm::platform::HeapTable())
{
MODM_LOG_INFO.printf("Memory section %#x @[0x%p,0x%p](%u)\n",
traits.value, start, end, size);
}

void* ptr;
size_t counter{0};
while (true)
{
LedD13::toggle();
modm::delayMilliseconds(200);

// leak memory until heap is exhausted
ptr = malloc(1024);
if (ptr) counter++;
MODM_LOG_INFO << "Allocated " << counter << "kb of heap!" << modm::endl;
}

return 0;
}
11 changes: 11 additions & 0 deletions examples/nucleo_g071rb/custom_allocator/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<library>
<extends>modm:nucleo-g071rb</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_g071rb/custom_allocator</option>
</options>
<modules>
<module>modm:platform:gpio</module>
<module>modm:architecture:memory</module>
<module>modm:build:scons</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/nucleo_g071rb/rtos/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/stm32f072_discovery/unaligned_access/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<module>modm:architecture:unaligned</module>
<module>modm:container</module>
<module>modm:platform:gpio</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
9 changes: 9 additions & 0 deletions examples/stm32f469_discovery/tlsf-allocator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ int main()
MODM_LOG_INFO << modm::endl;
}

size_t total_size{0};
for (const auto [traits, start, end, size] : modm::platform::HeapTable())
{
MODM_LOG_INFO.printf("Memory section %#x @[0x%p,0x%p](%u)\n",
traits.value, start, end, size);
total_size += size;
}
MODM_LOG_INFO << "Total heap size (kB): " << (total_size >> 10) << modm::endl;

while (true)
{
Board::Leds::toggle();
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f4_discovery/open407v-d/gui/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<module>modm:platform:fsmc</module>
<module>modm:platform:spi:2</module>
<module>modm:platform:uart:2</module>
<module>modm:platform:heap</module>
<module>modm:ui:display</module>
<module>modm:ui:gui</module>
<module>modm:utils</module>
Expand Down
1 change: 1 addition & 0 deletions examples/stm32f746g_discovery/rtos/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</options>
<modules>
<module>modm:processing:rtos</module>
<module>modm:platform:heap</module>
<module>modm:build:scons</module>
</modules>
</library>
1 change: 1 addition & 0 deletions examples/zmq/1_stm32/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<module>modm:communication:xpcc:generator</module>
<module>modm:platform:can:1</module>
<module>modm:platform:gpio</module>
<module>modm:platform:heap</module>
<module>modm:platform:timer:1</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
Expand Down
11 changes: 5 additions & 6 deletions ext/gcc/module_c++.lb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def prepare(module, options):
name="safe_statics", default=True,
description=descr_safe_statics))

module.depends(":architecture:assert", ":architecture:memory", ":stdc")
module.depends(":architecture:assert", ":stdc")
return True


Expand All @@ -77,19 +77,18 @@ def build(env):
env.substitutions = {
"core": core,
"with_exceptions": with_exceptions,
"with_threadsafe_statics": with_threadsafe_statics
"with_threadsafe_statics": with_threadsafe_statics,
"with_memory_traits": env.has_module(":architecture:memory"),
"is_avr": is_avr,
}
env.outbasepath = "modm/ext/gcc"
env.template("cxxabi.cpp.in")
env.template("new_delete.cpp.in")

if is_avr:
env.collect(":build:path.include", "modm/ext/gcc/libstdc++/include")
env.copy("libstdc++", ignore=env.ignore_files("*.lb", "*.md", "*.in", "examples"))
env.template("assert.cpp.in", "assert.cpp")
env.copy("newdelete_avr.cpp", "newdelete.cpp")

elif is_cortex_m:
env.copy("newdelete_cortex.cpp", "newdelete.cpp")

env.collect(":build:cxxflags", "-fuse-cxa-atexit")
# Threadsafe statics
Expand Down
Loading

0 comments on commit b8648be

Please sign in to comment.