Browse Source
Merge-conflict: took _prior_ verision of CCS_MUXSELR_MASK_PIN as bracketing of (pin) seemed more correct!pull/1274/head
Kevin Stefanik
5 years ago
committed by
Karl Palsson
5 changed files with 744 additions and 6 deletions
@ -0,0 +1,163 @@ |
|||
/**
|
|||
* @brief Memory Controller definitions for the Qorvo PAC55xx series of microcontrollers |
|||
* |
|||
* @addtogroup PAC55xx_memctl Memory Controller Defines |
|||
* @ingroup PAC55xx_defines |
|||
* @author Kevin Stefanik <kevin@allocor.tech> |
|||
* LGPL License Terms @ref lgpl_license |
|||
* @date 17 Mar 2020 |
|||
* |
|||
* Definitions in this file come from the PAC55XX Family User Guide Rev 1.23 |
|||
* by Active-Semi dated November 19, 2019. |
|||
*/ |
|||
/*
|
|||
* This file is part of the libopencm3 project. |
|||
* |
|||
* Copyright (C) 2020 Kevin Stefanik <kevin@allocor.tech> |
|||
* |
|||
* This library is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Lesser General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This library is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Lesser General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Lesser General Public License |
|||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
#ifndef LIBOPENCM3_PAC55XX_MEMCTL_H_ |
|||
#define LIBOPENCM3_PAC55XX_MEMCTL_H_ |
|||
|
|||
#include <libopencm3/cm3/common.h> |
|||
#include <libopencm3/pac55xx/memorymap.h> |
|||
/**@{*/ |
|||
|
|||
/** @defgroup memctl_reg Memory Controller Configuration Register
|
|||
@{*/ |
|||
/** Memory Controller Configuration Register */ |
|||
#define MEMCTL_MEMCTLR MMIO32(MEMCTL_BASE) |
|||
#define MEMCTL_MEMCTLR_WSTATE_MASK (0xF) |
|||
#define MEMCTL_MEMCTLR_WSTATE(ws) ((ws) & MEMCTL_MEMCTLR_WSTATE_MASK) |
|||
#define MEMCTL_MEMCTLR_MCLKDIV_MASK (0xF) |
|||
#define MEMCTL_MEMCTLR_MCLKDIV_SHIFT 4 |
|||
/* Supported MCLK divisors: 1-16 */ |
|||
#define MEMCTL_MEMCTLR_MCLKDIV(div) (((div-1) & MEMCTL_MEMCTLR_MCLKDIV_MASK) << MEMCTL_MEMCTLR_MCLKDIV_SHIFT) |
|||
#define MEMCTL_MEMCTLR_WRITEWORDCNT_MASK (0x3) |
|||
#define MEMCTL_MEMCTLR_WRITEWORDCNT_SHIFT 8 |
|||
#define MEMCTL_MEMCTLR_WRITEWORDCNT(cnt) (((cnt) & MEMCTL_MEMCTLR_WRITEWORDCNT_MASK) << MEMCTL_MEMCTLR_WRITEWORDCNT_SHIFT) |
|||
#define MEMCTL_MEMCTLR_SEIE BIT16 |
|||
#define MEMCTL_MEMCTLR_DEIE BIT17 |
|||
#define MEMCTL_MEMCTLR_INVADDRIE BIT18 |
|||
#define MEMCTL_MEMCTLR_STBY BIT19 |
|||
#define MEMCTL_MEMCTLR_ECCDIS BIT20 |
|||
#define MEMCTL_MEMCTLR_CACHEDIS BIT21 |
|||
#define MEMCTL_MEMCTLR_MCLKSEL BIT22 |
|||
/**@}*/ |
|||
|
|||
/** @defgroup memstatus_reg Memory Controller Status Register
|
|||
@{*/ |
|||
/** Memory Controller Status Register */ |
|||
#define MEMCTL_MEMSTATUS MMIO32(MEMCTL_BASE + 0x0004) |
|||
#define MEMCTL_MEMSTATUS_WBUSY BIT0 |
|||
#define MEMCTL_MEMSTATUS_EBUSY BIT1 |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT_MASK (0x3) |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT_SHIFT 8 |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT ((MEMCTL_MEMSTATUS >> MEMCTL_MEMSTATUS_WRITEWORDCNT_SHIFT) & MEMCTL_MEMSTATUS_WRITEWORDCNT_MASK) |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT_4BYTES (0) |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT_8BYTES (1) |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT_12BYTES (2) |
|||
#define MEMCTL_MEMSTATUS_WRITEWORDCNT_16BYTES (3) |
|||
#define MEMCTL_MEMSTATUS_SE BIT16 |
|||
#define MEMCTL_MEMSTATUS_DE BIT17 |
|||
#define MEMCTL_MEMSTATUS_INVADDR BIT18 |
|||
/**@}*/ |
|||
|
|||
/** @defgroup flashlock_vals Flash Lock/Write Enable Register values
|
|||
@{*/ |
|||
/** Flash Lock Access Register */ |
|||
#define MEMCTL_FLASHLOCK MMIO32(MEMCTL_BASE + 0x0008) |
|||
#define MEMCTL_FLASHLOCK_CLEAR (0) |
|||
#define MEMCTL_FLASHLOCK_ALLOW_FLASH_WRITE (0x43DF140A) |
|||
#define MEMCTL_FLASHLOCK_ALLOW_MEMCTL_WRITE (0xD513B490) |
|||
#define MEMCTL_FLASHLOCK_ALLOW_INFO2_SWDFUSE (0x79B4F762) |
|||
/**@}*/ |
|||
|
|||
/** Flash Page Address Register */ |
|||
#define MEMCTL_FLASHPAGE MMIO32(MEMCTL_BASE + 0x000C) |
|||
/** SWD Unlock Register */ |
|||
#define MEMCTL_SWDUNLOCK MMIO32(MEMCTL_BASE + 0x0010) |
|||
|
|||
/** @defgroup flasherase_vals Flash Erase Enable Register values
|
|||
@{*/ |
|||
/** Flash Erase Enable Register */ |
|||
#define MEMCTL_FLASHERASE MMIO32(MEMCTL_BASE + 0x0020) |
|||
#define MEMCTL_FLASHERASE_PAGE_ERASE (0x8C799CA7) |
|||
#define MEMCTL_FLASHERASE_MASS_PAGE_ERASE (0x09EE76C9) |
|||
#define MEMCTL_FLASHERASE_INFO3_ERASE (0x1266FF45) |
|||
/**@}*/ |
|||
|
|||
/**@}*/ |
|||
|
|||
BEGIN_DECLS |
|||
|
|||
/**
|
|||
* @defgroup memctl_api Memory Controller API |
|||
* @ingroup peripheral_apis |
|||
* @brief <b>PAC5xx MEMCTL Driver</b> |
|||
* @author @htmlonly © @endhtmlonly 2020 Kevin Stefanik <kevin@allocor.tech> |
|||
* @date March 7, 2020 |
|||
* |
|||
* This library supports the MEMCTL module in the PAC55xx SoC from Qorvo. |
|||
* |
|||
* LGPL License Terms @ref lgpl_license |
|||
*/ |
|||
|
|||
/*@{*/ |
|||
|
|||
/** Set the number of wait states for Flash reads.
|
|||
* @param[in] wstate Wait states: 0-15 |
|||
*/ |
|||
void memctl_flash_set_wstate(uint32_t wstate); |
|||
/** Set the MCLK divisor.
|
|||
* @param[in] div HCLK to MCLK divisor: 1-16 |
|||
*/ |
|||
void memctl_flash_set_mclkdiv(uint32_t div); |
|||
/** Set WRITEWORDCOUNT to 0 to reset the Flash write data buffer */ |
|||
void memctl_flash_reset_write_buffer(void); |
|||
/** Enable Flash Standby Mode */ |
|||
void memctl_flash_standby_mode_enable(void); |
|||
/** Disable Flash Standby Mode */ |
|||
void memctl_flash_standby_mode_disable(void); |
|||
/** Enable Flash cache */ |
|||
void memctl_flash_cache_enable(void); |
|||
/** Disable Flash cache */ |
|||
void memctl_flash_cache_disable(void); |
|||
/** Select ROSCCLK as input to Flash Memory Controller */ |
|||
void memctl_flash_select_roscclk(void); |
|||
/** Select MCLK as input to Flash Memory Controller */ |
|||
void memctl_flash_select_mclk(void); |
|||
/** Enable SRAM ECC */ |
|||
void memctl_sram_ecc_enable(void); |
|||
/** Disable SRAM ECC */ |
|||
void memctl_sram_ecc_disable(void); |
|||
/** Enable SRAM ECC Single Bit Detection Interrupt */ |
|||
void memctl_sram_ecc_single_bit_interrupt_enable(void); |
|||
/** Disable SRAM ECC Single Bit Detection Interrupt */ |
|||
void memctl_sram_ecc_single_bit_interrupt_disable(void); |
|||
/** Enable SRAM ECC Dual Bit Detection Interrupt */ |
|||
void memctl_sram_ecc_dual_bit_interrupt_enable(void); |
|||
/** Disable SRAM ECC Dual Bit Detection Interrupt */ |
|||
void memctl_sram_ecc_dual_bit_interrupt_disable(void); |
|||
/** Enable Invalid Memory Access Interrupt */ |
|||
void memctl_invaddr_interrupt_enable(void); |
|||
/** Disable Invalid Memory Access Interrupt */ |
|||
void memctl_invaddr_interrupt_disable(void); |
|||
|
|||
/**@}*/ |
|||
|
|||
END_DECLS |
|||
|
|||
#endif /* LIBOPENCM3_PAC55XX_MEMCTL_H_ */ |
@ -0,0 +1,261 @@ |
|||
/**
|
|||
* @brief <b>PAC55xxxx CCS Driver</b> |
|||
* @author @htmlonly © @endhtmlonly 2020 Kevin Stefanik <kevin@allocor.tech> |
|||
* @date March 7, 2020 |
|||
* |
|||
* This library supports the CCS module in the PAC55xx SoC from Qorvo. |
|||
* |
|||
* LGPL License Terms @ref lgpl_license |
|||
*/ |
|||
/*
|
|||
* This file is part of the libopencm3 project. |
|||
* |
|||
* This library is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Lesser General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This library is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Lesser General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Lesser General Public License |
|||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
#include <libopencm3/pac55xx/ccs.h> |
|||
#include <libopencm3/pac55xx/memorymap.h> |
|||
#include <libopencm3/pac55xx/memctl.h> |
|||
#include <libopencm3/cm3/assert.h> |
|||
|
|||
static volatile uint32_t ccs_extclk_frequency = 0; |
|||
static volatile uint32_t ccs_frclk_frequency = CCS_ROSC_FREQ; |
|||
static volatile uint32_t ccs_sclk_frequency = CCS_ROSC_FREQ; |
|||
static volatile uint32_t ccs_pll_clk_frequency = 0; |
|||
static volatile uint32_t ccs_hclk_frequency = CCS_ROSC_FREQ; |
|||
static volatile uint32_t ccs_aclk_frequency = CCS_ROSC_FREQ; |
|||
static volatile uint32_t ccs_pclk_frequency = CCS_ROSC_FREQ; |
|||
|
|||
void ccs_frclkmux_select(uint32_t sel) { |
|||
CCSCTL = (CCSCTL & ~CCS_CTL_FRCLKMUXSEL(CCS_CTL_FRCLKMUXSEL_MASK)) | CCS_CTL_FRCLKMUXSEL(sel); |
|||
} |
|||
void ccs_rosc_enable(void) { |
|||
CCSCTL |= CCS_CTL_ROSCEN; |
|||
} |
|||
void ccs_rosc_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_ROSCEN; |
|||
} |
|||
void ccs_sclkmux_select_frclk(void) { |
|||
CCSCTL &= ~CCS_CTL_SCLKMUXSEL; |
|||
} |
|||
void ccs_sclkmux_select_pllclk(void) { |
|||
CCSCTL |= CCS_CTL_SCLKMUXSEL; |
|||
} |
|||
void ccs_clkfail_enable(void) { |
|||
CCSCTL |= CCS_CTL_CLKFAILEN; |
|||
} |
|||
void ccs_clkfail_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_CLKFAILEN; |
|||
} |
|||
void ccs_clkfailmux_select_frclk(void) { |
|||
CCSCTL &= ~CCS_CTL_CLKFAILMUXSEL; |
|||
} |
|||
void ccs_clkfailmux_select_pllclk(void) { |
|||
CCSCTL |= CCS_CTL_CLKFAILMUXSEL; |
|||
} |
|||
void ccs_ldo_enable(void) { |
|||
CCSCTL |= CCS_CTL_LDOEN; |
|||
} |
|||
void ccs_ldo_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_LDOEN; |
|||
} |
|||
void ccs_pclk_enable(void) { |
|||
CCSCTL |= CCS_CTL_PCLKEN; |
|||
} |
|||
void ccs_pclk_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_PCLKEN; |
|||
} |
|||
void ccs_aclk_enable(void) { |
|||
CCSCTL |= CCS_CTL_ACLKEN; |
|||
} |
|||
void ccs_aclk_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_ACLKEN; |
|||
} |
|||
void ccs_adcclk_enable(void) { |
|||
CCSCTL |= CCS_CTL_ADCCLKEN; |
|||
} |
|||
void ccs_adcclk_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_ADCCLKEN; |
|||
} |
|||
void ccs_stclk_sleep_enable(void) { |
|||
CCSCTL |= CCS_CTL_STCLKSLPEN; |
|||
} |
|||
void ccs_stclk_sleep_disable(void) { |
|||
CCSCTL &= ~CCS_CTL_STCLKSLPEN; |
|||
} |
|||
void ccs_set_pclkdiv(uint32_t div) { |
|||
CCSCTL = (CCSCTL & ~CCS_CTL_PCLKDIV(8)) | CCS_CTL_PCLKDIV(div); |
|||
} |
|||
void ccs_set_aclkdiv(uint32_t div) { |
|||
CCSCTL = (CCSCTL & ~CCS_CTL_ACLKDIV(8)) | CCS_CTL_ACLKDIV(div); |
|||
} |
|||
void ccs_set_hclkdiv(uint32_t div) { |
|||
CCSCTL = (CCSCTL & ~CCS_CTL_HCLKDIV(8)) | CCS_CTL_HCLKDIV(div); |
|||
} |
|||
void ccs_pll_enable(void) { |
|||
CCSPLLCTL |= CCS_PLLCTL_PLLEN; |
|||
} |
|||
void ccs_pll_disable(void) { |
|||
CCSPLLCTL &= ~CCS_PLLCTL_PLLEN; |
|||
} |
|||
bool ccs_pll_locked(void) { |
|||
return (CCSPLLCTL & CCS_PLLCTL_PLLLOCK) == CCS_PLLCTL_PLLLOCK; |
|||
} |
|||
void ccs_pll_bypass_enable(void) { |
|||
CCSPLLCTL |= CCS_PLLCTL_PLLBP; |
|||
} |
|||
void ccs_pll_bypass_disable(void) { |
|||
CCSPLLCTL &= ~CCS_PLLCTL_PLLBP; |
|||
} |
|||
void ccs_pll_set_outdiv(uint32_t div) { |
|||
CCSPLLCTL = (CCSPLLCTL & ~CCS_PLLCTL_PLLOUTDIV(CCS_PLLCTL_PLLOUTDIV_MASK)) | CCS_PLLCTL_PLLOUTDIV(div); |
|||
} |
|||
void ccs_pll_set_indiv(uint32_t div) { |
|||
if (div <= 15 && div >= 1) { |
|||
CCSPLLCTL = (CCSPLLCTL & ~CCS_PLLCTL_PLLINDIV(CCS_PLLCTL_PLLINDIV_MASK)) | CCS_PLLCTL_PLLINDIV(div); |
|||
} else { |
|||
cm3_assert_not_reached(); |
|||
} |
|||
} |
|||
void ccs_pll_set_fbdiv(uint32_t div) { |
|||
if (div <= 16383 && div >= 4) { |
|||
CCSPLLCTL = (CCSPLLCTL & ~CCS_PLLCTL_PLLFBDIV(CCS_PLLCTL_PLLFBDIV_MASK)) | CCS_PLLCTL_PLLFBDIV(div); |
|||
} else { |
|||
cm3_assert_not_reached(); |
|||
} |
|||
} |
|||
void css_pll_config_enable(uint32_t indiv, uint32_t fbdiv, uint32_t outdiv) { |
|||
ccs_pll_disable(); |
|||
ccs_pll_set_fbdiv(fbdiv); |
|||
ccs_pll_set_outdiv(outdiv); |
|||
ccs_pll_set_indiv(indiv); |
|||
ccs_pll_enable(); |
|||
while (!ccs_pll_locked()) ; /* Wait for PLL lock ~500us */ |
|||
} |
|||
uint32_t ccs_get_peripheral_clk_freq(uint32_t periph, uint32_t select) { |
|||
switch (periph) { |
|||
case ADC_BASE: |
|||
return ccs_sclk_frequency; |
|||
case I2C_BASE: /* fall through */ |
|||
case USARTA_BASE: /* fall through */ |
|||
case USARTB_BASE: /* fall through */ |
|||
case USARTC_BASE: /* fall through */ |
|||
case USARTD_BASE: /* fall through */ |
|||
case CAN_BASE: /* fall through */ |
|||
case GPTIMERA_BASE: /* fall through */ |
|||
case GPTIMERB_BASE: |
|||
return ccs_pclk_frequency; |
|||
case TIMERA_BASE: /* fall through */ |
|||
case TIMERB_BASE: /* fall through */ |
|||
case TIMERC_BASE: /* fall through */ |
|||
case TIMERD_BASE: |
|||
return (select == 0) ? ccs_pclk_frequency : ccs_aclk_frequency; |
|||
case MEMCTL_BASE: |
|||
return (select == 0) ? CCS_ROSC_FREQ : ccs_hclk_frequency; |
|||
case WWDT_BASE: |
|||
return (select == 0) ? ccs_frclk_frequency : CCS_ROSC_FREQ; |
|||
case RTC_BASE: |
|||
return ccs_frclk_frequency; |
|||
case CRC_BASE: /* fall through */ |
|||
case SYS_TICK_BASE: |
|||
return ccs_hclk_frequency; |
|||
default: |
|||
cm3_assert_not_reached(); |
|||
} |
|||
} |
|||
|
|||
void ccs_reset_clocks(void) { |
|||
CCSCTL = CCS_CTL_LDOEN | CCS_CTL_ROSCEN | |
|||
CCS_CTL_PCLKEN | CCS_CTL_ACLKEN | |
|||
CCS_CTL_ADCCLKEN | CCS_CTL_STCLKSLPEN; |
|||
CCSPLLCTL = 0; |
|||
} |
|||
|
|||
void ccs_configure_clocks(const struct ccs_clk_config *config) { |
|||
MEMCTL_FLASHLOCK = MEMCTL_FLASHLOCK_ALLOW_MEMCTL_WRITE; |
|||
|
|||
ccs_reset_clocks(); /* set safe defaults */ |
|||
ccs_frclkmux_select(CCS_CTL_FRCLKMUXSEL_ROSC); |
|||
ccs_sclkmux_select_frclk(); |
|||
memctl_flash_select_roscclk(); |
|||
|
|||
if (config->mem_enable_cache) { |
|||
memctl_flash_cache_enable(); |
|||
} else { |
|||
memctl_flash_cache_disable(); |
|||
} |
|||
|
|||
ccs_frclkmux_select(CCS_CTL_FRCLKMUXSEL_CLKREF); /* switch frclk to 4MHz CLKREF */ |
|||
|
|||
switch (config->frclk_source) { |
|||
case CCS_CTL_FRCLKMUXSEL_ROSC: |
|||
ccs_frclkmux_select(CCS_CTL_FRCLKMUXSEL_ROSC); |
|||
ccs_frclk_frequency = CCS_ROSC_FREQ; |
|||
break; |
|||
case CCS_CTL_FRCLKMUXSEL_CLKREF: |
|||
ccs_frclkmux_select(CCS_CTL_FRCLKMUXSEL_CLKREF); |
|||
ccs_frclk_frequency = CCS_CLKREF_FREQ; |
|||
break; |
|||
case CCS_CTL_FRCLKMUXSEL_EXTCLK: |
|||
if (config->extclk_frequency > CCS_EXTCLK_MAX_FREQ |
|||
|| config->extclk_frequency == 0) { |
|||
cm3_assert_not_reached(); |
|||
} |
|||
ccs_frclkmux_select(CCS_CTL_FRCLKMUXSEL_EXTCLK); |
|||
ccs_frclk_frequency = ccs_extclk_frequency = config->extclk_frequency; |
|||
break; |
|||
default: |
|||
cm3_assert_not_reached(); |
|||
} |
|||
|
|||
if (config->sclk_source == CCS_CTL_SCLKMUXSEL_FRCLK) { |
|||
ccs_set_hclkdiv(config->hclkdiv); |
|||
ccs_set_aclkdiv(config->aclkdiv); |
|||
memctl_flash_set_wstate(config->mem_wstate); |
|||
ccs_sclkmux_select_frclk(); |
|||
memctl_flash_set_mclkdiv(config->mem_mclkdiv); |
|||
if (config->mem_mclksel == false) { |
|||
memctl_flash_select_roscclk(); |
|||
} else { |
|||
memctl_flash_select_mclk(); |
|||
} |
|||
ccs_sclk_frequency = ccs_frclk_frequency; |
|||
} else if (config->sclk_source == CCS_CTL_SCLKMUXSEL_PLLCLK) { |
|||
css_pll_config_enable(config->pll_indiv, config->pll_fbdiv, config->pll_outdiv); |
|||
ccs_set_hclkdiv(config->hclkdiv); |
|||
ccs_set_aclkdiv(config->aclkdiv); |
|||
memctl_flash_set_wstate(config->mem_wstate); |
|||
ccs_sclkmux_select_pllclk(); |
|||
memctl_flash_set_mclkdiv(config->mem_mclkdiv); |
|||
if (config->mem_mclksel == false) { |
|||
memctl_flash_select_roscclk(); |
|||
} else { |
|||
memctl_flash_select_mclk(); |
|||
} |
|||
ccs_pll_clk_frequency = ((ccs_frclk_frequency * config->pll_fbdiv) / config->pll_indiv) >> config->pll_outdiv; |
|||
ccs_sclk_frequency = ccs_pll_clk_frequency; |
|||
} else { |
|||
cm3_assert_not_reached(); |
|||
} |
|||
ccs_set_pclkdiv(config->pclkdiv); |
|||
ccs_pclk_enable(); |
|||
ccs_aclk_enable(); |
|||
ccs_adcclk_enable(); |
|||
ccs_stclk_sleep_disable(); |
|||
|
|||
ccs_hclk_frequency = ccs_sclk_frequency / config->hclkdiv; |
|||
ccs_aclk_frequency = ccs_sclk_frequency / config->aclkdiv; |
|||
ccs_pclk_frequency = ccs_hclk_frequency / config->pclkdiv; |
|||
|
|||
MEMCTL_FLASHLOCK = MEMCTL_FLASHLOCK_CLEAR; |
|||
} |
@ -0,0 +1,78 @@ |
|||
/**
|
|||
* @brief <b>PAC55xxxx Memory Controller Driver</b> |
|||
* @author @htmlonly © @endhtmlonly 2020 Kevin Stefanik <kevin@allocor.tech> |
|||
* @date April 1, 2020 |
|||
* |
|||
* This library supports the Memory Controller in the PAC55xx SoC from Qorvo. |
|||
* |
|||
* LGPL License Terms @ref lgpl_license |
|||
*/ |
|||
/*
|
|||
* This file is part of the libopencm3 project. |
|||
* |
|||
* This library is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Lesser General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This library is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Lesser General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Lesser General Public License |
|||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
#include <libopencm3/pac55xx/memctl.h> |
|||
|
|||
void memctl_flash_set_wstate(uint32_t wstate) { |
|||
MEMCTL_MEMCTLR = (MEMCTL_MEMCTLR & ~MEMCTL_MEMCTLR_WSTATE(MEMCTL_MEMCTLR_WSTATE_MASK)) | MEMCTL_MEMCTLR_WSTATE(wstate); |
|||
} |
|||
void memctl_flash_set_mclkdiv(uint32_t div) { |
|||
MEMCTL_MEMCTLR = (MEMCTL_MEMCTLR & ~MEMCTL_MEMCTLR_MCLKDIV(16)) | MEMCTL_MEMCTLR_MCLKDIV(div); |
|||
} |
|||
void memctl_flash_reset_write_buffer(void) { |
|||
MEMCTL_MEMCTLR = (MEMCTL_MEMCTLR & ~MEMCTL_MEMCTLR_WRITEWORDCNT(MEMCTL_MEMCTLR_WRITEWORDCNT_MASK)); |
|||
} |
|||
void memctl_flash_standby_mode_enable(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_STBY; |
|||
} |
|||
void memctl_flash_standby_mode_disable(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_STBY; |
|||
} |
|||
void memctl_flash_cache_enable(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_CACHEDIS; |
|||
} |
|||
void memctl_flash_cache_disable(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_CACHEDIS; |
|||
} |
|||
void memctl_flash_select_roscclk(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_MCLKSEL; |
|||
} |
|||
void memctl_flash_select_mclk(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_MCLKSEL; |
|||
} |
|||
void memctl_sram_ecc_enable(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_ECCDIS; |
|||
} |
|||
void memctl_sram_ecc_disable(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_ECCDIS; |
|||
} |
|||
void memctl_sram_ecc_single_bit_interrupt_enable(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_SEIE; |
|||
} |
|||
void memctl_sram_ecc_single_bit_interrupt_disable(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_SEIE; |
|||
} |
|||
void memctl_sram_ecc_dual_bit_interrupt_enable(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_DEIE; |
|||
} |
|||
void memctl_sram_ecc_dual_bit_interrupt_disable(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_DEIE; |
|||
} |
|||
void memctl_invaddr_interrupt_enable(void) { |
|||
MEMCTL_MEMCTLR |= MEMCTL_MEMCTLR_INVADDRIE; |
|||
} |
|||
void memctl_invaddr_interrupt_disable(void) { |
|||
MEMCTL_MEMCTLR &= ~MEMCTL_MEMCTLR_INVADDRIE; |
|||
} |
Loading…
Reference in new issue