Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers flash.c Source File

flash.c

00001 /**
00002  * @file    flash.c
00003  * @brief
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include "flash_hal.h"        // FlashOS Structures
00023 #include "target_config.h"    // target_device
00024 #include "util.h"
00025 #include "string.h"
00026 #include "target_board.h"
00027 #include "NuMicro.h"
00028 
00029 uint32_t Init(uint32_t adr, uint32_t clk, uint32_t fnc)
00030 {
00031     SYS_UnlockReg();
00032     /* Enable FMC ISP function */
00033     FMC_Open();
00034     FMC_ENABLE_AP_UPDATE();
00035     return 0;
00036 }
00037 
00038 uint32_t UnInit(uint32_t fnc)
00039 {
00040     FMC_DISABLE_AP_UPDATE();
00041     /* Disable FMC ISP function */
00042     FMC_Close();
00043     SYS_LockReg();
00044     return 0;
00045 }
00046 
00047 uint32_t EraseChip(void)
00048 {
00049     return 1;
00050 }
00051 
00052 uint32_t EraseSector(uint32_t adr)
00053 {
00054     uint32_t ret = 0;
00055 
00056     if (FMC_Erase(adr) != 0) {
00057         ret = 1;
00058     }
00059 
00060     return ret;
00061 }
00062 
00063 uint32_t ProgramPage(uint32_t adr, uint32_t sz, uint32_t *buf)
00064 {
00065     uint32_t i;
00066     uint32_t ret = 0;
00067 
00068     for (i = 0; i < sz; i += 4) {
00069         FMC_Write(adr + i, buf[i / 4]);
00070 
00071         if (FMC_GET_FAIL_FLAG()) {
00072             FMC_CLR_FAIL_FLAG();
00073             ret = 1;
00074             break;
00075         }
00076     }
00077 
00078     return ret;
00079 }