Skip to content

Commit

Permalink
Merge pull request ARMmbed#1 from wjzhang/develope
Browse files Browse the repository at this point in the history
Merge the CMSIS-DAP changes of Mesheven made.
  • Loading branch information
wjzhang committed Jul 8, 2016
2 parents fa41329 + 9813ba2 commit 9899997
Show file tree
Hide file tree
Showing 39 changed files with 1,235 additions and 173 deletions.
4 changes: 4 additions & 0 deletions projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,7 @@ projects:
- *module_if
- *module_hic_lpc11u35
- records/board/archlink.yaml
lpc11u35_multi_targets_if:
- *module_if
- *module_hic_lpc11u35
- records/board/mesh_multi_targets.yaml
18 changes: 18 additions & 0 deletions records/board/mesh_multi_targets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
common:
includes:
- source/target/mesheven/
sources:
board:
- source/board/mesh_multi_targets.c
target:
- source/target/mesheven/DBG_nRF51822/nrf51_target_flash.c
- source/target/mesheven/DBG_nRF51822/nrf51_target_reset.c
- source/target/mesheven/DBG_STM32F051/stm32f051_target_flash.c
- source/target/mesheven/DBG_STM32F051/stm32f051_target_reset.c
- source/target/mesheven/DBG_STM32F071/stm32f071_target_flash.c
- source/target/mesheven/DBG_STM32F071/stm32f071_target_reset.c
- source/target/mesheven/DBG_STM32F103RC/stm32f103_target_flash.c
- source/target/mesheven/DBG_STM32F405/stm32f405_target_flash.c
- source/target/mesheven/target.c
- source/target/mesheven/target_ids.h
- source/target/mesheven/target_reset.c
22 changes: 22 additions & 0 deletions source/board/mesh_multi_targets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file mesh_multi_targets.c
* @brief board ID for the Mesheven multi-targets: nRF51/STM32F051/STM32F072/STM32F103/STM32F405
*
* DAPLink Interface Firmware
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed 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.
*/

const char *board_id = "2000";
3 changes: 2 additions & 1 deletion source/daplink/drag-n-drop/file_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "RTL.h"
#include "compiler.h"


typedef enum {
STREAM_STATE_CLOSED,
STREAM_STATE_OPEN,
Expand Down Expand Up @@ -140,7 +141,7 @@ error_t stream_open(stream_type_t stream_type)
util_assert(0);
return ERROR_INTERNAL;
}

stream_thread_set();
// Initialize all variables
memset(&shared_state, 0, sizeof(shared_state));
Expand Down
4 changes: 2 additions & 2 deletions source/daplink/drag-n-drop/flash_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ error_t flash_decoder_get_flash(flash_decoder_type_t type, uint32_t addr, bool a
flash_intf_local = flash_intf_iap_protected;
}
} else if (FLASH_DECODER_TYPE_TARGET == type) {
flash_start_local = target_device.flash_start;
flash_start_local = target_device[targetID].flash_start;
flash_intf_local = flash_intf_target;
}
} else {
Expand Down Expand Up @@ -338,7 +338,7 @@ static bool flash_decoder_is_at_end(uint32_t addr, const uint8_t *data, uint32_t
break;

case FLASH_DECODER_TYPE_TARGET:
end_addr = target_device.flash_end;
end_addr = target_device[targetID].flash_end;
break;

default:
Expand Down
9 changes: 0 additions & 9 deletions source/daplink/drag-n-drop/flash_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ error_t flash_manager_init(const flash_intf_t *flash_intf)
return status;
}

// Erase flash and unint if there are errors
status = intf->erase_chip();
flash_manager_printf(" intf->erase_chip ret=%i\r\n", status);

if (ERROR_SUCCESS != status) {
intf->uninit();
return status;
}

state = STATE_OPEN;
return status;
}
Expand Down
45 changes: 36 additions & 9 deletions source/daplink/drag-n-drop/vfs_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "file_stream.h"
#include "error.h"

#include "target_ids.h"
#include "target_config.h"

// Set to 1 to enable debugging
#define DEBUG_VFS_MANAGER 0

Expand Down Expand Up @@ -129,6 +132,9 @@ static uint32_t time_usb_idle;
static OS_MUT sync_mutex;
static OS_TID sync_thread = 0;

