44 *
55 * DAPLink Interface Firmware
66 * Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+ * Copyright 2019, Cypress Semiconductor Corporation
8+ * or a subsidiary of Cypress Semiconductor Corporation.
79 * SPDX-License-Identifier: Apache-2.0
810 *
911 * Licensed under the Apache License, Version 2.0 (the "License"); you may
3234#include "target_family.h"
3335#include "target_board.h"
3436
37+ #define DEFAULT_PROGRAM_PAGE_MIN_SIZE (256u)
38+
3539typedef enum {
3640 STATE_CLOSED ,
3741 STATE_OPEN ,
@@ -107,13 +111,15 @@ static error_t flash_func_start(flash_func_t func)
107111 {
108112 // Finish the currently active function.
109113 if (FLASH_FUNC_NOP != last_flash_func &&
110- 0 == swd_flash_syscall_exec (& flash -> sys_call_s , flash -> uninit , last_flash_func , 0 , 0 , 0 )) {
114+ ((flash -> algo_flags & kAlgoSingleInitType ) == 0 || FLASH_FUNC_NOP == func ) &&
115+ 0 == swd_flash_syscall_exec (& flash -> sys_call_s , flash -> uninit , last_flash_func , 0 , 0 , 0 , FLASHALGO_RETURN_BOOL )) {
111116 return ERROR_UNINIT ;
112117 }
113118
114119 // Start a new function.
115120 if (FLASH_FUNC_NOP != func &&
116- 0 == swd_flash_syscall_exec (& flash -> sys_call_s , flash -> init , flash_start , 0 , func , 0 )) {
121+ ((flash -> algo_flags & kAlgoSingleInitType ) == 0 || FLASH_FUNC_NOP == last_flash_func ) &&
122+ 0 == swd_flash_syscall_exec (& flash -> sys_call_s , flash -> init , flash_start , 0 , func , 0 , FLASHALGO_RETURN_BOOL )) {
117123 return ERROR_INIT ;
118124 }
119125
@@ -237,7 +243,8 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
237243 addr ,
238244 write_size ,
239245 flash -> program_buffer ,
240- 0 )) {
246+ 0 ,
247+ FLASHALGO_RETURN_BOOL )) {
241248 return ERROR_WRITE ;
242249 }
243250
@@ -248,12 +255,19 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
248255 if (status != ERROR_SUCCESS ) {
249256 return status ;
250257 }
258+ flash_algo_return_t return_type ;
259+ if ((flash -> algo_flags & kAlgoVerifyReturnsAddress ) != 0 ) {
260+ return_type = FLASHALGO_RETURN_POINTER ;
261+ } else {
262+ return_type = FLASHALGO_RETURN_BOOL ;
263+ }
251264 if (!swd_flash_syscall_exec (& flash -> sys_call_s ,
252265 flash -> verify ,
253266 addr ,
254267 write_size ,
255268 flash -> program_buffer ,
256- 0 )) {
269+ 0 ,
270+ return_type )) {
257271 return ERROR_WRITE_VERIFY ;
258272 }
259273 } else {
@@ -308,7 +322,7 @@ static error_t target_flash_erase_sector(uint32_t addr)
308322 return status ;
309323 }
310324
311- if (0 == swd_flash_syscall_exec (& flash -> sys_call_s , flash -> erase_sector , addr , 0 , 0 , 0 )) {
325+ if (0 == swd_flash_syscall_exec (& flash -> sys_call_s , flash -> erase_sector , addr , 0 , 0 , 0 , FLASHALGO_RETURN_BOOL )) {
312326 return ERROR_ERASE_SECTOR ;
313327 }
314328
@@ -325,6 +339,11 @@ static error_t target_flash_erase_chip(void)
325339 region_info_t * flash_region = g_board_info .target_cfg -> flash_regions ;
326340
327341 for (; flash_region -> start != 0 || flash_region -> end != 0 ; ++ flash_region ) {
342+ program_target_t * new_flash_algo = get_flash_algo (flash_region -> start );
343+ if ((new_flash_algo != NULL ) && ((new_flash_algo -> algo_flags & kAlgoSkipChipErase ) != 0 )) {
344+ // skip flash region
345+ continue ;
346+ }
328347 status = target_flash_set (flash_region -> start );
329348 if (status != ERROR_SUCCESS ) {
330349 return status ;
@@ -333,7 +352,7 @@ static error_t target_flash_erase_chip(void)
333352 if (status != ERROR_SUCCESS ) {
334353 return status ;
335354 }
336- if (0 == swd_flash_syscall_exec (& current_flash_algo -> sys_call_s , current_flash_algo -> erase_chip , 0 , 0 , 0 , 0 )) {
355+ if (0 == swd_flash_syscall_exec (& current_flash_algo -> sys_call_s , current_flash_algo -> erase_chip , 0 , 0 , 0 , 0 , FLASHALGO_RETURN_BOOL )) {
337356 return ERROR_ERASE_ALL ;
338357 }
339358 }
@@ -352,7 +371,7 @@ static error_t target_flash_erase_chip(void)
352371static uint32_t target_flash_program_page_min_size (uint32_t addr )
353372{
354373 if (g_board_info .target_cfg ){
355- uint32_t size = 256 ;
374+ uint32_t size = DEFAULT_PROGRAM_PAGE_MIN_SIZE ;
356375 if (size > target_flash_erase_sector_size (addr )) {
357376 size = target_flash_erase_sector_size (addr );
358377 }
0 commit comments