Skip to content

Commit 1495a43

Browse files
authored
Merge pull request #699 from MarianSavchuk/switching_between_erase_modes
Switching between chip erase/sector erase
2 parents 7be99f5 + 91225d1 commit 1495a43

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-2
lines changed

docs/MSD_COMMANDS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ own right.
5050

5151
``msd_on.act`` Mass storage device can be enabled back by this file command on bootloader mode only if there is a target flash algo.
5252

53+
``page_off.act`` This file temporary enables page programming and chip erasing until the next restart occurred for drag and drop.
54+
55+
``page_on.act`` This file temporary enables page programming and sector erasing until the next restart occurred for drag and drop.
56+
5357
### Configuration Commands
5458

5559
``auto_rst.cfg`` This file will turn on Auto Reset mode. In this mode,

source/daplink/cmsis-dap/DAP_vendor.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
* Copyright (c) 2013-2016 ARM Limited. All rights reserved.
3+
* Copyright 2019, Cypress Semiconductor Corporation
4+
* or a subsidiary of Cypress Semiconductor Corporation.
35
*
46
* SPDX-License-Identifier: Apache-2.0
57
*
@@ -33,6 +35,7 @@
3335
#include "uart.h"
3436
#include "settings.h"
3537
#include "target_family.h"
38+
#include "flash_manager.h"
3639
#include <string.h>
3740

3841

@@ -158,7 +161,25 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) {
158161
break;
159162
}
160163
#endif
161-
case ID_DAP_Vendor13: break;
164+
case ID_DAP_Vendor13: {
165+
// switching between chip erase and page erase
166+
// COMMAND(OUT Packet)
167+
// BYTE 0 1000 1110 0x8D
168+
// BYTE 1 Desired Mode:
169+
// 0x00 - Chip Erase
170+
// nonzero - Page Erase
171+
// RESPONSE(IN Packet)
172+
// BYTE 0
173+
// 0x00 - OK
174+
*response = DAP_OK;
175+
if (0x00U == *request) {
176+
flash_manager_set_page_erase(false);
177+
} else {
178+
flash_manager_set_page_erase(true);
179+
}
180+
num += (1U << 16) | 1U; // increment request and response count each by 1
181+
break;
182+
}
162183
case ID_DAP_Vendor14: break;
163184
case ID_DAP_Vendor15: break;
164185
case ID_DAP_Vendor16: break;

source/daplink/drag-n-drop/flash_manager.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
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
@@ -22,6 +24,7 @@
2224
#include "flash_manager.h"
2325
#include "util.h"
2426
#include "error.h"
27+
#include "settings.h"
2528

2629
// Set to 1 to enable debugging
2730
#define DEBUG_FLASH_MANAGER 0
@@ -236,6 +239,7 @@ error_t flash_manager_uninit(void)
236239

237240
void flash_manager_set_page_erase(bool enabled)
238241
{
242+
config_ram_set_page_erase(enabled);
239243
page_erase_enabled = enabled;
240244
}
241245

source/daplink/drag-n-drop/vfs_user.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2020, 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
@@ -35,6 +37,7 @@
3537
#include "flash_intf.h" // for flash_intf_target
3638
#include "cortex_m.h"
3739
#include "target_board.h"
40+
#include "flash_manager.h"
3841

3942
//! @brief Size in bytes of the virtual disk.
4043
//!
@@ -63,6 +66,8 @@ typedef enum _magic_file {
6366
kOverflowOffConfigFile, //!< Disable UART overflow reporting.
6467
kMSDOnConfigFile, //!< Enable USB MSC. Uh....
6568
kMSDOffConfigFile, //!< Disable USB MSC.
69+
kPageEraseActionFile, //!< Enable page programming and sector erase for drag and drop.
70+
kChipEraseActionFile, //!< Enable page programming and chip erase for drag and drop.
6671
} magic_file_t;
6772

6873
//! @brief Mapping from filename string to magic file enum.
@@ -105,6 +110,8 @@ static const magic_file_info_t s_magic_file_info[] = {
105110
{ "OVFL_OFFCFG", kOverflowOffConfigFile },
106111
{ "MSD_ON CFG", kMSDOnConfigFile },
107112
{ "MSD_OFF CFG", kMSDOffConfigFile },
113+
{ "PAGE_ON ACT", kPageEraseActionFile },
114+
{ "PAGE_OFFACT", kChipEraseActionFile },
108115
};
109116

110117
static uint8_t file_buffer[VFS_SECTOR_SIZE];
@@ -261,6 +268,12 @@ void vfs_user_file_change_handler(const vfs_filename_t filename, vfs_file_change
261268
case kMSDOffConfigFile:
262269
config_ram_set_disable_msd(true);
263270
break;
271+
case kPageEraseActionFile:
272+
config_ram_set_page_erase(true);
273+
break;
274+
case kChipEraseActionFile:
275+
config_ram_set_page_erase(false);
276+
break;
264277
default:
265278
util_assert(false);
266279
}
@@ -479,6 +492,9 @@ static uint32_t update_details_txt_file(uint8_t *data, uint32_t datasize)
479492
pos += util_write_string(buf + pos, "Overflow detection: ");
480493
pos += util_write_string(buf + pos, config_get_overflow_detect() ? "1" : "0");
481494
pos += util_write_string(buf + pos, "\r\n");
495+
pos += util_write_string(buf + pos, "Page erasing: ");
496+
pos += util_write_string(buf + pos, config_ram_get_page_erase() ? "1" : "0");
497+
pos += util_write_string(buf + pos, "\r\n");
482498
// Current mode
483499
mode_str = daplink_is_bootloader() ? "Bootloader" : "Interface";
484500
pos += util_write_string(buf + pos, "Daplink Mode: ");

source/daplink/settings/settings.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2016, 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
@@ -57,7 +59,7 @@ typedef struct __attribute__((__packed__)) cfg_ram {
5759
uint8_t disable_msd;
5860

5961
//Add new entries from here
60-
62+
uint8_t page_erase_enable;
6163
} cfg_ram_t;
6264

6365
// Configuration RAM
@@ -93,6 +95,7 @@ void config_init()
9395
config_ram.valid_dumps = config_ram_copy.valid_dumps;
9496
memcpy(config_ram.hexdump, config_ram_copy.hexdump, sizeof(config_ram_copy.hexdump[0]) * config_ram_copy.valid_dumps);
9597
config_ram.disable_msd = config_ram_copy.disable_msd;
98+
config_ram.page_erase_enable = config_ram_copy.page_erase_enable;
9699
config_rom_init();
97100
}
98101

@@ -230,3 +233,12 @@ uint8_t config_ram_get_disable_msd(void)
230233
return config_ram.disable_msd;
231234
}
232235

236+
void config_ram_set_page_erase(bool page_erase_enable)
237+
{
238+
config_ram.page_erase_enable = page_erase_enable;
239+
}
240+
241+
bool config_ram_get_page_erase(void)
242+
{
243+
return config_ram.page_erase_enable;
244+
}

source/daplink/settings/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2016, 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
@@ -55,6 +57,8 @@ uint8_t config_ram_add_hexdump(uint32_t hexdump);
5557
uint8_t config_ram_get_hexdumps(uint32_t **hexdumps);
5658
void config_ram_set_disable_msd(bool disable_msd);
5759
uint8_t config_ram_get_disable_msd(void);
60+
void config_ram_set_page_erase(bool page_erase_enable);
61+
bool config_ram_get_page_erase(void);
5862

5963
// Private - should only be called from settings.c
6064
void config_rom_init(void);

0 commit comments

Comments
 (0)