system_nrf5340_network.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2009-2020 ARM Limited. All rights reserved.
  3. SPDX-License-Identifier: Apache-2.0
  4. Licensed under the Apache License, Version 2.0 (the License); you may
  5. not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an AS IS BASIS, WITHOUT
  10. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. NOTICE: This file has been modified by Nordic Semiconductor ASA.
  14. */
  15. /* NOTE: Template files (including this one) are application specific and therefore expected to
  16. be copied into the application project folder prior to its use! */
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include "nrf.h"
  20. #include "nrf_erratas.h"
  21. #include "system_nrf5340_network.h"
  22. /*lint ++flb "Enter library region" */
  23. #define __SYSTEM_CLOCK (64000000UL) /*!< NRF5340 network core uses a fixed System Clock Frequency of 32MHz */
  24. #if defined ( __CC_ARM )
  25. uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
  26. #elif defined ( __ICCARM__ )
  27. __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
  28. #elif defined ( __GNUC__ )
  29. uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
  30. #endif
  31. void SystemCoreClockUpdate(void)
  32. {
  33. SystemCoreClock = __SYSTEM_CLOCK;
  34. }
  35. void SystemInit(void)
  36. {
  37. /* Trimming of the device. Copy all the trimming values from FICR into the target addresses. Trim
  38. until one ADDR is not initialized. */
  39. uint32_t index = 0;
  40. for (index = 0; index < 32ul && NRF_FICR_NS->TRIMCNF[index].ADDR != (uint32_t *)0xFFFFFFFFul; index++){
  41. #if defined ( __ICCARM__ )
  42. /* IAR will complain about the order of volatile pointer accesses. */
  43. #pragma diag_suppress=Pa082
  44. #endif
  45. *NRF_FICR_NS->TRIMCNF[index].ADDR = NRF_FICR_NS->TRIMCNF[index].DATA;
  46. #if defined ( __ICCARM__ )
  47. #pragma diag_default=Pa082
  48. #endif
  49. }
  50. /* Workaround for Errata 49 "SLEEPENTER and SLEEPEXIT events asserted after pin reset" found at the Errata document
  51. for your device located at https://infocenter.nordicsemi.com/index.jsp */
  52. if (nrf53_errata_49())
  53. {
  54. if (NRF_RESET_NS->RESETREAS & RESET_RESETREAS_RESETPIN_Msk)
  55. {
  56. NRF_POWER_NS->EVENTS_SLEEPENTER = 0;
  57. NRF_POWER_NS->EVENTS_SLEEPEXIT = 0;
  58. }
  59. }
  60. /* Workaround for Errata 55 "Bits in RESETREAS are set when they should not be" found at the Errata document
  61. for your device located at https://infocenter.nordicsemi.com/index.jsp */
  62. if (nrf53_errata_55())
  63. {
  64. if (NRF_RESET_NS->RESETREAS & RESET_RESETREAS_RESETPIN_Msk){
  65. NRF_RESET_NS->RESETREAS = ~RESET_RESETREAS_RESETPIN_Msk;
  66. }
  67. }
  68. SystemCoreClockUpdate();
  69. }
  70. /*lint --flb "Leave library region" */