efm32_chip.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Chip Initialization API for EFM32
  4. * @author Energy Micro AS
  5. * @version 2.3.2
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_CHIP_H
  29. #define __EFM32_CHIP_H
  30. #include "efm32.h"
  31. #include "efm32_system.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /***************************************************************************//**
  36. * @addtogroup EFM32_Library
  37. * @{
  38. ******************************************************************************/
  39. /***************************************************************************//**
  40. * @addtogroup CHIP
  41. * @brief Chip Initialization API for EFM32
  42. * @{
  43. ******************************************************************************/
  44. /**************************************************************************//**
  45. * @brief
  46. * Chip initialization routine for revision errata workarounds
  47. *
  48. * This init function will configure the EFM32 device to a state where it is
  49. * as similar as later revisions as possible, to improve software compatibility
  50. * with newer parts. See the device specific errata for details.
  51. *****************************************************************************/
  52. static __INLINE void CHIP_Init(void)
  53. {
  54. /* Currently only run time changes for Gecko devices */
  55. #if defined(_EFM32_GECKO_FAMILY)
  56. uint32_t rev;
  57. SYSTEM_ChipRevision_TypeDef chipRev;
  58. volatile uint32_t *reg;
  59. rev = *(volatile uint32_t *)(0x0FE081FC);
  60. /* Engineering Sample calibration setup */
  61. if ((rev >> 24) == 0)
  62. {
  63. reg = (volatile uint32_t *)0x400CA00C;
  64. *reg &= ~(0x70UL);
  65. /* DREG */
  66. reg = (volatile uint32_t *)0x400C6020;
  67. *reg &= ~(0xE0000000UL);
  68. *reg |= ~(7UL << 25);
  69. }
  70. if ((rev >> 24) <= 3)
  71. {
  72. /* DREG */
  73. reg = (volatile uint32_t *)0x400C6020;
  74. *reg &= ~(0x00001F80UL);
  75. /* Update CMU reset values */
  76. reg = (volatile uint32_t *)0x400C8040;
  77. *reg = 0;
  78. reg = (volatile uint32_t *)0x400C8044;
  79. *reg = 0;
  80. reg = (volatile uint32_t *)0x400C8058;
  81. *reg = 0;
  82. reg = (volatile uint32_t *)0x400C8060;
  83. *reg = 0;
  84. reg = (volatile uint32_t *)0x400C8078;
  85. *reg = 0;
  86. }
  87. SYSTEM_ChipRevisionGet(&chipRev);
  88. if (chipRev.major == 0x01)
  89. {
  90. /* Rev A errata handling for EM2/3. Must enable DMA clock in order for EM2/3 */
  91. /* to work. This will be fixed in later chip revisions, so only do for rev A. */
  92. if (chipRev.minor == 00)
  93. {
  94. reg = (volatile uint32_t *)0x400C8040;
  95. *reg |= 0x2;
  96. }
  97. /* Rev A+B errata handling for I2C when using EM2/3. USART0 clock must be enabled */
  98. /* after waking up from EM2/EM3 in order for I2C to work. This will be fixed in */
  99. /* later chip revisions, so only do for rev A+B. */
  100. if (chipRev.minor <= 0x01)
  101. {
  102. reg = (volatile uint32_t *)0x400C8044;
  103. *reg |= 0x1;
  104. }
  105. }
  106. /* Ensure correct ADC/DAC calibration value */
  107. rev = *(volatile uint32_t *)0x0FE081F0;
  108. if (rev < 0x4C8ABA00)
  109. {
  110. uint32_t cal;
  111. /* Enable ADC/DAC clocks */
  112. reg = (volatile uint32_t *)0x400C8044UL;
  113. *reg |= (1 << 14 | 1 << 11);
  114. /* Retrive calibration values */
  115. cal = ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x00007F00UL) >>
  116. 8) << 24;
  117. cal |= ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x0000007FUL) >>
  118. 0) << 16;
  119. cal |= ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x00007F00UL) >>
  120. 8) << 8;
  121. cal |= ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x0000007FUL) >>
  122. 0) << 0;
  123. /* ADC0->CAL = 1.25 reference */
  124. reg = (volatile uint32_t *)0x40002034UL;
  125. *reg = cal;
  126. /* DAC0->CAL = 1.25 reference */
  127. reg = (volatile uint32_t *)(0x4000402CUL);
  128. cal = *(volatile uint32_t *)0x0FE081C8UL;
  129. *reg = cal;
  130. /* Turn off ADC/DAC clocks */
  131. reg = (volatile uint32_t *)0x400C8044UL;
  132. *reg &= ~(1 << 14 | 1 << 11);
  133. }
  134. #endif
  135. }
  136. /** @} (end addtogroup SYSTEM) */
  137. /** @} (end addtogroup EFM32_Library) */
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif /* __EFM32_CHIP_H */