2016-02-04 15:30:06 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
|
|
|
|
* 2016 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cpu_nrf52
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Implementation of the CPU initialization
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
* @author Jan Wagner <mail@jwagner.eu>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-07-09 11:25:34 +02:00
|
|
|
#define DONT_OVERRIDE_NVIC
|
|
|
|
|
2016-02-04 15:30:06 +01:00
|
|
|
#include "cpu.h"
|
2023-01-02 18:08:35 +01:00
|
|
|
#include "kernel_init.h"
|
2022-04-28 12:17:02 +02:00
|
|
|
#include "nrfx_riot.h"
|
2017-04-03 15:26:10 +02:00
|
|
|
#include "nrf_clock.h"
|
2016-02-04 15:30:06 +01:00
|
|
|
#include "periph_conf.h"
|
2017-01-20 11:18:38 +01:00
|
|
|
#include "periph/init.h"
|
2019-04-10 11:07:05 +02:00
|
|
|
#include "stdio_base.h"
|
2016-02-04 15:30:06 +01:00
|
|
|
|
|
|
|
/* FTPAN helper functions */
|
|
|
|
static bool ftpan_32(void);
|
|
|
|
static bool ftpan_37(void);
|
|
|
|
static bool ftpan_36(void);
|
|
|
|
|
2023-07-06 15:47:22 +02:00
|
|
|
/**
|
|
|
|
* @brief LFCLK Clock selection configuration guard
|
|
|
|
*/
|
|
|
|
#if ((CLOCK_LFCLK != CLOCK_LFCLKSRC_SRC_RC) && \
|
|
|
|
(CLOCK_LFCLK != CLOCK_LFCLKSRC_SRC_Xtal) && \
|
|
|
|
(CLOCK_LFCLK != CLOCK_LFCLKSRC_SRC_Synth))
|
|
|
|
#error "LFCLK init: CLOCK_LFCLK has invalid value"
|
|
|
|
#endif
|
|
|
|
|
2016-02-04 15:30:06 +01:00
|
|
|
/**
|
|
|
|
* @brief Initialize the CPU, set IRQ priorities
|
|
|
|
*/
|
|
|
|
void cpu_init(void)
|
|
|
|
{
|
|
|
|
/* Workaround for FTPAN-32
|
|
|
|
* "DIF: Debug session automatically enables TracePort pins." */
|
|
|
|
if (ftpan_32()) {
|
|
|
|
CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Workaround for FTPAN-37
|
|
|
|
* "AMLI: EasyDMA is slow with Radio, ECB, AAR and CCM." */
|
|
|
|
if (ftpan_37()) {
|
|
|
|
*(volatile uint32_t *)0x400005A0 = 0x3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Workaround for FTPAN-36
|
|
|
|
* "CLOCK: Some registers are not reset when expected." */
|
|
|
|
if (ftpan_36()) {
|
|
|
|
NRF_CLOCK->EVENTS_DONE = 0;
|
|
|
|
NRF_CLOCK->EVENTS_CTTO = 0;
|
|
|
|
}
|
2020-03-07 17:04:06 +01:00
|
|
|
/* Enable the DC/DC power converter */
|
|
|
|
nrfx_dcdc_init();
|
2016-02-04 15:30:06 +01:00
|
|
|
|
2017-04-03 15:26:10 +02:00
|
|
|
/* initialize hf clock */
|
|
|
|
clock_init_hf();
|
2016-07-09 11:25:34 +02:00
|
|
|
|
2020-06-23 00:30:18 +02:00
|
|
|
#ifdef NVMC_ICACHECNF_CACHEEN_Msk
|
2018-06-22 16:09:23 +02:00
|
|
|
/* enable instruction cache */
|
|
|
|
NRF_NVMC->ICACHECNF = (NVMC_ICACHECNF_CACHEEN_Msk);
|
2020-06-23 00:30:18 +02:00
|
|
|
#endif
|
2018-06-22 16:09:23 +02:00
|
|
|
|
2017-12-02 23:14:48 +01:00
|
|
|
/* call cortexm default initialization */
|
|
|
|
cortexm_init();
|
2017-01-20 11:18:38 +01:00
|
|
|
|
2019-04-10 11:07:05 +02:00
|
|
|
/* initialize stdio prior to periph_init() to allow use of DEBUG() there */
|
2023-01-02 18:08:35 +01:00
|
|
|
early_init();
|
2019-04-10 11:07:05 +02:00
|
|
|
|
2017-01-20 11:18:38 +01:00
|
|
|
/* trigger static peripheral initialization */
|
|
|
|
periph_init();
|
2016-02-04 15:30:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check workaround for FTPAN-32
|
|
|
|
*/
|
|
|
|
static bool ftpan_32(void)
|
|
|
|
{
|
|
|
|
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6)
|
|
|
|
&& (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) {
|
|
|
|
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30)
|
|
|
|
&& (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check workaround for FTPAN-36
|
|
|
|
*/
|
|
|
|
static bool ftpan_36(void)
|
|
|
|
{
|
|
|
|
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6)
|
|
|
|
&& (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) {
|
|
|
|
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30)
|
|
|
|
&& (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check workaround for FTPAN-37
|
|
|
|
*/
|
|
|
|
static bool ftpan_37(void)
|
|
|
|
{
|
|
|
|
if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6)
|
|
|
|
&& (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) {
|
|
|
|
if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30)
|
|
|
|
&& (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|