DIY Logging Volt/Ampmeter
sysmem.c File Reference

STM32CubeIDE System Memory calls file. More...

#include <errno.h>
#include <stdint.h>

Go to the source code of this file.

Functions

void * _sbrk (ptrdiff_t incr)
 _sbrk() allocates memory to the newlib heap and is used by malloc and others from the C library More...
 

Variables

static uint8_t * __sbrk_heap_end = NULL
 

Detailed Description

STM32CubeIDE System Memory calls file.

Author
Generated by STM32CubeIDE
       For more information about which C functions
       need which of these lowlevel functions
       please consult the newlib libc manual
Attention

© Copyright (c) 2020 STMicroelectronics. All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Definition in file sysmem.c.

Function Documentation

◆ _sbrk()

void* _sbrk ( ptrdiff_t  incr)

_sbrk() allocates memory to the newlib heap and is used by malloc and others from the C library

* ############################################################################
* #  .data  #  .bss  #       newlib heap       #          MSP stack          #
* #         #        #                         # Reserved by _Min_Stack_Size #
* ############################################################################
* ^-- RAM start      ^-- _end                             _estack, RAM end --^
* 

This implementation starts allocating at the '_end' linker symbol The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack The implementation considers '_estack' linker symbol to be RAM end NOTE: If the MSP stack, at any point during execution, grows larger than the reserved size, please increase the '_Min_Stack_Size'.

Parameters
incrMemory size
Returns
Pointer to allocated memory

Definition at line 54 of file sysmem.c.

55 {
56  extern uint8_t _end; /* Symbol defined in the linker script */
57  extern uint8_t _estack; /* Symbol defined in the linker script */
58  extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
59  const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
60  const uint8_t *max_heap = (uint8_t *)stack_limit;
61  uint8_t *prev_heap_end;
62 
63  /* Initialize heap end at first call */
64  if (NULL == __sbrk_heap_end)
65  {
66  __sbrk_heap_end = &_end;
67  }
68 
69  /* Protect heap from growing into the reserved MSP stack */
70  if (__sbrk_heap_end + incr > max_heap)
71  {
72  errno = ENOMEM;
73  return (void *)-1;
74  }
75 
76  prev_heap_end = __sbrk_heap_end;
77  __sbrk_heap_end += incr;
78 
79  return (void *)prev_heap_end;
80 }

Variable Documentation

◆ __sbrk_heap_end

uint8_t* __sbrk_heap_end = NULL
static

Pointer to the current high watermark of the heap usage

Definition at line 31 of file sysmem.c.

__sbrk_heap_end
static uint8_t * __sbrk_heap_end
Definition: sysmem.c:31
errno
int errno
NULL
#define NULL
Definition: SEGGER_RTT.c:177