Skip to content

Commit

Permalink
Merge pull request #699 from MarianSavchuk/switching_between_erase_modes
Browse files Browse the repository at this point in the history
Switching between chip erase/sector erase
  • Loading branch information
0xc0170 authored Mar 26, 2020
2 parents 7be99f5 + 91225d1 commit 1495a43
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/MSD_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ own right.

``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.

``page_off.act`` This file temporary enables page programming and chip erasing until the next restart occurred for drag and drop.

``page_on.act`` This file temporary enables page programming and sector erasing until the next restart occurred for drag and drop.

### Configuration Commands

``auto_rst.cfg`` This file will turn on Auto Reset mode. In this mode,
Expand Down
23 changes: 22 additions & 1 deletion source/daplink/cmsis-dap/DAP_vendor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright (c) 2013-2016 ARM Limited. All rights reserved.
* Copyright 2019, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -33,6 +35,7 @@
#include "uart.h"
#include "settings.h"
#include "target_family.h"
#include "flash_manager.h"
#include <string.h>


Expand Down Expand Up @@ -158,7 +161,25 @@ uint32_t DAP_ProcessVendorCommand(const uint8_t *request, uint8_t *response) {
break;
}
#endif
case ID_DAP_Vendor13: break;
case ID_DAP_Vendor13: {
// switching between chip erase and page erase
// COMMAND(OUT Packet)
// BYTE 0 1000 1110 0x8D
// BYTE 1 Desired Mode:
// 0x00 - Chip Erase
// nonzero - Page Erase
// RESPONSE(IN Packet)
// BYTE 0
// 0x00 - OK
*response = DAP_OK;
if (0x00U == *request) {
flash_manager_set_page_erase(false);
} else {
flash_manager_set_page_erase(true);
}
num += (1U << 16) | 1U; // increment request and response count each by 1
break;
}
case ID_DAP_Vendor14: break;
case ID_DAP_Vendor15: break;
case ID_DAP_Vendor16: break;
Expand Down
4 changes: 4 additions & 0 deletions source/daplink/drag-n-drop/flash_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
* Copyright 2019, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -22,6 +24,7 @@
#include "flash_manager.h"
#include "util.h"
#include "error.h"
#include "settings.h"

// Set to 1 to enable debugging
#define DEBUG_FLASH_MANAGER 0
Expand Down Expand Up @@ -236,6 +239,7 @@ error_t flash_manager_uninit(void)

void flash_manager_set_page_erase(bool enabled)
{
config_ram_set_page_erase(enabled);
page_erase_enabled = enabled;
}

Expand Down
16 changes: 16 additions & 0 deletions source/daplink/drag-n-drop/vfs_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2020, ARM Limited, All Rights Reserved
* Copyright 2019, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -35,6 +37,7 @@
#include "flash_intf.h" // for flash_intf_target
#include "cortex_m.h"
#include "target_board.h"
#include "flash_manager.h"

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

//! @brief Mapping from filename string to magic file enum.
Expand Down Expand Up @@ -105,6 +110,8 @@ static const magic_file_info_t s_magic_file_info[] = {
{ "OVFL_OFFCFG", kOverflowOffConfigFile },
{ "MSD_ON CFG", kMSDOnConfigFile },
{ "MSD_OFF CFG", kMSDOffConfigFile },
{ "PAGE_ON ACT", kPageEraseActionFile },
{ "PAGE_OFFACT", kChipEraseActionFile },
};

static uint8_t file_buffer[VFS_SECTOR_SIZE];
Expand Down Expand Up @@ -261,6 +268,12 @@ void vfs_user_file_change_handler(const vfs_filename_t filename, vfs_file_change
case kMSDOffConfigFile:
config_ram_set_disable_msd(true);
break;
case kPageEraseActionFile:
config_ram_set_page_erase(true);
break;
case kChipEraseActionFile:
config_ram_set_page_erase(false);
break;
default:
util_assert(false);
}
Expand Down Expand Up @@ -479,6 +492,9 @@ static uint32_t update_details_txt_file(uint8_t *data, uint32_t datasize)
pos += util_write_string(buf + pos, "Overflow detection: ");
pos += util_write_string(buf + pos, config_get_overflow_detect() ? "1" : "0");
pos += util_write_string(buf + pos, "\r\n");
pos += util_write_string(buf + pos, "Page erasing: ");
pos += util_write_string(buf + pos, config_ram_get_page_erase() ? "1" : "0");
pos += util_write_string(buf + pos, "\r\n");
// Current mode
mode_str = daplink_is_bootloader() ? "Bootloader" : "Interface";
pos += util_write_string(buf + pos, "Daplink Mode: ");
Expand Down
14 changes: 13 additions & 1 deletion source/daplink/settings/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright 2019, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -57,7 +59,7 @@ typedef struct __attribute__((__packed__)) cfg_ram {
uint8_t disable_msd;

//Add new entries from here

uint8_t page_erase_enable;
} cfg_ram_t;

// Configuration RAM
Expand Down Expand Up @@ -93,6 +95,7 @@ void config_init()
config_ram.valid_dumps = config_ram_copy.valid_dumps;
memcpy(config_ram.hexdump, config_ram_copy.hexdump, sizeof(config_ram_copy.hexdump[0]) * config_ram_copy.valid_dumps);
config_ram.disable_msd = config_ram_copy.disable_msd;
config_ram.page_erase_enable = config_ram_copy.page_erase_enable;
config_rom_init();
}

Expand Down Expand Up @@ -230,3 +233,12 @@ uint8_t config_ram_get_disable_msd(void)
return config_ram.disable_msd;
}

void config_ram_set_page_erase(bool page_erase_enable)
{
config_ram.page_erase_enable = page_erase_enable;
}

bool config_ram_get_page_erase(void)
{
return config_ram.page_erase_enable;
}
4 changes: 4 additions & 0 deletions source/daplink/settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* Copyright 2019, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -55,6 +57,8 @@ uint8_t config_ram_add_hexdump(uint32_t hexdump);
uint8_t config_ram_get_hexdumps(uint32_t **hexdumps);
void config_ram_set_disable_msd(bool disable_msd);
uint8_t config_ram_get_disable_msd(void);
void config_ram_set_page_erase(bool page_erase_enable);
bool config_ram_get_page_erase(void);

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

0 comments on commit 1495a43

Please sign in to comment.