efm32_chip.h 5.2 KB

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