Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/nrf52: nvmc and flash should depends on ALLOW_BSD_COMPONENTS=y #8827

Merged
merged 2 commits into from Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm/src/nrf52/Kconfig
Expand Up @@ -383,6 +383,7 @@ config NRF52_FLASH_PREFETCH

config NRF52_PROGMEM
bool "FLASH program memory"
depends on ALLOW_BSD_COMPONENTS
default n
select ARCH_HAVE_PROGMEM
---help---
Expand Down
13 changes: 8 additions & 5 deletions arch/arm/src/nrf52/Make.defs
Expand Up @@ -29,9 +29,16 @@ endif
endif

CHIP_CSRCS += nrf52_start.c nrf52_clockconfig.c nrf52_irq.c nrf52_utils.c
CHIP_CSRCS += nrf52_allocateheap.c nrf52_lowputc.c nrf52_gpio.c nrf52_nvmc.c
CHIP_CSRCS += nrf52_allocateheap.c nrf52_lowputc.c nrf52_gpio.c
CHIP_CSRCS += nrf52_uid.c

ifeq ($(CONFIG_ALLOW_BSD_COMPONENTS),y)
CHIP_CSRCS += nrf52_nvmc.c
ifeq ($(CONFIG_NRF52_PROGMEM),y)
CHIP_CSRCS += nrf52_flash.c
endif
endif

ifeq ($(CONFIG_ARCH_CHIP_NRF52832),y)
CHIP_CSRCS += nrf52832_errdata.c
endif
Expand All @@ -52,10 +59,6 @@ ifeq ($(CONFIG_NRF52_UART),y)
CHIP_CSRCS += nrf52_serial.c
endif

ifeq ($(CONFIG_NRF52_PROGMEM),y)
CHIP_CSRCS += nrf52_flash.c
endif

ifeq ($(CONFIG_NRF52_WDT),y)
CHIP_CSRCS += nrf52_wdt.c

Expand Down
4 changes: 4 additions & 0 deletions arch/arm/src/nrf52/nrf52_flash.c
Expand Up @@ -61,6 +61,10 @@
* Pre-processor Definitions
****************************************************************************/

#ifndef CONFIG_ALLOW_BSD_COMPONENTS
# error "This file requires Kconfig ALLOW_BSD_COMPONENTS"
#endif

#define NRF52_FLASH_PAGE_SIZE (4*1024)

#define NRF52_FLASH_ERASEDVAL (0xffu)
Expand Down
80 changes: 8 additions & 72 deletions arch/arm/src/nrf52/nrf52_nvmc.c
Expand Up @@ -53,6 +53,14 @@
#include "hardware/nrf52_nvmc.h"
#include "nrf52_nvmc.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#ifndef CONFIG_ALLOW_BSD_COMPONENTS
# error "This file requires Kconfig ALLOW_BSD_COMPONENTS"
#endif

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -102,78 +110,6 @@ static inline void nrf_mem_barrier(void)
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: nrf_nvmc_enable_icache
*
* Description:
* Enable I-Cache for Flash
*
* Input Parameter:
* flag - Flag to enable or disable.
*
* Returned Values:
* None
*
****************************************************************************/

void nrf_nvmc_enable_icache(bool flag)
{
uint32_t value;

/* Read the current icache configuration */

value = getreg32(NRF52_NVMC_ICACHECNF);

if (flag)
{
value |= NVMC_ICACHECNF_CACHEEN;
}
else
{
value &= ~NVMC_ICACHECNF_CACHEEN;
}

/* Setup the new icache configuration */

putreg32(value, NRF52_NVMC_ICACHECNF);
}

/****************************************************************************
* Name: nrf_nvmc_enable_profile
*
* Description:
* Enable profiling I-Cache for flash
*
* Input Parameter:
* flag - Flag to enable or disable.
*
* Returned Values:
* None
*
****************************************************************************/

