STLparam.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. ******************************************************************************
  3. * @file STLparam.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date May-2012
  7. * @brief This file contains the parameters to be customized for
  8. * the final application.
  9. ******************************************************************************
  10. * @copyright
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. /* Define to prevent recursive inclusion -------------------------------------*/
  27. #ifndef __SELFTEST_PARAM_H
  28. #define __SELFTEST_PARAM_H
  29. /* Includes ------------------------------------------------------------------*/
  30. #include "gd32f30x.h"
  31. /* Exported types ------------------------------------------------------------*/
  32. /* Exported constants --------------------------------------------------------*/
  33. /* Exported types ------------------------------------------------------------*/
  34. typedef enum {
  35. TEST_RUNNING,
  36. CLASS_B_DATA_FAIL,
  37. CTRL_FLW_ERROR,
  38. TEST_FAILURE,
  39. TEST_OK
  40. } ClassBTestStatus;
  41. /* This is for having self-diagnostic messages reported on a PC via UART */
  42. //#define STL_VERBOSE_POR /* During Power-on phase only */
  43. //#define STL_VERBOSE /* During main program execution */
  44. /* comment out next lines to remove any eval board control */
  45. //#define STL_EVAL_MODE //ly
  46. /* uncomment next line to use March-X test instead of March-C */
  47. #define USE_MARCHX_RAM_TEST
  48. #define USE_MARCH_X
  49. /* uncomment next lines to configure proper watchdog control at run mode */
  50. #define USE_INDEPENDENT_WDOG
  51. /* #define USE_WINDOW_AT_INDEPENDENT_WDOG */
  52. //#define USE_WINDOW_WDOG //ly
  53. /* uncomment next lines to generate reset at fail safe routine */
  54. #define GENERATE_RESET_AT_FAIL_SAFE
  55. /* These are the direct and inverted data (pattern) used during the RAM
  56. test, performed using March C- Algorithm */
  57. #define BCKGRND ((uint32_t)0x00000000uL)
  58. #define INV_BCKGRND ((uint32_t)0xFFFFFFFFuL)
  59. /* Initial value of the CRC */
  60. #define CRC_INIT ((uint32_t)0x00000000uL)
  61. /* Define the time bases for clock frequency measure: RUN and START time bases
  62. must be equal or multiple. RUN time base must take into account SysTick
  63. prescaler and PLL setting (if enabled) */
  64. #define SYSTICK_2_ms_HSI ((uint32_t)16000uL) /* HSI = 8MHz */
  65. #define SYSTICK_2_ms_HSE ((uint32_t)16000uL) /* HSE = 8MHz */
  66. #define SYSTICK_1_ms_PLL ((uint32_t)72000) /* PLL = 72MHz, SysTick clock not prescaled */
  67. #define SYSTICK_TB_START ((uint32_t)SYSTICK_1_ms_PLL)
  68. #define SYSTICK_TB_RUN ((uint32_t)SYSTICK_1_ms_PLL)
  69. /* This is to provide a time base longer than the SysTick for the main */
  70. /* For instance this is needed to refresh the LSI watchdog and window watchdog */
  71. #define SYSTICK_20ms_TB ((uint32_t)10uL) /* 10*2ms */
  72. /* Timeout required to avoid being stuck in while loops during clock circuitry
  73. initialization, in case of problem. Watchdog is also active, but these timeouts
  74. allow to react more quickly */
  75. #define LSI_START_TIMEOUT ((uint32_t)1000uL) /* ~3.5ms (IAR, speed optimized) */
  76. /* ~35ms to be adapted depending on crystal/resonator */
  77. #define HSE_START_TIMEOUT ((uint32_t)10000uL)
  78. /* For clock switch:~3.5ms (IAR, speed optimized) valid for 8MHz and 64MHz
  79. (~3.5/8=450µs)*/
  80. #define CLOCK_SWITCH_TIMEOUT ((uint32_t)1000uL)
  81. /* PLL lock Timeout set to ~10ms (IAR, speed optimized) */
  82. #define PLL_LOCK_TIMEOUT ((uint32_t)3000uL)
  83. /* Value of the Internal oscillator in Hz*/
  84. #define HSI_Freq ((uint32_t)8000000uL)
  85. /* HSE frequency above this limit considered as harmonics*/
  86. #define HSE_LimitHigh ((uint32_t)(HSE_VALUE*5u)/4u) /* (HSEValue + 25%) */
  87. /* HSE frequency below this limit considered as sub-harmonics*/
  88. #define HSE_LimitLow ((uint32_t)(HSE_VALUE*3u)/4u) /* (HSEValue - 25%) */
  89. /* define the maximum U32 */
  90. #define U32_MAX ((uint32_t)4294967295uL)
  91. #define REF_CRC16 ((uint16_t )(0x08007FF0))//ly add
  92. /* -------------------------------------------------------------------------- */
  93. /* ------------------ CONTROL FLOW TAGS and CHECKPOINTS --------------------- */
  94. /* -------------------------------------------------------------------------- */
  95. /* RAM_TEST_CALLEE is only needed for CtrlFlowCntInv when exiting routine */
  96. /* This is because the RAM test routines destroys the control flow counters */
  97. #define RAM_TEST_CALLEE ((uint32_t)0xFFFFFFFFuL)
  98. #define CPU_TEST_CALLER ((uint32_t)2)
  99. #define CPU_TEST_CALLEE ((uint32_t)3) /* Do not modify: hard coded in assembly file */
  100. #define WDG_TEST_CALLER ((uint32_t)5)
  101. #define CRC32_INIT_CALLEE ((uint32_t)7)
  102. #define CRC32_TEST_CALLER ((uint32_t)11)
  103. #define CRC32_TEST_CALLEE ((uint32_t)13)
  104. #define CRC_TEST_CALLER ((uint32_t)17)
  105. #define CRC16_TEST_CALLEE ((uint32_t)19)
  106. #define CLOCK_TEST_CALLER ((uint32_t)23)
  107. #define CLOCK_TEST_CALLEE ((uint32_t)29)
  108. #define LSI_INIT_CALLEE ((uint32_t)31)
  109. #define HSE_INIT_CALLEE ((uint32_t)37)
  110. #define RTC_INIT_CALLEE ((uint32_t)41)
  111. #define SYSTICK_INIT_CALLEE ((uint32_t)43)
  112. #define CLOCK_SWITCH_CALLEE ((uint32_t)47)
  113. #define STACK_OVERFLOW_TEST ((uint32_t)53)
  114. #define STACK_OVERFLOW_CALLEE ((uint32_t)59)
  115. #define CLOCKPERIOD_TEST_CALLEE ((uint32_t)61)
  116. #define CRC16_RUN_TEST_CALLEE ((uint32_t)67)
  117. #define CRC32_RUN_TEST_CALLEE ((uint32_t)71)
  118. #define FLASH_TEST_CALLER ((uint32_t)73)
  119. #define ADC_TEST_CALLER ((uint32_t)77)
  120. #ifdef __IAR_SYSTEMS_ICC__ /* IAR Compiler */
  121. #define CHECKPOINT1 ((uint32_t)CPU_TEST_CALLER + \
  122. /* CPU_TEST_CALLEE */0 + \
  123. /* WDG_TEST_CALLER */0 + \
  124. CRC32_INIT_CALLEE + \
  125. CRC32_TEST_CALLER + \
  126. CRC_TEST_CALLER)
  127. #endif /* __IAR_SYSTEMS_ICC__ */
  128. #ifdef __CC_ARM /* KEIL Compiler */
  129. #define CHECKPOINT1 ((uint32_t)CPU_TEST_CALLER + \
  130. CPU_TEST_CALLEE + \
  131. WDG_TEST_CALLER + \
  132. CRC32_TEST_CALLER + \
  133. CRC32_INIT_CALLEE + \
  134. CRC_TEST_CALLER + \
  135. CRC16_TEST_CALLEE)
  136. #endif /* __CC_ARM */
  137. #define CHECKPOINT2 ((uint32_t)CLOCK_TEST_CALLER + \
  138. CLOCK_TEST_CALLEE + \
  139. LSI_INIT_CALLEE + \
  140. /*HSE_INIT_CALLEE*/0 + \
  141. RTC_INIT_CALLEE + \
  142. SYSTICK_INIT_CALLEE + \
  143. /*CLOCK_SWITCH_CALLEE*/0 + \
  144. STACK_OVERFLOW_TEST)
  145. /* This is for run-time tests with 16-bit CRC */
  146. #define DELTA_MAIN ((uint32_t)CPU_TEST_CALLER + \
  147. /*CPU_TEST_CALLEE*/0 + \
  148. STACK_OVERFLOW_TEST + \
  149. STACK_OVERFLOW_CALLEE + \
  150. CLOCK_TEST_CALLER + \
  151. CLOCK_TEST_CALLEE + \
  152. /*CLOCKPERIOD_TEST_CALLEE*/0 + \
  153. FLASH_TEST_CALLER + \
  154. CRC32_RUN_TEST_CALLEE + \
  155. CRC32_TEST_CALLEE + \
  156. ADC_TEST_CALLER)
  157. #define LAST_DELTA_MAIN ((uint32_t) DELTA_MAIN - CRC32_TEST_CALLEE + CRC32_INIT_CALLEE)
  158. #define FULL_FLASH_CHECKED ((uint32_t)DELTA_MAIN * STEPS_NUMBER + LAST_DELTA_MAIN)
  159. #define MEASPERIOD_ISR_CALLER ((uint32_t)2)
  160. #define MEASPERIOD_ISR_CALLEE ((uint32_t)3)
  161. #define CLOCKPERIOD_ISR_CALLEE ((uint32_t)5)
  162. #define RAM_MARCHC_ISR_CALLER ((uint32_t)7)
  163. #define RAM_MARCHC_ISR_CALLEE ((uint32_t)11)
  164. #define RAM_MARCHX_ISR_CALLER ((uint32_t)13)
  165. #define RAM_MARCHX_ISR_CALLEE ((uint32_t)17)
  166. #ifndef USE_MARCH_X
  167. /* This is for March C tests */
  168. #define DELTA_ISR ((uint32_t) /*MEASPERIOD_ISR_CALLER*/0 + \
  169. RAM_MARCHC_ISR_CALLER + \
  170. RAM_MARCHC_ISR_CALLEE)
  171. #else
  172. /* This is for March X tests */
  173. #define DELTA_ISR ((uint32_t) /*MEASPERIOD_ISR_CALLER*/0+\
  174. /*MEASPERIOD_ISR_CALLER*/0+\
  175. /*CPU_TEST_CALLER +*/0+\
  176. /*CPU_TEST_CALLEE*/0 + \
  177. RAM_MARCHX_ISR_CALLER + \
  178. RAM_MARCHX_ISR_CALLEE)
  179. #endif /* USE_MARCH_X */
  180. #define CLASS_B_ROWS (((uint32_t)RAM_END - (uint32_t)RAM_START+1) / 4u)
  181. /* +1 below is for buffer self-test*/
  182. #define RAM_TEST_COMPLETED ((uint32_t)(DELTA_ISR * (CLASS_B_ROWS-1)))//(CLASS_B_ROWS + 1u)))//(16*1024-8)/4
  183. /* Exported macro ------------------------------------------------------------*/
  184. /* Exported functions ------------------------------------------------------- */
  185. #ifdef __IAR_SYSTEMS_ICC__ /* IAR Compiler */
  186. /* This is the IAR compiler entry point, usually executed right after reset */
  187. extern void __iar_program_start( void );
  188. extern void Reset_Handler( void );
  189. extern uint16_t __checksum;
  190. /* The 4 variables here above are set by IAR linker */
  191. extern uint32_t __ICFEDIT_region_ROM_start__;
  192. extern uint32_t __ICFEDIT_region_CLASSB_ROM_start__;
  193. extern uint32_t __ICFEDIT_region_ROM_end__;
  194. extern uint32_t __ICFEDIT_region_RAM_start__;
  195. extern uint32_t __ICFEDIT_region_RAM_end__;
  196. extern uint32_t __ICFEDIT_region_CLASSB_start__;
  197. extern uint32_t __ICFEDIT_region_CLASSB_end__;
  198. extern uint32_t __ICFEDIT_region_PNT_start__;
  199. extern uint32_t __ICFEDIT_region_BUF_start__;
  200. /* Constants necessary for Flash CRC calculation (last block - 64 bytes - separated for CRC) */
  201. #define ROM_START ((uint8_t *)(&__ICFEDIT_region_ROM_start__))
  202. #define ROM_END ((uint8_t *)0x0803DFEF) //((uint32_t *)(&__ICFEDIT_region_ROM_end__))
  203. #define ROM_SIZE (0x0803DFEF - 0x08003000 + 1u)
  204. #define STEPS_NUMBER ((uint32_t)ROM_SIZE / 16u)//64u)
  205. #define ROM_SIZEinWORDS (uint32_t) (ROM_SIZE / 4u)
  206. #define FLASH_BLOCK (uint32_t)((ROM_SIZE) / STEPS_NUMBER)
  207. #define FLASH_BLOCK_WORDS (uint32_t)((ROM_SIZEinWORDS) / STEPS_NUMBER)
  208. /* Constants necessary for RAM test (RAM_END is word aligned) */
  209. #define RAM_START (uint32_t *)0x20000000
  210. #define RAM_END (uint32_t *)0x20017FFF//0x2000BFFc
  211. /* Constants necessary for Transparent March tests */
  212. #define CLASS_B_START ((uint32_t *)(&__ICFEDIT_region_CLASSB_start__))
  213. #define CLASS_B_END ((uint32_t *)(&__ICFEDIT_region_CLASSB_end__))
  214. #define PNT_B_START ((uint32_t *)(&__ICFEDIT_region_PNT_start__ ))
  215. #define BUF_B_START ((uint32_t *)(&__ICFEDIT_region_BUF_start__ ))
  216. #define GotoCompilerStartUp() __iar_program_start();
  217. //#define REF_CRC32 __checksum
  218. #define REF_CRC32 ((uint32_t *)(0x0803DFF0))//__checksum
  219. #endif /* __IAR_SYSTEMS_ICC__ */
  220. #ifdef __CC_ARM /* KEIL Compiler */
  221. /* This is the KEIL compiler entry point, usually executed right after reset */
  222. extern void Reset_Handler( void );
  223. extern const uint32_t __Check_Sum;
  224. #define GotoCompilerStartUp() Reset_Handler();
  225. /* Constants necessary for Flash CRC calculation (ROM_SIZE in byte) */
  226. /* byte-aligned addresses */
  227. #define ROM_START ((uint8_t *)0x08000000)
  228. #define ROM_END ((uint8_t *)(&__Check_Sum) - 1)
  229. #define ROM_SIZE ((uint32_t)ROM_END - (uint32_t)ROM_START + 1)
  230. #define ROM_SIZEinWORDS (uint32_t) (ROM_SIZE/4u)
  231. #define STEPS_NUMBER ((uint32_t)ROM_SIZE/64)
  232. #define FLASH_BLOCK (uint16_t)((ROM_SIZE)/STEPS_NUMBER)
  233. #define FLASH_BLOCK_WORDS (uint32_t)((ROM_SIZEinWORDS)/STEPS_NUMBER)
  234. /* Constants necessary for Transparent March tests */
  235. #define CLASS_B_START ((uint32_t *) 0x20000040)
  236. #define CLASS_B_END ((uint32_t *) 0x200000C0)
  237. /* Constants necessary for RAM test (RAM_END is word aligned ) */
  238. #define RAM_START (uint32_t *)0x20000000
  239. #ifdef STM32F30X
  240. #define RAM_END (uint32_t *)0x2000BFFc
  241. #else
  242. #if defined(STM32F37X) || defined(STM32F38X)
  243. #define RAM_END (uint32_t *)0x20007FFc
  244. #endif
  245. #endif
  246. #endif /* __CC_ARM */
  247. #endif /* __SELFTEST_PARAM_H */
  248. /******************* (C) COPYRIGHT STMicroelectronics *****END OF FILE****/