sysmem.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. ******************************************************************************
  3. * @file sysmem.c
  4. * @author Auto-generated by STM32CubeIDE
  5. * @brief STM32CubeIDE Minimal System Memory calls file
  6. *
  7. * For more information about which c-functions
  8. * need which of these lowlevel functions
  9. * please consult the Newlib libc-manual
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  14. * All rights reserved.</center></h2>
  15. *
  16. * This software component is licensed by ST under BSD 3-Clause license,
  17. * the "License"; You may not use this file except in compliance with the
  18. * License. You may obtain a copy of the License at:
  19. * opensource.org/licenses/BSD-3-Clause
  20. *
  21. ******************************************************************************
  22. */
  23. /* Includes */
  24. #include <errno.h>
  25. #include <stdio.h>
  26. /* Variables */
  27. extern int errno;
  28. register char * stack_ptr asm("sp");
  29. /* Functions */
  30. /**
  31. _sbrk
  32. Increase program data space. Malloc and related functions depend on this
  33. **/
  34. caddr_t _sbrk(int incr)
  35. {
  36. extern char end asm("end");
  37. static char *heap_end;
  38. char *prev_heap_end;
  39. if (heap_end == 0)
  40. heap_end = &end;
  41. prev_heap_end = heap_end;
  42. if (heap_end + incr > stack_ptr)
  43. {
  44. errno = ENOMEM;
  45. return (caddr_t) -1;
  46. }
  47. heap_end += incr;
  48. return (caddr_t) prev_heap_end;
  49. }