void nrf_nvmc_enable_profile(bool flag)
{
uint32_t value;

/* Read the current icache configuration */

value = getreg32(NRF52_NVMC_ICACHECNF);

if (flag)
{
value |= NVMC_ICACHECNF_CACHEPROFEN;
}
else
{
value &= ~NVMC_ICACHECNF_CACHEPROFEN;
}

/* Setup the new icache configuration */

putreg32(value, NRF52_NVMC_ICACHECNF);
}

xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
/****************************************************************************
* Name: nrf_nvmc_get_profiling_ihit
*
Expand Down
32 changes: 0 additions & 32 deletions arch/arm/src/nrf52/nrf52_nvmc.h
Expand Up @@ -146,38 +146,6 @@ void nrf_nvmc_write_bytes(uint32_t address, const uint8_t *src,
void nrf_nvmc_write_words(uint32_t address, const uint32_t *src,
uint32_t num_words);

/****************************************************************************
* Name: nrf_nvmc_enable_icache
*
* Description:
* Enable I-Cache for Flash
*
* Input Parameter:
* flag - Flag to enable or disable.
*
* Returned Values:
* None
*
****************************************************************************/

void nrf_nvmc_enable_icache(bool flag);

/****************************************************************************
* Name: nrf_nvmc_enable_profile
*
* Description:
* Enable profiling I-Cache for flash
*
* Input Parameter:
* flag - Flag to enable or disable.
*
* Returned Values:
* None
*
****************************************************************************/

void nrf_nvmc_enable_profile(bool flag);

/****************************************************************************
* Name: nrf_nvmc_get_profiling_ihit
*
Expand Down
64 changes: 59 additions & 5 deletions arch/arm/src/nrf52/nrf52_start.c
Expand Up @@ -33,10 +33,9 @@
#include <arch/irq.h>

#include "arm_internal.h"
#include "nvic.h"

#include "nrf52_clockconfig.h"
#include "hardware/nrf52_nvmc.h"
#include "hardware/nrf52_utils.h"
#include "nrf52_clockconfig.h"
#include "nrf52_lowputc.h"
#include "nrf52_start.h"
#include "nrf52_gpio.h"
Expand Down Expand Up @@ -71,6 +70,61 @@
void __start(void) noinstrument_function;
#endif

#ifdef CONFIG_NRF52_FLASH_PREFETCH

/****************************************************************************
* Name: nrf52_enable_icache
*
* Description:
* Enable I-Cache for Flash
*
* Input Parameter:
* enable - enable or disable I-Cache
*
* Returned Values:
* None
*
****************************************************************************/

void nrf52_enable_icache(bool enable)
{
if (enable)
{
modifyreg32(NRF52_NVMC_ICACHECNF, 0, NVMC_ICACHECNF_CACHEEN);
}
else
{
modifyreg32(NRF52_NVMC_ICACHECNF, NVMC_ICACHECNF_CACHEEN, 0);
}
}

/****************************************************************************
* Name: nrf52_enable_profile
*
* Description:
* Enable profiling I-Cache for flash
*
* Input Parameter:
* enable - enable or disable profiling for I-Cache
*
* Returned Values:
* None
*
****************************************************************************/

void nrf52_enable_profile(bool enable)
{
if (enable)
{
modifyreg32(NRF52_NVMC_ICACHECNF, 0, NVMC_ICACHECNF_CACHEPROFEN);
}
else
{
modifyreg32(NRF52_NVMC_ICACHECNF, NVMC_ICACHECNF_CACHEPROFEN, 0);
}
}
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -145,8 +199,8 @@ void __start(void)
arm_fpuconfig();

#ifdef CONFIG_NRF52_FLASH_PREFETCH
nrf_nvmc_enable_icache(true);
nrf_nvmc_enable_profile(true);
nrf52_enable_icache(true);
nrf52_enable_profile(true);
#endif

showprogress('D');
Expand Down