My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unwmemaccess.cpp 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /***************************************************************************
  2. * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk
  3. * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle
  4. *
  5. * This program is PUBLIC DOMAIN.
  6. * This means that there is no copyright and anyone is able to take a copy
  7. * for free and use it as they wish, with or without modifications, and in
  8. * any context, commercially or otherwise. The only limitation is that I
  9. * don't guarantee that the software is fit for any purpose or accept any
  10. * liability for it's use or misuse - this software is without warranty.
  11. ***************************************************************************
  12. * File Description: Utility functions to access memory
  13. **************************************************************************/
  14. #if defined(__arm__) || defined(__thumb__)
  15. #include "unwmemaccess.h"
  16. #include "../../../inc/MarlinConfig.h"
  17. /* Validate address */
  18. #ifdef ARDUINO_ARCH_SAM
  19. // For DUE, valid address ranges are
  20. // SRAM (0x20070000 - 0x20088000) (96kb)
  21. // FLASH (0x00080000 - 0x00100000) (512kb)
  22. //
  23. #define START_SRAM_ADDR 0x20070000
  24. #define END_SRAM_ADDR 0x20088000
  25. #define START_FLASH_ADDR 0x00080000
  26. #define END_FLASH_ADDR 0x00100000
  27. #endif
  28. #ifdef TARGET_LPC1768
  29. // For LPC1769:
  30. // SRAM (0x10000000 - 0x10008000) (32kb)
  31. // FLASH (0x00000000 - 0x00080000) (512kb)
  32. //
  33. #define START_SRAM_ADDR 0x10000000
  34. #define END_SRAM_ADDR 0x10008000
  35. #define START_FLASH_ADDR 0x00000000
  36. #define END_FLASH_ADDR 0x00080000
  37. #endif
  38. #if 0
  39. // For STM32F103CBT6
  40. // SRAM (0x20000000 - 0x20005000) (20kb)
  41. // FLASH (0x00000000 - 0x00020000) (128kb)
  42. //
  43. #define START_SRAM_ADDR 0x20000000
  44. #define END_SRAM_ADDR 0x20005000
  45. #define START_FLASH_ADDR 0x00000000
  46. #define END_FLASH_ADDR 0x00020000
  47. #endif
  48. #if defined(__STM32F1__) || defined(STM32F1xx) || defined(STM32F0xx)
  49. // For STM32F103ZET6/STM32F103VET6/STM32F0xx
  50. // SRAM (0x20000000 - 0x20010000) (64kb)
  51. // FLASH (0x00000000 - 0x00080000) (512kb)
  52. //
  53. #define START_SRAM_ADDR 0x20000000
  54. #define END_SRAM_ADDR 0x20010000
  55. #define START_FLASH_ADDR 0x00000000
  56. #define END_FLASH_ADDR 0x00080000
  57. #endif
  58. #if defined(STM32F4) || defined(STM32F4xx)
  59. // For STM32F407VET
  60. // SRAM (0x20000000 - 0x20030000) (192kb)
  61. // FLASH (0x08000000 - 0x08080000) (512kb)
  62. //
  63. #define START_SRAM_ADDR 0x20000000
  64. #define END_SRAM_ADDR 0x20030000
  65. #define START_FLASH_ADDR 0x08000000
  66. #define END_FLASH_ADDR 0x08080000
  67. #endif
  68. #if MB(THE_BORG)
  69. // For STM32F765 in BORG
  70. // SRAM (0x20000000 - 0x20080000) (512kb)
  71. // FLASH (0x08000000 - 0x08100000) (1024kb)
  72. //
  73. #define START_SRAM_ADDR 0x20000000
  74. #define END_SRAM_ADDR 0x20080000
  75. #define START_FLASH_ADDR 0x08000000
  76. #define END_FLASH_ADDR 0x08100000
  77. #endif
  78. #if MB(REMRAM_V1)
  79. // For STM32F765VI in RemRam v1
  80. // SRAM (0x20000000 - 0x20080000) (512kb)
  81. // FLASH (0x08000000 - 0x08200000) (2048kb)
  82. //
  83. #define START_SRAM_ADDR 0x20000000
  84. #define END_SRAM_ADDR 0x20080000
  85. #define START_FLASH_ADDR 0x08000000
  86. #define END_FLASH_ADDR 0x08200000
  87. #endif
  88. #ifdef __MK20DX256__
  89. // For MK20DX256 in TEENSY 3.1 or TEENSY 3.2
  90. // SRAM (0x1FFF8000 - 0x20008000) (64kb)
  91. // FLASH (0x00000000 - 0x00040000) (256kb)
  92. //
  93. #define START_SRAM_ADDR 0x1FFF8000
  94. #define END_SRAM_ADDR 0x20008000
  95. #define START_FLASH_ADDR 0x00000000
  96. #define END_FLASH_ADDR 0x00040000
  97. #endif
  98. #ifdef __MK64FX512__
  99. // For MK64FX512 in TEENSY 3.5
  100. // SRAM (0x1FFF0000 - 0x20020000) (192kb)
  101. // FLASH (0x00000000 - 0x00080000) (512kb)
  102. //
  103. #define START_SRAM_ADDR 0x1FFF0000
  104. #define END_SRAM_ADDR 0x20020000
  105. #define START_FLASH_ADDR 0x00000000
  106. #define END_FLASH_ADDR 0x00080000
  107. #endif
  108. #ifdef __MK66FX1M0__
  109. // For MK66FX1M0 in TEENSY 3.6
  110. // SRAM (0x1FFF0000 - 0x20030000) (256kb)
  111. // FLASH (0x00000000 - 0x00140000) (1.25Mb)
  112. //
  113. #define START_SRAM_ADDR 0x1FFF0000
  114. #define END_SRAM_ADDR 0x20030000
  115. #define START_FLASH_ADDR 0x00000000
  116. #define END_FLASH_ADDR 0x00140000
  117. #endif
  118. #ifdef __SAMD51P20A__
  119. // For SAMD51x20, valid address ranges are
  120. // SRAM (0x20000000 - 0x20040000) (256kb)
  121. // FLASH (0x00000000 - 0x00100000) (1024kb)
  122. //
  123. #define START_SRAM_ADDR 0x20000000
  124. #define END_SRAM_ADDR 0x20040000
  125. #define START_FLASH_ADDR 0x00000000
  126. #define END_FLASH_ADDR 0x00100000
  127. #endif
  128. static bool validate_addr(uint32_t addr) {
  129. // Address must be in SRAM range
  130. if (addr >= START_SRAM_ADDR && addr < END_SRAM_ADDR)
  131. return true;
  132. // Or in FLASH range
  133. if (addr >= START_FLASH_ADDR && addr < END_FLASH_ADDR)
  134. return true;
  135. return false;
  136. }
  137. bool UnwReadW(const uint32_t a, uint32_t *v) {
  138. if (!validate_addr(a))
  139. return false;
  140. *v = *(uint32_t *)a;
  141. return true;
  142. }
  143. bool UnwReadH(const uint32_t a, uint16_t *v) {
  144. if (!validate_addr(a))
  145. return false;
  146. *v = *(uint16_t *)a;
  147. return true;
  148. }
  149. bool UnwReadB(const uint32_t a, uint8_t *v) {
  150. if (!validate_addr(a))
  151. return false;
  152. *v = *(uint8_t *)a;
  153. return true;
  154. }
  155. #endif