// the drag&drop file is Bin/Hex format
static bool fileIsBinOrHex = false;

// Synchronization functions
static void sync_init(void);
static void sync_assert_usb_thread(void);
Expand Down Expand Up @@ -307,8 +313,6 @@ void usbd_msc_read_sect(uint32_t sector, uint8_t *buf, uint32_t num_of_sectors)
return;
}

// indicate msc activity
main_blink_msc_led(MAIN_LED_OFF);
vfs_read(sector, buf, num_of_sectors);
}

Expand All @@ -329,9 +333,10 @@ void usbd_msc_write_sect(uint32_t sector, uint8_t *buf, uint32_t num_of_sectors)
return;
}

// indicate msc activity
main_blink_msc_led(MAIN_LED_OFF);
vfs_write(sector, buf, num_of_sectors);
// indicate DAP activity
main_blink_hid_led(MAIN_LED_OFF);
if (vfs_write(sector, buf, num_of_sectors) == true)
return;
file_data_handler(sector, buf, num_of_sectors);
}

Expand Down Expand Up @@ -363,6 +368,9 @@ static bool changing_state()

static void build_filesystem()
{
//init
fileIsBinOrHex = false;

// Update anything that could have changed file system state
file_transfer_state = default_transfer_state;
vfs_user_build_filesystem();
Expand Down Expand Up @@ -400,6 +408,8 @@ static void file_change_handler(const vfs_filename_t filename, vfs_file_change_t
// the same extension to keep track of transfer info in some cases.
if (!(VFS_FILE_ATTR_HIDDEN & vfs_file_get_attr(new_file_data))) {
stream = stream_type_from_name(filename);
if (STREAM_TYPE_NONE != stream)
fileIsBinOrHex = true;
uint32_t size = vfs_file_get_size(new_file_data);
vfs_sector_t sector = vfs_file_get_start_sector(new_file_data);
transfer_update_file_info(file, sector, size, stream);
Expand All @@ -421,7 +431,9 @@ static void file_data_handler(uint32_t sector, const uint8_t *buf, uint32_t num_

// this is the key for starting a file write - we dont care what file types are sent
// just look for something unique (NVIC table, hex, srec, etc) until root dir is updated
if (!file_transfer_state.stream_started) {
if (!file_transfer_state.stream_started && fileIsBinOrHex == true) {
if ( targetID == Target_UNKNOWN )
targetID = swd_init_get_target();
// look for file types we can program
stream = stream_start_identify((uint8_t *)buf, VFS_SECTOR_SIZE * num_of_sectors);

Expand Down Expand Up @@ -659,6 +671,7 @@ static void transfer_stream_data(uint32_t sector, const uint8_t *data, uint32_t
util_assert(file_transfer_state.stream_open);
status = stream_write((uint8_t *)data, size);
vfs_mngr_printf(" stream_write ret=%i\r\n", status);
file_transfer_state.size_processed += size;

if (ERROR_SUCCESS_DONE == status) {
// Override status so ERROR_SUCCESS_DONE
Expand All @@ -669,13 +682,23 @@ static void transfer_stream_data(uint32_t sector, const uint8_t *data, uint32_t
file_transfer_state.stream_finished = true;
file_transfer_state.stream_optional_finish = true;
} else if (ERROR_SUCCESS_DONE_OR_CONTINUE == status) {
status = ERROR_SUCCESS;
file_transfer_state.stream_optional_finish = true;
if (file_transfer_state.size_processed < file_transfer_state.file_size)
{
status = ERROR_SUCCESS;
file_transfer_state.stream_optional_finish = true;
}
else
{
status = stream_close();
vfs_mngr_printf(" stream_close ret=%i\r\n", status);
file_transfer_state.stream_open = false;
file_transfer_state.stream_finished = true;
file_transfer_state.stream_optional_finish = true;
}
} else {
file_transfer_state.stream_optional_finish = false;
}

file_transfer_state.size_processed += size;
transfer_update_state(status);
}

Expand Down Expand Up @@ -778,6 +801,10 @@ static void transfer_update_state(error_t status)
// Set the fail reason
fail_reason = local_status;
vfs_mngr_printf(" Transfer finished, status: %i=%s\r\n", fail_reason, error_get_string(fail_reason));

target_set_state(RESET_RUN);
targetID = Target_UNKNOWN;

}

// If this state change is not from aborting a transfer
Expand Down
7 changes: 5 additions & 2 deletions source/daplink/drag-n-drop/virtual_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static const mbr_t mbr_tmpl = {
/*uint8_t */.boot_record_signature = 0x29, // signature is present
/*uint32_t*/.volume_id = 0x27021974, // serial number
// needs to match the root dir label
/*char[11]*/.volume_label = {'D', 'A', 'P', 'L', 'I', 'N', 'K', '-', 'D', 'N', 'D'},
/*char[11]*/.volume_label = {'M', 'E', 'S', 'H', '-', 'D', 'B', 'G', ' ', ' ', ' '},
// unused by msft - just a label (FAT, FAT12, FAT16)
/*char[8] */.file_system_type = {'F', 'A', 'T', '1', '2', ' ', ' ', ' '},

Expand Down Expand Up @@ -461,8 +461,9 @@ void vfs_read(uint32_t requested_sector, uint8_t *buf, uint32_t num_sectors)
}
}

void vfs_write(uint32_t requested_sector, const uint8_t *buf, uint32_t num_sectors)
bool vfs_write(uint32_t requested_sector, const uint8_t *buf, uint32_t num_sectors)
{
bool rc = false;
uint8_t i = 0;
uint32_t current_sector;
current_sector = 0;
Expand All @@ -484,6 +485,7 @@ void vfs_write(uint32_t requested_sector, const uint8_t *buf, uint32_t num_secto
// Update requested sector
requested_sector += sectors_to_read;
num_sectors -= sectors_to_read;
rc = true;
}

// If there is no more data to be read then break
Expand All @@ -494,6 +496,7 @@ void vfs_write(uint32_t requested_sector, const uint8_t *buf, uint32_t num_secto
// Move to the next virtual media entry
current_sector += vm_sectors;
}
return rc;
}

static uint32_t read_zero(uint32_t sector_offset, uint8_t *data, uint32_t num_sectors)
Expand Down
3 changes: 2 additions & 1 deletion source/daplink/drag-n-drop/virtual_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define VIRTUAL_FS_H

#include "stdint.h"
#include "stdbool.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -99,7 +100,7 @@ void vfs_set_file_change_callback(vfs_file_change_cb_t cb);
void vfs_read(uint32_t sector, uint8_t *buf, uint32_t num_of_sectors);

// Write one or more sectors to the virtual filesystem
void vfs_write(uint32_t sector, const uint8_t *buf, uint32_t num_of_sectors);
bool vfs_write(uint32_t sector, const uint8_t *buf, uint32_t num_of_sectors);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion source/daplink/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ static const char *const error_message[] = {
"",
// ERROR_BL_UPDT_BAD_CRC
"The bootloader CRC did not pass.",

// ERROR_TARGET_UNKNOWN
"unsupported target device."
};
COMPILER_ASSERT(ERROR_COUNT == ELEMENTS_IN_ARRAY(error_message));

Expand Down
2 changes: 1 addition & 1 deletion source/daplink/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef enum {
ERROR_BL_UPDT_BAD_CRC,

// Add new values here

ERROR_TARGET_UNKNOWN,
ERROR_COUNT
} error_t;

Expand Down
2 changes: 1 addition & 1 deletion source/daplink/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const char *info_get_unique_id_string_descriptor(void)
static void setup_basics()
{
uint8_t i = 0, idx = 0;
memset(string_board_id, 0, sizeof(string_board_id));
memset(string_version, 0, sizeof(string_version));
memset(string_host_id, 0, sizeof(string_host_id));
memset(string_target_id, 0, sizeof(string_target_id));
memset(string_hic_id, 0, sizeof(string_hic_id));
Expand Down
2 changes: 1 addition & 1 deletion source/daplink/interface/daplink.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const vfs_filename_t daplink_mode_file_name = "START_BLACT";
__attribute__((weak))
const vfs_filename_t daplink_url_name = "MBED HTM";
__attribute__((weak))
const vfs_filename_t daplink_drive_name = "DAPLINK ";
const vfs_filename_t daplink_drive_name = "MESH-DBG ";
__attribute__((weak))
const char *const daplink_target_url = "https://mbed.org/device/?code=@U?version=@V?target_id=@T";

Expand Down
Loading

0 comments on commit 9899997

Please sign in to comment.