2022-08-15 04:20:27 -05:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2015-2019 BES.
|
|
|
|
* All rights reserved. All unpublished rights reserved.
|
|
|
|
*
|
|
|
|
* No part of this work may be used or reproduced in any form or by any
|
|
|
|
* means, or stored in a database or retrieval system, without prior written
|
|
|
|
* permission of BES.
|
|
|
|
*
|
|
|
|
* Use of this work is governed by a license granted by BES.
|
|
|
|
* This work contains confidential and proprietary information of
|
|
|
|
* BES. which is protected by copyright, trade secret,
|
|
|
|
* trademark and other intellectual property rights.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __ARM_ARCH_ISA_ARM
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "system_ARMCM.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "cmsis.h"
|
|
|
|
#include "hal_location.h"
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void BOOT_TEXT_FLASH_LOC SystemInit(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#if (__FPU_USED == 1)
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->CPACR |= ((3UL << 10 * 2) | /* set CP10 Full Access */
|
|
|
|
(3UL << 11 * 2)); /* set CP11 Full Access */
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->CCR |= SCB_CCR_DIV_0_TRP_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __ARM_ARCH_8M_MAIN__
|
2023-02-01 14:52:54 -06:00
|
|
|
// Disable stack limit check on hard fault, NMI and reset
|
|
|
|
// (The check will generate STKOF usage fault)
|
|
|
|
SCB->CCR |= SCB_CCR_STKOFHFNMIGN_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef UNALIGNED_ACCESS
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->CCR &= ~SCB_CCR_UNALIGN_TRP_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef USAGE_FAULT
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk;
|
|
|
|
NVIC_SetPriority(UsageFault_IRQn, IRQ_PRIORITY_REALTIME);
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->SHCSR &= ~SCB_SHCSR_USGFAULTENA_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_FAULT
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->SHCSR |= SCB_SHCSR_BUSFAULTENA_Msk;
|
|
|
|
NVIC_SetPriority(BusFault_IRQn, IRQ_PRIORITY_REALTIME);
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->SHCSR &= ~SCB_SHCSR_BUSFAULTENA_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
#ifdef MEM_FAULT
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
|
|
|
NVIC_SetPriority(MemoryManagement_IRQn, IRQ_PRIORITY_REALTIME);
|
2022-08-15 04:20:27 -05:00
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
|
|
|
|
TZ_SAU_Setup();
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef UNALIGNED_ACCESS
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool get_unaligned_access_status(void) {
|
|
|
|
return !(SCB->CCR & SCB_CCR_UNALIGN_TRP_Msk);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
bool config_unaligned_access(bool enable) {
|
|
|
|
bool en;
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
en = !(SCB->CCR & SCB_CCR_UNALIGN_TRP_Msk);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
if (enable) {
|
|
|
|
SCB->CCR &= ~SCB_CCR_UNALIGN_TRP_Msk;
|
|
|
|
} else {
|
|
|
|
SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk;
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
return en;
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
// CPU ID
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
uint32_t BOOT_TEXT_SRAM_DEF(get_cpu_id)(void) {
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef CHIP_HAS_CP
|
|
|
|
#ifdef __ARM_ARCH_8M_MAIN__
|
2023-02-01 14:52:54 -06:00
|
|
|
return (SCB->ID_ADR & 3);
|
|
|
|
#else /*__ARM_ARCH_8M_MAIN__*/
|
|
|
|
return (SCB->ADR & 3);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif /*__ARM_ARCH_8M_MAIN__*/
|
|
|
|
#else
|
2023-02-01 14:52:54 -06:00
|
|
|
return 0;
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|