efm32_chip.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Chip Initialization API for EFM32
  4. * @author Energy Micro AS
  5. * @version 2.0.0
  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. uint32_t rev;
  55. SYSTEM_ChipRevision_TypeDef chipRev;
  56. volatile uint32_t *reg;
  57. rev = *(volatile uint32_t *)(0x0FE081FC);
  58. /* Engineering Sample calibration setup */
  59. if ((rev >> 24) == 0)
  60. {
  61. reg = (volatile uint32_t *)0x400CA00C;
  62. *reg &= ~(0x70UL);
  63. /* DREG */
  64. reg = (volatile uint32_t *)0x400C6020;
  65. *reg &= ~(0xE0000000UL);
  66. *reg |= ~(7UL << 25);
  67. }
  68. if ((rev >> 24) <= 3)
  69. {
  70. /* DREG */
  71. reg = (volatile uint32_t *)0x400C6020;
  72. *reg &= ~(0x00001F80UL);
  73. /* Update CMU reset values */
  74. reg = (volatile uint32_t *)0x400C8040;
  75. *reg = 0;
  76. reg = (volatile uint32_t *)0x400C8044;
  77. *reg = 0;
  78. reg = (volatile uint32_t *)0x400C8058;
  79. *reg = 0;
  80. reg = (volatile uint32_t *)0x400C8060;
  81. *reg = 0;
  82. reg = (volatile uint32_t *)0x400C8078;
  83. *reg = 0;
  84. }
  85. SYSTEM_ChipRevisionGet(&chipRev);
  86. if (chipRev.major == 0x01)
  87. {
  88. /* Rev A errata handling for EM2/3. Must enable DMA clock in order for EM2/3 */
  89. /* to work. This will be fixed in later chip revisions, so only do for rev A. */
  90. if (chipRev.minor == 00)
  91. {
  92. reg = (volatile uint32_t *)0x400C8040;
  93. *reg |= 0x2;
  94. }
  95. /* Rev A+B errata handling for I2C when using EM2/3. USART0 clock must be enabled */
  96. /* after waking up from EM2/EM3 in order for I2C to work. This will be fixed in */
  97. /* later chip revisions, so only do for rev A+B. */
  98. if (chipRev.minor <= 0x01)
  99. {
  100. reg = (volatile uint32_t *)0x400C8044;
  101. *reg |= 0x1;
  102. }
  103. }
  104. /* Ensure correct ADC/DAC calibration value */
  105. rev = *(volatile uint32_t *)0x0FE081F0;
  106. if (rev < 0x4C8ABA00)
  107. {
  108. uint32_t cal;
  109. /* Enable ADC/DAC clocks */
  110. reg = (volatile uint32_t *)0x400C8044UL;
  111. *reg |= (1 << 14 | 1 << 11);
  112. /* Retrive calibration values */
  113. cal = ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x00007F00UL) >>
  114. 8) << 24;
  115. cal |= ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x0000007FUL) >>
  116. 0) << 16;
  117. cal |= ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x00007F00UL) >>
  118. 8) << 8;
  119. cal |= ((*(volatile uint32_t *)(0x0FE081B4UL) & 0x0000007FUL) >>
  120. 0) << 0;
  121. /* ADC0->CAL = 1.25 reference */
  122. reg = (volatile uint32_t *)0x40002034UL;
  123. *reg = cal;
  124. /* DAC0->CAL = 1.25 reference */
  125. reg = (volatile uint32_t *)(0x4000402CUL);
  126. cal = *(volatile uint32_t *)0x0FE081C8UL;
  127. *reg = cal;
  128. /* Turn off ADC/DAC clocks */
  129. reg = (volatile uint32_t *)0x400C8044UL;
  130. *reg &= ~(1 << 14 | 1 << 11);
  131. }
  132. }
  133. /** @} (end addtogroup SYSTEM) */
  134. /** @} (end addtogroup EFM32_Library) */
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif /* __EFM32_CHIP_H */