rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright (c) 2015, Nordic Semiconductor ASA
|
| 2 | * All rights reserved.
|
| 3 | *
|
| 4 | * Redistribution and use in source and binary forms, with or without
|
| 5 | * modification, are permitted provided that the following conditions are met:
|
| 6 | *
|
| 7 | * * Redistributions of source code must retain the above copyright notice, this
|
| 8 | * list of conditions and the following disclaimer.
|
| 9 | *
|
| 10 | * * Redistributions in binary form must reproduce the above copyright notice,
|
| 11 | * this list of conditions and the following disclaimer in the documentation
|
| 12 | * and/or other materials provided with the distribution.
|
| 13 | *
|
| 14 | * * Neither the name of Nordic Semiconductor ASA nor the names of its
|
| 15 | * contributors may be used to endorse or promote products derived from
|
| 16 | * this software without specific prior written permission.
|
| 17 | *
|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 28 | *
|
| 29 | */
|
| 30 |
|
| 31 | /* NOTE: Template files (including this one) are application specific and therefore expected to
|
| 32 | be copied into the application project folder prior to its use! */
|
| 33 |
|
| 34 | #include <stdint.h>
|
| 35 | #include <stdbool.h>
|
| 36 | #include <platform/nrf51.h>
|
| 37 | #include <platform/system_nrf51.h>
|
| 38 |
|
| 39 | /*lint ++flb "Enter library region" */
|
| 40 |
|
| 41 |
|
| 42 | #define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
|
| 43 |
|
| 44 | static bool is_manual_peripheral_setup_needed(void);
|
| 45 | static bool is_disabled_in_debug_needed(void);
|
| 46 |
|
| 47 |
|
| 48 | #if defined ( __CC_ARM )
|
| 49 | uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
|
| 50 | #elif defined ( __ICCARM__ )
|
| 51 | __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
|
| 52 | #elif defined ( __GNUC__ )
|
| 53 | uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
|
| 54 | #endif
|
| 55 |
|
| 56 | void SystemCoreClockUpdate(void)
|
| 57 | {
|
| 58 | SystemCoreClock = __SYSTEM_CLOCK;
|
| 59 | }
|
| 60 |
|
| 61 | void SystemInit(void)
|
| 62 | {
|
| 63 | /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
|
| 64 | It can also be done in the application main() function. */
|
| 65 |
|
| 66 | /* Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
|
| 67 | to enable the use of peripherals" found at Product Anomaly document for your device found at
|
| 68 | https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
|
| 69 | that do not need it is that the new peripherals in the second generation devices (LPCOMP for
|
| 70 | example) will not be available. */
|
| 71 | if (is_manual_peripheral_setup_needed())
|
| 72 | {
|
| 73 | *(uint32_t volatile *)0x40000504 = 0xC007FFDF;
|
| 74 | *(uint32_t volatile *)0x40006C18 = 0x00008000;
|
| 75 | }
|
| 76 |
|
| 77 | /* Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
|
| 78 | register is incorrect" found at Product Anomaly document four your device found at
|
| 79 | https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed. */
|
| 80 | if (is_disabled_in_debug_needed())
|
| 81 | {
|
| 82 | NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 |
|
| 87 | static bool is_manual_peripheral_setup_needed(void)
|
| 88 | {
|
| 89 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
|
| 90 | {
|
| 91 | if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x00) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
| 92 | {
|
| 93 | return true;
|
| 94 | }
|
| 95 | if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x10) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
| 96 | {
|
| 97 | return true;
|
| 98 | }
|
| 99 | if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
| 100 | {
|
| 101 | return true;
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 | return false;
|
| 106 | }
|
| 107 |
|
| 108 | static bool is_disabled_in_debug_needed(void)
|
| 109 | {
|
| 110 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
|
| 111 | {
|
| 112 | if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
|
| 113 | {
|
| 114 | return true;
|
| 115 | }
|
| 116 | }
|
| 117 |
|
| 118 | return false;
|
| 119 | }
|
| 120 |
|
| 121 | /*lint --flb "Leave library region" */
|