mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 10:46:28 +08:00
Add XMC4 flash command sequence API
This commit is contained in:
@@ -23,8 +23,8 @@ include armv7-m/Make.defs
|
||||
# Required XMC4xxx files
|
||||
|
||||
CHIP_CSRCS = xmc4_allocateheap.c xmc4_clockconfig.c xmc4_clockutils.c
|
||||
CHIP_CSRCS += xmc4_clrpend.c xmc4_irq.c xmc4_lowputc.c xmc4_gpio.c
|
||||
CHIP_CSRCS += xmc4_serial.c xmc4_start.c xmc4_usic.c
|
||||
CHIP_CSRCS += xmc4_clrpend.c xmc4_flash.c xmc4_gpio.c xmc4_irq.c
|
||||
CHIP_CSRCS += xmc4_lowputc.c xmc4_serial.c xmc4_start.c xmc4_usic.c
|
||||
|
||||
# Configuration-dependent Kinetis files
|
||||
|
||||
|
||||
@@ -64,6 +64,42 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Flash memory address */
|
||||
|
||||
#define XMC4_FLASH_S0_OFFSET 0X000000
|
||||
#define XMC4_FLASH_S1_OFFSET 0X004000
|
||||
#define XMC4_FLASH_S2_OFFSET 0X008000
|
||||
#define XMC4_FLASH_S3_OFFSET 0X00c000
|
||||
#define XMC4_FLASH_S4_OFFSET 0X010000
|
||||
#define XMC4_FLASH_S5_OFFSET 0X014000
|
||||
#define XMC4_FLASH_S6_OFFSET 0X018000
|
||||
#define XMC4_FLASH_S7_OFFSET 0X01c000
|
||||
#define XMC4_FLASH_S8_OFFSET 0X020000
|
||||
#define XMC4_FLASH_S9_OFFSET 0X040000
|
||||
#define XMC4_FLASH_S10_OFFSET 0X080000
|
||||
#define XMC4_FLASH_S11_OFFSET 0X0c0000
|
||||
#define XMC4_FLASH_S12_OFFSET 0X100000
|
||||
#define XMC4_FLASH_S13_OFFSET 0X140000
|
||||
#define XMC4_FLASH_S14_OFFSET 0X180000
|
||||
#define XMC4_FLASH_S15_OFFSET 0X1c0000
|
||||
|
||||
#define XMC4_FLASH_S0 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S0_OFFSET)
|
||||
#define XMC4_FLASH_S1 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S1_OFFSET)
|
||||
#define XMC4_FLASH_S2 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S2_OFFSET)
|
||||
#define XMC4_FLASH_S3 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S3_OFFSET)
|
||||
#define XMC4_FLASH_S4 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S4_OFFSET)
|
||||
#define XMC4_FLASH_S5 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S5_OFFSET)
|
||||
#define XMC4_FLASH_S6 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S6_OFFSET)
|
||||
#define XMC4_FLASH_S7 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S7_OFFSET)
|
||||
#define XMC4_FLASH_S8 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S8_OFFSET)
|
||||
#define XMC4_FLASH_S9 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S9_OFFSET)
|
||||
#define XMC4_FLASH_S10 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S10_OFFSET)
|
||||
#define XMC4_FLASH_S11 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S11_OFFSET)
|
||||
#define XMC4_FLASH_S12 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S12_OFFSET)
|
||||
#define XMC4_FLASH_S13 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S13_OFFSET)
|
||||
#define XMC4_FLASH_S14 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S14_OFFSET)
|
||||
#define XMC4_FLASH_S15 (XMC4_UNCACHED_PFLASH_BASE + XMC4_FLASH_S15_OFFSET)
|
||||
|
||||
/* Register Offsets *********************************************************/
|
||||
|
||||
/* PMU Registers -- See ID register */
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
* USCI - Universal Serial Interface
|
||||
*/
|
||||
|
||||
#define XMC4_UNCACHED_PFLASH_BASE 0X0c000000 /* Uncached PMU/flash start address */
|
||||
#define XMC4_PBA0_BASE 0x40000000 /* PBA0 */
|
||||
#define XMC4_VADC_BASE 0x40004000 /* VADC */
|
||||
#define XMC4_VADC_G0_BASE 0x40004400
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/xmc4/xmc4_flash.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "xmc4_flash.h"
|
||||
|
||||
#include "arm_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_reset_to_read(void)
|
||||
{
|
||||
putreg32(0xf0, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
}
|
||||
|
||||
void xmc4_flash_enter_page_mode(void)
|
||||
{
|
||||
putreg32(0x50, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
}
|
||||
|
||||
void xmc4_flash_load_page(uint32_t low_word, uint32_t high_word)
|
||||
{
|
||||
putreg32(low_word, XMC4_UNCACHED_PFLASH_BASE + 0x55f0);
|
||||
putreg32(high_word, XMC4_UNCACHED_PFLASH_BASE + 0x55f4);
|
||||
}
|
||||
|
||||
void xmc4_flash_write_page(uint32_t page_start_address)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0xa0, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0xaa, page_start_address);
|
||||
}
|
||||
|
||||
void xmc4_flash_write_user_config_page(uint32_t page_start_address)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0xc0, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0xaa, page_start_address);
|
||||
}
|
||||
|
||||
void xmc4_flash_erase_sector(uint32_t sector_start_address)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x80, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x30, sector_start_address);
|
||||
}
|
||||
|
||||
void xmc4_flash_erase_physical_sector(uint32_t sector_start_address)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x80, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x40, sector_start_address);
|
||||
}
|
||||
|
||||
void xmc4_flash_repair_physical_sector(uint32_t sector_start_address)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x80, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x40, sector_start_address);
|
||||
}
|
||||
|
||||
void xmc4_flash_erase_user_config_block(uint32_t block_start_address)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x80, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0xc0, block_start_address);
|
||||
}
|
||||
|
||||
void xmc4_flash_disable_sector_write_protection(uint32_t user_level,
|
||||
uint32_t password_0,
|
||||
uint32_t password_1)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(user_level, XMC4_UNCACHED_PFLASH_BASE + 0x553c);
|
||||
putreg32(password_0, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(password_1, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x05, XMC4_UNCACHED_PFLASH_BASE + 0x5558);
|
||||
}
|
||||
|
||||
void xmc4_flash_disable_sector_read_protection(uint32_t password_0,
|
||||
uint32_t password_1)
|
||||
{
|
||||
putreg32(0xaa, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
putreg32(0x55, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x00, XMC4_UNCACHED_PFLASH_BASE + 0x553c);
|
||||
putreg32(password_0, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(password_1, XMC4_UNCACHED_PFLASH_BASE + 0xaaa8);
|
||||
putreg32(0x08, XMC4_UNCACHED_PFLASH_BASE + 0x5558);
|
||||
}
|
||||
|
||||
void xmc4_flash_resume_protection(void)
|
||||
{
|
||||
putreg32(0x5e, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
}
|
||||
|
||||
void xmc4_flash_clear_status(void)
|
||||
{
|
||||
putreg32(0xf5, XMC4_UNCACHED_PFLASH_BASE + 0x5554);
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/xmc4/xmc4_flash.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_ARM_SRC_XMC4_XMC4_FLASH_H
|
||||
#define __ARCH_ARM_SRC_XMC4_XMC4_FLASH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "hardware/xmc4_flash.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Flash Command Sequences API */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_reset_to_read
|
||||
*
|
||||
* Description: Reset command interpreter, abort page mode.
|
||||
* Clear error flags of FSR.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_reset_to_read(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_enter_page_mode
|
||||
*
|
||||
* Description: PFLASH enters page mode.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_enter_page_mode(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_load_page
|
||||
*
|
||||
* Description: Fill the page assembly buffer. Addressed bank must be in
|
||||
* page mode. In case of overflow, overflow data is discarded.
|
||||
* 32 Load Page operations are required to fill the assembly
|
||||
* buffer for one 256 byte page.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_load_page(uint32_t low_word, uint32_t high_word);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_write_page
|
||||
*
|
||||
* Description: Starts the programming process for one page with the data
|
||||
* transferred previously by Load Page commands.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_write_page(uint32_t page_start_address);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_write_user_config_page
|
||||
*
|
||||
* Description: Starts the programming process for one page with the data
|
||||
* transferred previously by Load Page commands.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_write_user_config_page(uint32_t page_start_address);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_erase_sector
|
||||
*
|
||||
* Description: Given sector is erased.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_erase_sector(uint32_t sector_start_address);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_erase_physical_sector
|
||||
*
|
||||
* Description: Given physical sector is erased. Depending on config of
|
||||
* PROCON1.PSR it repairs the sector.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_erase_physical_sector(uint32_t sector_start_address);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_repair_physical_sector
|
||||
*
|
||||
* Description: Given physical sector is repaired. Depending on config of
|
||||
* PROCON1.PSR it erases the sector.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_repair_physical_sector(uint32_t sector_start_address);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_erase_user_config_block
|
||||
*
|
||||
* Description: Given user configurable block is erased.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_erase_user_config_block(uint32_t block_start_address);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_disable_sector_write_protection
|
||||
*
|
||||
* Description: The sector write protection belonging to user level UL is
|
||||
* temporarily disabled by setting FSR.WPRODIS when the passwords
|
||||
* PW0 and PW1 match their configured values in the corresponding
|
||||
* UCB
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_disable_sector_write_protection(uint32_t user_level,
|
||||
uint32_t password_0,
|
||||
uint32_t password_1);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_disable_sector_read_protection
|
||||
*
|
||||
* Description: The Flash module read protection including the derived module
|
||||
* wide write protection are temporarily disabled by setting
|
||||
* FSR.RPRODIS when the passwords PW0 and PW1 match their
|
||||
* configured values in the UCB0.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_disable_sector_read_protection(uint32_t password_0,
|
||||
uint32_t password_1);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_resume_protection
|
||||
*
|
||||
* Description: This command clears all FSR.WPRODISx and the FSR.RPRODIS
|
||||
* effectively enabling again the Flash protection as it was
|
||||
* configured.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_resume_protection(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xmc4_flash_clear_status
|
||||
*
|
||||
* Description: The flags FSR.PROG and FSR.ERASE and the error flags of FSR
|
||||
* (PFOPER, SQER, PROER, PFDBER, ORIER, VER) are cleared.
|
||||
****************************************************************************/
|
||||
|
||||
void xmc4_flash_clear_status(void);
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_XMC4_XMC4_FLASH_H */
|
||||
Reference in New Issue
Block a user