aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/NRF5/NRF52832
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/NRF5/NRF52832')
-rw-r--r--os/hal/ports/NRF5/NRF52832/hal_lld.c26
-rw-r--r--os/hal/ports/NRF5/NRF52832/hal_lld.h32
-rw-r--r--os/hal/ports/NRF5/NRF52832/nrf_delay.h335
-rw-r--r--os/hal/ports/NRF5/NRF52832/platform.mk3
4 files changed, 287 insertions, 109 deletions
diff --git a/os/hal/ports/NRF5/NRF52832/hal_lld.c b/os/hal/ports/NRF5/NRF52832/hal_lld.c
index 500de13..e63e57e 100644
--- a/os/hal/ports/NRF5/NRF52832/hal_lld.c
+++ b/os/hal/ports/NRF5/NRF52832/hal_lld.c
@@ -55,23 +55,37 @@
*/
void hal_lld_init(void)
{
- /* High frequency clock initialisation
+ /* High frequency clock initialization
*/
NRF_CLOCK->TASKS_HFCLKSTOP = 1;
+
#if !defined(NRF5_XTAL_VALUE) && (NRF5_XTAL_VALUE != 32000000)
#error "A 32Mhz crystal is mandatory on nRF52 boards."
#endif
+#if (NRF5_HFCLK_SOURCE == NRF5_HFCLK_HFXO)
+ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
+ NRF_CLOCK->TASKS_HFCLKSTART = 1;
+ while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
+#endif
- /* Low frequency clock initialisation
- * Clock is only started if st driver requires it
+ /* Low frequency clock initialization
*/
+#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE)
+#if (NRF5_ST_USE_RTC0 || NRF5_ST_USE_RTC1) && \
+ (NRF5_LFCLK_SOURCE == NRF5_LFCLK_RC)
+#error "A NRF5_SYSTEM_TICKS_AS_RTC requires LFCLK clock to be started."
+#endif
+#endif
+
NRF_CLOCK->TASKS_LFCLKSTOP = 1;
+
+#if (NRF5_LFCLK_SOURCE != NRF5_LFCLK_RC)
NRF_CLOCK->LFCLKSRC = NRF5_LFCLK_SOURCE;
-
-#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) && \
- (NRF5_SYSTEM_TICKS == NRF5_SYSTEM_TICKS_AS_RTC)
+
+ NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
+ while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
#endif
}
diff --git a/os/hal/ports/NRF5/NRF52832/hal_lld.h b/os/hal/ports/NRF5/NRF52832/hal_lld.h
index 24784d3..a2a8cc3 100644
--- a/os/hal/ports/NRF5/NRF52832/hal_lld.h
+++ b/os/hal/ports/NRF5/NRF52832/hal_lld.h
@@ -60,22 +60,36 @@
/*===========================================================================*/
/**
+ * @brief Select source of High Frequency Clock (HFCLK)
+ * @details Possible values for source are:
+ * 0 : 64 MHz internal oscillator (HFINT)
+ * 1 : 32 MHz external crystal oscillator (HFXO)
+ */
+#if !defined(NRF5_HFCLK_SOURCE) || defined(__DOXYGEN__)
+#define NRF5_HFCLK_SOURCE NRF5_HFCLK_HFINT
+#endif
+
+/**
* @brief Select source of Low Frequency Clock (LFCLK)
* @details Possible values for source are:
* 0 : RC oscillator
- * 1 : External cristal
- * 2 : Synthetized clock from High Frequency Clock (HFCLK)
- * When cristal is not available it's preferable to use the
- * internal RC oscillator that synthezing the clock.
+ * 1 : External crystal
+ * 2 : Synthesized clock from High Frequency Clock (HFCLK)
+ * When crystal is not available it's preferable to use the
+ * internal RC oscillator that synthesizing the clock.
*/
#if !defined(NRF5_LFCLK_SOURCE) || defined(__DOXYGEN__)
-#define NRF5_LFCLK_SOURCE 0
+#define NRF5_LFCLK_SOURCE NRF5_LFCLK_RC
#endif
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
+#if (NRF5_HFCLK_SOURCE < 0) || (NRF5_HFCLK_SOURCE > 1)
+#error "Possible value for NRF5_HFCLK_SOURCE are HFINT=0, HFXO=1"
+#endif
+
#if (NRF5_LFCLK_SOURCE < 0) || (NRF5_LFCLK_SOURCE > 2)
#error "Possible value for NRF5_LFCLK_SOURCE are 0=RC, 1=XTAL, 2=Synth"
#endif
@@ -91,6 +105,14 @@
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
+#if 0 // moved to board.h
+#define NRF5_HFCLK_HFINT 0
+#define NRF5_HFCLK_HFXO 1
+
+#define NRF5_LFCLK_RC 0
+#define NRF5_LFCLK_XTAL 1
+#define NRF5_LFCLK_SYNTH 2
+#endif
#include "nvic.h"
diff --git a/os/hal/ports/NRF5/NRF52832/nrf_delay.h b/os/hal/ports/NRF5/NRF52832/nrf_delay.h
index 9b5df64..b73d8ae 100644
--- a/os/hal/ports/NRF5/NRF52832/nrf_delay.h
+++ b/os/hal/ports/NRF5/NRF52832/nrf_delay.h
@@ -1,97 +1,238 @@
-/*
- Copyright (C) 2015 Stephen Caudle
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-/**
- * @file NRF5/NRF52832/nrf_delay.h
- * @brief NRF5 Delay routines
- *
- * @{
- */
-
-#ifndef _NRF_DELAY_H
-#define _NRF_DELAY_H
-
-inline static void nrf_delay_us(uint32_t volatile number_of_us) __attribute__((always_inline));
-inline static void nrf_delay_us(uint32_t volatile number_of_us)
-{
-register uint32_t delay __asm ("r0") = number_of_us;
-__asm volatile (
-".syntax unified\n"
- "1:\n"
- " SUBS %0, %0, #1\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " NOP\n"
- " BNE 1b\n"
- ".syntax divided\n"
- : "+r" (delay));
-}
-#endif //__NRF_DELAY_H
+#ifndef _NRF_DELAY_H
+#define _NRF_DELAY_H
+
+/**
+ * @brief Function for delaying execution for number of microseconds.
+ *
+ * @note NRF52 has instruction cache and because of that delay is not precise.
+ *
+ * @param number_of_ms
+ */
+/*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */
+#if defined ( __CC_ARM )
+
+static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
+{
+loop
+ SUBS R0, R0, #1
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+#ifdef NRF52
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+ NOP
+#endif
+ BNE loop
+ BX LR
+}
+
+#elif defined ( __ICCARM__ )
+
+static void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
+{
+__ASM (
+"loop:\n\t"
+ " SUBS R0, R0, #1\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+#ifdef NRF52
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+ " NOP\n\t"
+#endif
+ " BNE.n loop\n\t");
+}
+
+#elif defined ( _WIN32 ) || defined ( __unix ) || defined( __APPLE__ )
+
+__STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us);
+
+#ifndef CUSTOM_NRF_DELAY_US
+__STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us)
+{}
+#endif
+
+#elif defined ( __GNUC__ )
+
+inline static void nrf_delay_us(uint32_t volatile number_of_us) __attribute__((always_inline));
+inline static void nrf_delay_us(uint32_t volatile number_of_us)
+{
+register uint32_t delay __ASM ("r0") = number_of_us;
+__ASM volatile (
+#ifdef NRF51
+ ".syntax unified\n"
+#endif
+ "1:\n"
+ " SUBS %0, %0, #1\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+#ifdef NRF52
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+ " NOP\n"
+#endif
+ " BNE 1b\n"
+#ifdef NRF51
+ ".syntax divided\n"
+#endif
+ : "+r" (delay));
+}
+#endif
+
+#endif
diff --git a/os/hal/ports/NRF5/NRF52832/platform.mk b/os/hal/ports/NRF5/NRF52832/platform.mk
index e71f591..f1fcfe7 100644
--- a/os/hal/ports/NRF5/NRF52832/platform.mk
+++ b/os/hal/ports/NRF5/NRF52832/platform.mk
@@ -20,7 +20,8 @@ endif
include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/GPIOv1/driver.mk
include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/UARTv1/driver.mk
include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/SPIv1/driver.mk
-include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/TWIv1/driver.mk
+include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/TWIMv1/driver.mk
+include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/PWMv2/driver.mk
include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/TIMERv1/driver.mk
include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/WDTv1/driver.mk
include ${CHIBIOS_CONTRIB}/os/hal/ports/NRF5/LLD/RNGv1/driver.mk