1
0

em_chip.h 5.4 KB

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