timer0_print_cpuid.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "fw_hal.h"
  15. static uint16_t counter = 0;
  16. uint8_t readCode(uint8_t offset)
  17. {
  18. return (*(unsigned char volatile __CODE *)(__CID_ADDR + offset));
  19. }
  20. INTERRUPT(Timer0_Routine, EXTI_VectTimer0)
  21. {
  22. uint8_t i, j;
  23. counter++;
  24. if (counter == 1000)
  25. {
  26. i = 0;
  27. counter = 0;
  28. UART1_TxString("ADDR: 0x");
  29. UART1_TxHex(__CID_ADDR >> 8);
  30. UART1_TxHex(__CID_ADDR & 0xFF);
  31. UART1_TxString("\r\n");
  32. UART1_TxString(" VER1 VER2\r\n");
  33. UART1_TxString("VRTRIM 40M: ");
  34. UART1_TxHex(readCode(i++));
  35. UART1_TxString("\r\n");
  36. UART1_TxString("VRTRIM 24M: ");
  37. UART1_TxHex(readCode(i++));
  38. UART1_TxString("\r\n");
  39. UART1_TxString("VRTRIM 35M ??M: ");
  40. UART1_TxHex(readCode(i++));
  41. UART1_TxString("\r\n");
  42. UART1_TxString("VRTRIM 20M ??M: ");
  43. UART1_TxHex(readCode(i++));
  44. UART1_TxString("\r\n");
  45. UART1_TxString("ITRIM --- 45M: ");
  46. UART1_TxHex(readCode(i++));
  47. UART1_TxString("\r\n");
  48. UART1_TxString("ITRIM --- 40M: ");
  49. UART1_TxHex(readCode(i++));
  50. UART1_TxString("\r\n");
  51. UART1_TxString("ITRIM 36.864M: ");
  52. UART1_TxHex(readCode(i++));
  53. UART1_TxString("\r\n");
  54. UART1_TxString("ITRIM 35M: ");
  55. UART1_TxHex(readCode(i++));
  56. UART1_TxString("\r\n");
  57. UART1_TxString("ITRIM 33.1776M: ");
  58. UART1_TxHex(readCode(i++));
  59. UART1_TxString("\r\n");
  60. UART1_TxString("ITRIM 30M: ");
  61. UART1_TxHex(readCode(i++));
  62. UART1_TxString("\r\n");
  63. UART1_TxString("ITRIM 27M: ");
  64. UART1_TxHex(readCode(i++));
  65. UART1_TxString("\r\n");
  66. UART1_TxString("ITRIM 20M: ");
  67. UART1_TxHex(readCode(i++));
  68. UART1_TxString("\r\n");
  69. UART1_TxString("ITRIM 24M: ");
  70. UART1_TxHex(readCode(i++));
  71. UART1_TxString("\r\n");
  72. UART1_TxString("ITRIM 22.1184M: ");
  73. UART1_TxHex(readCode(i++));
  74. UART1_TxString("\r\n");
  75. UART1_TxString("32kHz PD FreQ: ");
  76. UART1_TxHex(readCode(i++));
  77. UART1_TxHex(readCode(i++));
  78. UART1_TxString("\r\n");
  79. UART1_TxString("1.19Vref: ");
  80. UART1_TxHex(readCode(i++));
  81. UART1_TxHex(readCode(i++));
  82. UART1_TxString("\r\n");
  83. UART1_TxString("\r\n");
  84. UART1_TxString("MCUID: ");
  85. for (j = 0; j < 7; j++)
  86. {
  87. UART1_TxHex(readCode(i+j));
  88. UART1_TxChar(' ');
  89. }
  90. UART1_TxString("\r\n");
  91. UART1_TxString("Current IRCBAND:");
  92. UART1_TxHex(IRCBAND);
  93. UART1_TxString(", VRTRIM:");
  94. UART1_TxHex(VRTRIM);
  95. UART1_TxString(", IRTRIM:");
  96. UART1_TxHex(IRTRIM);
  97. UART1_TxString(", LIRTRIM:");
  98. UART1_TxHex(LIRTRIM);
  99. UART1_TxString("\r\n\r\n");
  100. }
  101. }
  102. void main(void)
  103. {
  104. // Set system clock. Remove this line if system clock is already set by STC-ISP
  105. SYS_SetClock();
  106. // UART1 configuration: baud 115200 with Timer2, 1T mode, no interrupt
  107. UART1_Config8bitUart(UART1_BaudSource_Timer2, HAL_State_ON, 115200);
  108. // Timer0 configuration: 16-bit auto-reload, interrupt enabled
  109. TIM_Timer0_Config(HAL_State_ON, TIM_TimerMode_16BitAuto, 1000);
  110. EXTI_Timer0_SetIntState(HAL_State_ON);
  111. EXTI_Timer0_SetIntPriority(EXTI_IntPriority_High);
  112. EXTI_Global_SetIntState(HAL_State_ON);
  113. TIM_Timer0_SetRunState(HAL_State_ON);
  114. while(1);
  115. }