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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #elif defined(TARGET_LPC1768)
  28. // For LPC1769:
  29. // SRAM (0x10000000 - 0x10008000) (32kb)
  30. // FLASH (0x00000000 - 0x00080000) (512kb)
  31. //
  32. #define START_SRAM_ADDR 0x10000000
  33. #define END_SRAM_ADDR 0x10008000
  34. #define START_FLASH_ADDR 0x00000000
  35. #define END_FLASH_ADDR 0x00080000
  36. #elif 0
  37. // For STM32F103CBT6
  38. // SRAM (0x20000000 - 0x20005000) (20kb)
  39. // FLASH (0x00000000 - 0x00020000) (128kb)
  40. //
  41. #define START_SRAM_ADDR 0x20000000
  42. #define END_SRAM_ADDR 0x20005000
  43. #define START_FLASH_ADDR 0x00000000
  44. #define END_FLASH_ADDR 0x00020000
  45. #elif defined(__STM32F1__) || defined(STM32F1xx) || defined(STM32F0xx)
  46. // For STM32F103ZET6/STM32F103VET6/STM32F0xx
  47. // SRAM (0x20000000 - 0x20010000) (64kb)
  48. // FLASH (0x00000000 - 0x00080000) (512kb)
  49. //
  50. #define START_SRAM_ADDR 0x20000000
  51. #define END_SRAM_ADDR 0x20010000
  52. #define START_FLASH_ADDR 0x00000000
  53. #define END_FLASH_ADDR 0x00080000
  54. #elif defined(STM32F4) || defined(STM32F4xx)
  55. // For STM32F407VET
  56. // SRAM (0x20000000 - 0x20030000) (192kb)
  57. // FLASH (0x08000000 - 0x08080000) (512kb)
  58. //
  59. #define START_SRAM_ADDR 0x20000000
  60. #define END_SRAM_ADDR 0x20030000
  61. #define START_FLASH_ADDR 0x08000000
  62. #define END_FLASH_ADDR 0x08080000
  63. #elif MB(THE_BORG)
  64. // For STM32F765 in BORG
  65. // SRAM (0x20000000 - 0x20080000) (512kb)
  66. // FLASH (0x08000000 - 0x08100000) (1024kb)
  67. //
  68. #define START_SRAM_ADDR 0x20000000
  69. #define END_SRAM_ADDR 0x20080000
  70. #define START_FLASH_ADDR 0x08000000
  71. #define END_FLASH_ADDR 0x08100000
  72. #elif MB(REMRAM_V1, NUCLEO_F767ZI)
  73. // For STM32F765VI in RemRam v1
  74. // SRAM (0x20000000 - 0x20080000) (512kb)
  75. // FLASH (0x08000000 - 0x08200000) (2048kb)
  76. //
  77. #define START_SRAM_ADDR 0x20000000
  78. #define END_SRAM_ADDR 0x20080000
  79. #define START_FLASH_ADDR 0x08000000
  80. #define END_FLASH_ADDR 0x08200000
  81. #elif defined(__MK20DX256__)
  82. // For MK20DX256 in TEENSY 3.1 or TEENSY 3.2
  83. // SRAM (0x1FFF8000 - 0x20008000) (64kb)
  84. // FLASH (0x00000000 - 0x00040000) (256kb)
  85. //
  86. #define START_SRAM_ADDR 0x1FFF8000
  87. #define END_SRAM_ADDR 0x20008000
  88. #define START_FLASH_ADDR 0x00000000
  89. #define END_FLASH_ADDR 0x00040000
  90. #elif defined(__MK64FX512__)
  91. // For MK64FX512 in TEENSY 3.5
  92. // SRAM (0x1FFF0000 - 0x20020000) (192kb)
  93. // FLASH (0x00000000 - 0x00080000) (512kb)
  94. //
  95. #define START_SRAM_ADDR 0x1FFF0000
  96. #define END_SRAM_ADDR 0x20020000
  97. #define START_FLASH_ADDR 0x00000000
  98. #define END_FLASH_ADDR 0x00080000
  99. #elif defined(__MK66FX1M0__)
  100. // For MK66FX1M0 in TEENSY 3.6
  101. // SRAM (0x1FFF0000 - 0x20030000) (256kb)
  102. // FLASH (0x00000000 - 0x00140000) (1.25Mb)
  103. //
  104. #define START_SRAM_ADDR 0x1FFF0000
  105. #define END_SRAM_ADDR 0x20030000
  106. #define START_FLASH_ADDR 0x00000000
  107. #define END_FLASH_ADDR 0x00140000
  108. #elif defined(__IMXRT1062__)
  109. // For IMXRT1062 in TEENSY 4.0/4/1
  110. // ITCM (rwx): ORIGIN = 0x00000000, LENGTH = 512K
  111. // DTCM (rwx): ORIGIN = 0x20000000, LENGTH = 512K
  112. // RAM (rwx): ORIGIN = 0x20200000, LENGTH = 512K
  113. // FLASH (rwx): ORIGIN = 0x60000000, LENGTH = 1984K
  114. //
  115. #define START_SRAM_ADDR 0x00000000
  116. #define END_SRAM_ADDR 0x20280000
  117. #define START_FLASH_ADDR 0x60000000
  118. #define END_FLASH_ADDR 0x601F0000
  119. #elif defined(__SAMD51P20A__)
  120. // For SAMD51x20, valid address ranges are
  121. // SRAM (0x20000000 - 0x20040000) (256kb)
  122. // FLASH (0x00000000 - 0x00100000) (1024kb)
  123. //
  124. #define START_SRAM_ADDR 0x20000000
  125. #define END_SRAM_ADDR 0x20040000
  126. #define START_FLASH_ADDR 0x00000000
  127. #define END_FLASH_ADDR 0x00100000
  128. #endif
  129. static bool validate_addr(uint32_t addr) {
  130. // Address must be in SRAM range
  131. if (addr >= START_SRAM_ADDR && addr < END_SRAM_ADDR)
  132. return true;
  133. // Or in FLASH range
  134. if (addr >= START_FLASH_ADDR && addr < END_FLASH_ADDR)
  135. return true;
  136. return false;
  137. }
  138. bool UnwReadW(const uint32_t a, uint32_t *v) {
  139. if (!validate_addr(a))
  140. return false;
  141. *v = *(uint32_t *)a;
  142. return true;
  143. }
  144. bool UnwReadH(const uint32_t a, uint16_t *v) {
  145. if (!validate_addr(a))
  146. return false;
  147. *v = *(uint16_t *)a;
  148. return true;
  149. }
  150. bool UnwReadB(const uint32_t a, uint8_t *v) {
  151. if (!validate_addr(a))
  152. return false;
  153. *v = *(uint8_t *)a;
  154. return true;
  155. }
  156. #endif // __arm__ || __thumb__