123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #include <stdint.h>
- #include <stdbool.h>
- #include "nrf.h"
- #include "nrf_erratas.h"
- #include "system_nrf52810.h"
- #define __SYSTEM_CLOCK_64M (64000000UL)
- #if defined ( __CC_ARM )
- uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M;
- #elif defined ( __ICCARM__ )
- __root uint32_t SystemCoreClock = __SYSTEM_CLOCK_64M;
- #elif defined ( __GNUC__ )
- uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M;
- #endif
- void SystemCoreClockUpdate(void)
- {
- SystemCoreClock = __SYSTEM_CLOCK_64M;
- }
- void SystemInit(void)
- {
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_12()){
- *(volatile uint32_t *)0x40013540 = (*(uint32_t *)0x10000324 & 0x00001F00) >> 8;
- }
- #endif
-
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_16()){
- *(volatile uint32_t *)0x4007C074 = 3131961357ul;
- }
- #endif
-
-
- if (nrf52_errata_31()){
- *(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13;
- }
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_32()){
- CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
- }
- #endif
-
-
- if (nrf52_errata_36()){
- NRF_CLOCK->EVENTS_DONE = 0;
- NRF_CLOCK->EVENTS_CTTO = 0;
- NRF_CLOCK->CTIV = 0;
- }
-
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_37()){
- *(volatile uint32_t *)0x400005A0 = 0x3;
- }
- #endif
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_57()){
- *(volatile uint32_t *)0x40005610 = 0x00000005;
- *(volatile uint32_t *)0x40005688 = 0x00000001;
- *(volatile uint32_t *)0x40005618 = 0x00000000;
- *(volatile uint32_t *)0x40005614 = 0x0000003F;
- }
- #endif
-
-
- if (nrf52_errata_66()){
- NRF_TEMP->A0 = NRF_FICR->TEMP.A0;
- NRF_TEMP->A1 = NRF_FICR->TEMP.A1;
- NRF_TEMP->A2 = NRF_FICR->TEMP.A2;
- NRF_TEMP->A3 = NRF_FICR->TEMP.A3;
- NRF_TEMP->A4 = NRF_FICR->TEMP.A4;
- NRF_TEMP->A5 = NRF_FICR->TEMP.A5;
- NRF_TEMP->B0 = NRF_FICR->TEMP.B0;
- NRF_TEMP->B1 = NRF_FICR->TEMP.B1;
- NRF_TEMP->B2 = NRF_FICR->TEMP.B2;
- NRF_TEMP->B3 = NRF_FICR->TEMP.B3;
- NRF_TEMP->B4 = NRF_FICR->TEMP.B4;
- NRF_TEMP->B5 = NRF_FICR->TEMP.B5;
- NRF_TEMP->T0 = NRF_FICR->TEMP.T0;
- NRF_TEMP->T1 = NRF_FICR->TEMP.T1;
- NRF_TEMP->T2 = NRF_FICR->TEMP.T2;
- NRF_TEMP->T3 = NRF_FICR->TEMP.T3;
- NRF_TEMP->T4 = NRF_FICR->TEMP.T4;
- }
-
-
- if (nrf52_errata_103()){
- NRF_CCM->MAXPACKETSIZE = 0xFBul;
- }
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_108()){
- *(volatile uint32_t *)0x40000EE4ul = *(volatile uint32_t *)0x10000258ul & 0x0000004Ful;
- }
- #endif
-
-
- if (nrf52_errata_136()){
- if (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk){
- NRF_POWER->RESETREAS = ~POWER_RESETREAS_RESETPIN_Msk;
- }
- }
-
- #if defined (DEVELOP_IN_NRF52832)
-
- if (nrf52_errata_182()){
- *(volatile uint32_t *) 0x4000173C |= (0x1 << 10);
- }
- #endif
-
- if (nrf52_errata_217()){
- *(volatile uint32_t *)0x40000EE4ul |= 0x0000000Ful;
- }
-
- #if defined (CONFIG_GPIO_AS_PINRESET)
- if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
- ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){
- NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- NRF_UICR->PSELRESET[0] = 21;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- NRF_UICR->PSELRESET[1] = 21;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- NVIC_SystemReset();
- }
- #endif
-
- #if defined (DEVELOP_IN_NRF52832)
- if (((*((uint32_t *)0x10001200) & (1 << 0)) != 0) || ((*((uint32_t *)0x10001204) & (1 << 0)) != 0)){
- NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- *((uint32_t *)0x10001200) = 0;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- *((uint32_t *)0x10001204) = 0;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
- NVIC_SystemReset();
- }
- #endif
- SystemCoreClockUpdate();
- }
|