From 8bae1637dde53808c334084e54f2a5647649079f Mon Sep 17 00:00:00 2001 From: zzw Date: Mon, 17 Sep 2018 16:30:05 +0800 Subject: [PATCH 1/3] add daplink support 1, fix "automatio on" flash verfiy fail 2, Set data terminal rate in bits per second as 38400. RTL8195AM only works with 38400 to DAP UART 3, the updates need to wait Added verify api to daplink flash algo interface. #491 to be merged. --- projects.yaml | 4 + records/board/rtl8195am.yaml | 9 ++ source/board/rtl8195am.c | 30 ++++++ source/daplink/interface/swd_host.c | 4 +- source/daplink/interface/swd_host.h | 2 + source/target/realtek/rtl8195am/flash_blob.c | 89 +++++++++++++++++ source/target/realtek/rtl8195am/target.c | 97 +++++++++++++++++++ .../target/realtek/rtl8195am/target_reset.c | 54 +++++++++++ test/info.py | 5 +- 9 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 records/board/rtl8195am.yaml create mode 100644 source/board/rtl8195am.c create mode 100644 source/target/realtek/rtl8195am/flash_blob.c create mode 100644 source/target/realtek/rtl8195am/target.c create mode 100644 source/target/realtek/rtl8195am/target_reset.c diff --git a/projects.yaml b/projects.yaml index d4ce00d87..62380c4c2 100644 --- a/projects.yaml +++ b/projects.yaml @@ -331,6 +331,10 @@ projects: - *module_if - *module_hic_lpc11u35 - records/board/mbed_cloud_connect.yaml + lpc11u35_rtl8195am_if: + - *module_if + - *module_hic_lpc11u35 + - records/board/rtl8195am.yaml sam3u2c_ncs36510rf_if: - *module_if - *module_hic_sam3u2c diff --git a/records/board/rtl8195am.yaml b/records/board/rtl8195am.yaml new file mode 100644 index 000000000..6adea34a8 --- /dev/null +++ b/records/board/rtl8195am.yaml @@ -0,0 +1,9 @@ +common: + sources: + board: + - source/board/rtl8195am.c + target: + - source/target/realtek/rtl8195am/target.c + - source/target/realtek/rtl8195am/target_reset.c + macros: + - BOARD_RTL8195AM diff --git a/source/board/rtl8195am.c b/source/board/rtl8195am.c new file mode 100644 index 000000000..ba41a4f13 --- /dev/null +++ b/source/board/rtl8195am.c @@ -0,0 +1,30 @@ +/** + * @file rtl8195am.c + * @brief board ID for the Realtek RTL8195AM board + * + * DAPLink Interface Firmware + * Copyright (c) 2014-2017, Realtek Semiconductor Corp., 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. + */ + +#include "stdbool.h" +#include "flash_manager.h" + +const char *board_id = "4600"; + +void prerun_board_config(void) +{ + flash_manager_set_page_erase(true); +} diff --git a/source/daplink/interface/swd_host.c b/source/daplink/interface/swd_host.c index 0e48edae7..150b3ebb9 100644 --- a/source/daplink/interface/swd_host.c +++ b/source/daplink/interface/swd_host.c @@ -399,7 +399,7 @@ static uint8_t swd_write_data(uint32_t address, uint32_t data) } // Read 32-bit word from target memory. -static uint8_t swd_read_word(uint32_t addr, uint32_t *val) +uint8_t swd_read_word(uint32_t addr, uint32_t *val) { if (!swd_write_ap(AP_CSW, CSW_VALUE | CSW_SIZE32)) { return 0; @@ -413,7 +413,7 @@ static uint8_t swd_read_word(uint32_t addr, uint32_t *val) } // Write 32-bit word to target memory. -static uint8_t swd_write_word(uint32_t addr, uint32_t val) +uint8_t swd_write_word(uint32_t addr, uint32_t val) { if (!swd_write_ap(AP_CSW, CSW_VALUE | CSW_SIZE32)) { return 0; diff --git a/source/daplink/interface/swd_host.h b/source/daplink/interface/swd_host.h index 06337c3e0..4b01f7460 100644 --- a/source/daplink/interface/swd_host.h +++ b/source/daplink/interface/swd_host.h @@ -47,6 +47,8 @@ uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t e void swd_set_target_reset(uint8_t asserted); uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state); uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state); +uint8_t swd_read_word(uint32_t addr, uint32_t *val); +uint8_t swd_write_word(uint32_t addr, uint32_t val); #ifdef __cplusplus } diff --git a/source/target/realtek/rtl8195am/flash_blob.c b/source/target/realtek/rtl8195am/flash_blob.c new file mode 100644 index 000000000..5599cf081 --- /dev/null +++ b/source/target/realtek/rtl8195am/flash_blob.c @@ -0,0 +1,89 @@ +/* Flash OS Routines (Automagically Generated) + * Copyright (c) 2009-2015 ARM Limited + * + * 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. + */ + +static const uint32_t rtl8195am_flash_prog_blob[] = { + 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, + 0x01f8e92d, 0x8400f8df, 0x46172200, 0x0604f1a8, 0x4cff4dfe, 0x0c04f108, 0x5330f247, 0xf8cc2000, + 0x20010000, 0x0000f8c8, 0x21002005, 0x1000f8cc, 0xf4216831, 0xf4412170, 0x60317140, 0x20017020, + 0x0000f8cc, 0x97002000, 0x1c406829, 0x0101f001, 0x42989100, 0x2900d801, 0x7820d1f6, 0xf8cc2100, + 0xf0101000, 0xd0060f01, 0x42931c52, 0xe8bdd8d6, 0x200001f8, 0xe8bd4770, 0x200101f8, 0xe92d4770, + 0xb0814df7, 0xffbcf7ff, 0x20004ee2, 0xf1a66030, 0x20010b04, 0x0000f8cb, 0x21002005, 0xf1ab6031, + 0x468a0704, 0xf4216839, 0xf4412170, 0x60397140, 0x835cf8df, 0x0000f888, 0x60302001, 0x20004cd3, + 0x5530f247, 0xa000f8cd, 0x1c406821, 0x0101f001, 0x42a89100, 0x2900d801, 0xf898d1f6, 0x21000000, + 0xf0106031, 0xd1420f02, 0x21002006, 0x4aca6031, 0x60112101, 0xf4216839, 0xf4217140, 0x60392170, + 0x0000f888, 0x60302001, 0xf8cd2000, 0x6821a000, 0xf0011c40, 0x91000101, 0xd80142a8, 0xd1f62900, + 0xff6ef7ff, 0x60302000, 0xf8cb2001, 0x20050000, 0x60312100, 0xf4216839, 0xf4412170, 0x60397140, + 0x0000f888, 0x60302001, 0xf8cd2000, 0x6821a000, 0xf0011c40, 0x91000101, 0xd80142a8, 0xd1f62900, + 0x0000f898, 0x60312100, 0x0f02f010, 0xe9ddd0bc, 0x23000102, 0x60339a01, 0xc29cf8df, 0xf8cc2301, + 0x683b3000, 0x7340f423, 0x2370f423, 0xf888603b, 0x22002000, 0xd9062800, 0xf8885c8b, 0x1c523000, + 0x4290b2d2, 0x2001d8f8, 0x20006030, 0xa000f8cd, 0x1c406821, 0x0101f001, 0x42a89100, 0x2900d801, + 0xf7ffd1f6, 0x2000ff1d, 0x20016030, 0x0000f8cb, 0x21002005, 0x68396031, 0x2170f421, 0x7140f441, + 0xf8886039, 0x20010000, 0x20006030, 0xa000f8cd, 0x1c406821, 0x0101f001, 0x42a89100, 0x2900d801, + 0xf898d1f6, 0x21000000, 0xf0106031, 0xd1da0f02, 0xe8bdb004, 0x4a818df0, 0x2000b081, 0x91006811, + 0xd0042921, 0x60112121, 0x28141c40, 0x487cdbf6, 0xf0416801, 0x60010101, 0x680b497a, 0x0310f043, + 0x4979600b, 0xf443680b, 0x600b7380, 0xf443680b, 0x600b7300, 0x68194b75, 0x0120f041, 0x68016019, + 0x0106f021, 0x68106001, 0x1002f3c0, 0xbf282803, 0x4a6f2003, 0xf1a2444a, 0xf8120c04, 0xeb021020, + 0xf88c0080, 0x78421000, 0x2001f88c, 0xf88c7880, 0x48680002, 0xf0106800, 0xd0160f01, 0x68004866, + 0x0f20f010, 0x4865d011, 0xf0136803, 0xd00c7f80, 0xf3c06800, 0xf0004007, 0xeb03031f, 0xf88c0343, + 0xeb023002, 0xf88c1050, 0x23010001, 0xf88c4a51, 0x20003003, 0x485a6010, 0x1f006001, 0x49596003, + 0x90006808, 0x3001f89c, 0x000ff36f, 0x60084318, 0x68084955, 0xf89c9000, 0xf0203002, 0x431800ff, + 0x20046008, 0x60081f11, 0x1f0b2000, 0xf4216819, 0x9100117c, 0x60106019, 0x21384a4c, 0x4a4c6011, + 0x601121eb, 0x68114a4b, 0x71fff421, 0xb0016011, 0x20004770, 0x22004770, 0x0382eb00, 0x43d0f1a3, + 0xf841681b, 0x1c523022, 0x6f80f5b2, 0xf44fd3f4, 0x47705080, 0x45f8e92d, 0xf8df2400, 0x460e80b0, + 0x46a24607, 0x5530f247, 0x0084eb07, 0x40d0f1a0, 0x1024f856, 0x22006001, 0xa000f8cd, 0x0000f8d8, + 0xf0001c52, 0x90000001, 0xd80142aa, 0xd1f52800, 0xfe36f7ff, 0xf5b41c64, 0xd3e56f80, 0x5080f44f, + 0x85f8e8bd, 0x39080b01, 0xbf9c2902, 0x47702000, 0xf1a0b508, 0x0c0140d0, 0x1000f88d, 0xf88d0a01, + 0xf88d1001, 0x466a0002, 0x20202103, 0xfe57f7ff, 0xbd082000, 0x2700b5f8, 0x7000f88d, 0x7001f88d, + 0x4d1e4e1d, 0xf88d4c1e, 0x466a7002, 0x20202103, 0xfe45f7ff, 0xf88d2004, 0xf88d0000, 0xf88d7001, + 0x466a7002, 0xe02d2103, 0x40006004, 0x40006028, 0x40006060, 0x40006008, 0x40006118, 0x40000014, + 0x400002c0, 0x40000210, 0x40000230, 0x40000320, 0x00000008, 0x400001f4, 0x400000e0, 0x40000038, + 0x40006014, 0x4000611c, 0x40000300, 0x40006104, 0x400060f0, 0x40006120, 0x1fff8000, 0x1fff9000, + 0x1fffa000, 0xf7ff2020, 0xf44ffe0a, 0x46324300, 0xeb032000, 0xf1a10180, 0x680941d0, 0x1020f842, + 0xf5b01c40, 0xd3f46f80, 0x4310f44f, 0x2000462a, 0x0180eb03, 0x41d0f1a1, 0xf8426809, 0x1c401020, + 0x6f80f5b0, 0xf44fd3f4, 0x46214320, 0xeb032000, 0xf1a20280, 0x681242d0, 0x2020f841, 0xf5b01c40, + 0xd3f46f80, 0x46112200, 0xf7ff20c7, 0x4631fdd8, 0x4000f44f, 0xff3ef7ff, 0xf44f4629, 0xf7ff4010, + 0x4621ff39, 0x4020f44f, 0xff34f7ff, 0xbdf82000, 0x4ff8e92d, 0x000e4615, 0xf04f4607, 0xd01c0400, + 0x8078f8df, 0xf24746a3, 0x19385a30, 0x40d0f1a0, 0x60016829, 0xf8cd2000, 0xf8d8b000, 0x1c401000, + 0x0101f001, 0x45509100, 0x2900d801, 0xf7ffd1f5, 0x1d24fd67, 0x42b41d2d, 0x2000d3e7, 0x8ff8e8bd, + 0xf5a0b410, 0xf5b34300, 0xd9145f40, 0xebb32300, 0xd2100f91, 0x0c83eb00, 0x4cd0f1ac, 0xc000f8dc, + 0x4023f852, 0xd00245a4, 0x2001bc10, 0x1c5b4770, 0x0f91ebb3, 0xbc10d3ee, 0x47702000, 0x40006028, + 0x00000000, 0x00000000, 0x005e0101, 0x00000101, 0x00230201, 0x00050501 +}; + +static const program_target_t flash = { + 0x10007237, // Init + 0x10007353, // UnInit + 0x100073f5, // EraseChip + 0x100073c5, // EraseSector + 0x10007511, // ProgramPage + + 0x10007561, // Verify + + // BKPT : start of blob + 1 + // RSB : blob start + header + rw data offset + // RSP : stack pointer + { + 0x10007001, + 0x100075a0, + 0x10007800 + }, + + 0x10007000 + 0x00000A00, // mem buffer location + 0x10007000, // location to write prog_blob in target RAM + sizeof(rtl8195am_flash_prog_blob), // prog_blob size + rtl8195am_flash_prog_blob, // address of prog_blob + 0x00000400 // ram_to_flash_bytes_to_be_written +}; diff --git a/source/target/realtek/rtl8195am/target.c b/source/target/realtek/rtl8195am/target.c new file mode 100644 index 000000000..38a86423b --- /dev/null +++ b/source/target/realtek/rtl8195am/target.c @@ -0,0 +1,97 @@ +/** + * @file target.c + * @brief Target information for Realtek RTL8195AM + * + * DAPLink Interface Firmware + * Copyright (c) 2016-2017, Realtek Semiconductor Corp., 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. + */ + +#include "target_config.h" + +// The file flash_blob.c must only be included in target.c +#include "flash_blob.c" + +// target information +target_cfg_t target_device = { + .sector_size = KB(4), + .sector_cnt = MB(2) / KB(4), + .flash_start = 0x00000000, + .flash_end = 0x00000000 + MB(2), + .ram_start = 0x10007000, + .ram_end = 0x10070000, + .flash_algo = (program_target_t *) &flash, + .erase_reset = 0, +}; + +// RTL8195AM's main cpu can only talk 38400 with DAP UART +//#include "string.h" +#include "RTL.h" +#include "rl_usb.h" +#include "usb_for_lib.h" + +extern int32_t data_send_access; +extern int32_t data_send_active; +extern int32_t data_send_zlp; +extern int32_t data_to_send_wr; +extern int32_t data_to_send_rd; +extern uint8_t *ptr_data_to_send; +extern uint8_t *ptr_data_sent; +extern int32_t data_read_access; +extern int32_t data_receive_int_access; +extern int32_t data_received_pending_pckts; +extern int32_t data_no_space_for_receive; +extern uint8_t *ptr_data_received; +extern uint8_t *ptr_data_read; +extern uint16_t control_line_state; +extern CDC_LINE_CODING line_coding; + +extern int32_t USBD_CDC_ACM_PortReset(void); +extern int32_t USBD_CDC_ACM_PortSetLineCoding(CDC_LINE_CODING *line_coding); + +int32_t USBD_CDC_ACM_Reset(void) +{ + data_send_access = 0; + data_send_active = 0; + data_send_zlp = 0; + data_to_send_wr = 0; + data_to_send_rd = 0; + ptr_data_to_send = USBD_CDC_ACM_SendBuf; + ptr_data_sent = USBD_CDC_ACM_SendBuf; + data_read_access = 0; + data_receive_int_access = 0; + data_received_pending_pckts = 0; + data_no_space_for_receive = 0; + ptr_data_received = USBD_CDC_ACM_ReceiveBuf; + ptr_data_read = USBD_CDC_ACM_ReceiveBuf; + control_line_state = 0; + USBD_CDC_ACM_PortReset(); + line_coding.dwDTERate = 38400; + line_coding.bCharFormat = 0; + line_coding.bParityType = 0; + line_coding.bDataBits = 8; + + return (USBD_CDC_ACM_PortSetLineCoding(&line_coding)); +} + +int32_t USBD_CDC_ACM_SetLineCoding(void) +{ + line_coding.dwDTERate = 38400; + line_coding.bCharFormat = USBD_EP0Buf[4]; + line_coding.bParityType = USBD_EP0Buf[5]; + line_coding.bDataBits = USBD_EP0Buf[6]; + + return (USBD_CDC_ACM_PortSetLineCoding(&line_coding)); +} diff --git a/source/target/realtek/rtl8195am/target_reset.c b/source/target/realtek/rtl8195am/target_reset.c new file mode 100644 index 000000000..c7d168588 --- /dev/null +++ b/source/target/realtek/rtl8195am/target_reset.c @@ -0,0 +1,54 @@ +/* CMSIS-DAP Interface Firmware + * Copyright (c) 2015-2017 Realtek Semiconductor Corp. + * + * 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. + */ +#include +#include "target_reset.h" +#include "swd_host.h" +#include "DAP_Config.h" + +void target_before_init_debug(void) +{ + return; +} + +uint8_t target_unlock_sequence(void) +{ + return 1; +} + +uint8_t target_set_state(TARGET_RESET_STATE state) +{ + return swd_set_target_state_hw(state); +} + +uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size) +{ + return 0; +} + +void swd_set_target_reset(uint8_t asserted) +{ + if (asserted) { + swd_write_word(0xE000ED0C, 0x05FA0004); + } +} + +uint8_t validate_bin_nvic(const uint8_t *buf) +{ + const char header[] = {0x99, 0x99, 0x96, 0x96, 0x3F, 0xCC, 0x66, 0xFC, + 0xC0, 0x33, 0xCC, 0x03, 0xE5, 0xDC, 0x31, 0x62}; + + return !memcmp(header, buf, sizeof(header)); +} diff --git a/test/info.py b/test/info.py index 96099c69d..d31f8aa52 100644 --- a/test/info.py +++ b/test/info.py @@ -88,6 +88,7 @@ ("lpc11u35_vbluno51_if", False, 0x0000, "bin" ), ('lpc11u35_mtconnect04s_if', False, 0x0000, "bin" ), ('lpc11u35_mbed_cloud_connect_if', False, 0x0000, "bin" ), + ("lpc11u35_rtl8195am_if", False, 0x0000, "bin" ), ("lpc11u35_96b_nitrogen_if", False, 0x0000, "bin" ), ('lpc11u35_mtb_mxchip_emw3166_if', False, 0x0000, "bin" ), ('lpc11u35_mtb_nina_b112_if', False, 0x0000, "bin" ), @@ -169,6 +170,7 @@ ( 0x1200, 'sam3u2c_ncs36510rf_if', 'sam3u2c_bl', None ),# TODO - Set to 'ncs36510' when non-zero flash addresses are supported ( 0x1238, 'kl26z_nina_b1_if', 'kl26z_bl', 'u-blox-NINA-B1' ), ( 0x2410, 'lpc11u35_mbed_cloud_connect_if', None, None ), + ( 0x4600, 'lpc11u35_rtl8195am_if', None, 'REALTEK-RTL8195AM' ), ( 0x5050, 'lpc11u35_arm_watch_stm32f411_if', None, None ), ( 0x5051, 'lpc11u35_arm_watch_efm32_if', None, None ), ( 0x5052, 'lpc11u35_arm_watch_nrf51_if', None, None ), @@ -268,7 +270,8 @@ 'SSCI-MBIT', 'BlueNinja', 'U-BLOX-EVK-NINA-B1', - 'VNG-VBLUno51'] + 'VNG-VBLUno51', + 'REALTEK-RTL8195AM'] BOARD_ID_TO_BUILD_TARGET = {config[0]: config[3] for config in SUPPORTED_CONFIGURATIONS} From 173c67a3c7d6ca384d99cde224c049a835bc475f Mon Sep 17 00:00:00 2001 From: zzw Date: Mon, 17 Sep 2018 16:30:05 +0800 Subject: [PATCH 2/3] add daplink support 1, fix "automatio on" flash verfiy fail 2, Set data terminal rate in bits per second as 38400. RTL8195AM only works with 38400 to DAP UART 3, the updates need to wait Added verify api to daplink flash algo interface. #491 to be merged. --- projects.yaml | 4 + records/board/rtl8195am.yaml | 9 ++ source/board/rtl8195am.c | 30 ++++++ source/daplink/interface/swd_host.c | 4 +- source/daplink/interface/swd_host.h | 2 + source/target/realtek/rtl8195am/flash_blob.c | 89 +++++++++++++++++ source/target/realtek/rtl8195am/target.c | 97 +++++++++++++++++++ .../target/realtek/rtl8195am/target_reset.c | 54 +++++++++++ test/info.py | 5 +- 9 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 records/board/rtl8195am.yaml create mode 100644 source/board/rtl8195am.c create mode 100644 source/target/realtek/rtl8195am/flash_blob.c create mode 100644 source/target/realtek/rtl8195am/target.c create mode 100644 source/target/realtek/rtl8195am/target_reset.c diff --git a/projects.yaml b/projects.yaml index d4ce00d87..62380c4c2 100644 --- a/projects.yaml +++ b/projects.yaml @@ -331,6 +331,10 @@ projects: - *module_if - *module_hic_lpc11u35 - records/board/mbed_cloud_connect.yaml + lpc11u35_rtl8195am_if: + - *module_if + - *module_hic_lpc11u35 + - records/board/rtl8195am.yaml sam3u2c_ncs36510rf_if: - *module_if - *module_hic_sam3u2c diff --git a/records/board/rtl8195am.yaml b/records/board/rtl8195am.yaml new file mode 100644 index 000000000..6adea34a8 --- /dev/null +++ b/records/board/rtl8195am.yaml @@ -0,0 +1,9 @@ +common: + sources: + board: + - source/board/rtl8195am.c + target: + - source/target/realtek/rtl8195am/target.c + - source/target/realtek/rtl8195am/target_reset.c + macros: + - BOARD_RTL8195AM diff --git a/source/board/rtl8195am.c b/source/board/rtl8195am.c new file mode 100644 index 000000000..ba41a4f13 --- /dev/null +++ b/source/board/rtl8195am.c @@ -0,0 +1,30 @@ +/** + * @file rtl8195am.c + * @brief board ID for the Realtek RTL8195AM board + * + * DAPLink Interface Firmware + * Copyright (c) 2014-2017, Realtek Semiconductor Corp., 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. + */ + +#include "stdbool.h" +#include "flash_manager.h" + +const char *board_id = "4600"; + +void prerun_board_config(void) +{ + flash_manager_set_page_erase(true); +} diff --git a/source/daplink/interface/swd_host.c b/source/daplink/interface/swd_host.c index 0e48edae7..150b3ebb9 100644 --- a/source/daplink/interface/swd_host.c +++ b/source/daplink/interface/swd_host.c @@ -399,7 +399,7 @@ static uint8_t swd_write_data(uint32_t address, uint32_t data) } // Read 32-bit word from target memory. -static uint8_t swd_read_word(uint32_t addr, uint32_t *val) +uint8_t swd_read_word(uint32_t addr, uint32_t *val) { if (!swd_write_ap(AP_CSW, CSW_VALUE | CSW_SIZE32)) { return 0; @@ -413,7 +413,7 @@ static uint8_t swd_read_word(uint32_t addr, uint32_t *val) } // Write 32-bit word to target memory. -static uint8_t swd_write_word(uint32_t addr, uint32_t val) +uint8_t swd_write_word(uint32_t addr, uint32_t val) { if (!swd_write_ap(AP_CSW, CSW_VALUE | CSW_SIZE32)) { return 0; diff --git a/source/daplink/interface/swd_host.h b/source/daplink/interface/swd_host.h index 06337c3e0..4b01f7460 100644 --- a/source/daplink/interface/swd_host.h +++ b/source/daplink/interface/swd_host.h @@ -47,6 +47,8 @@ uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t e void swd_set_target_reset(uint8_t asserted); uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state); uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state); +uint8_t swd_read_word(uint32_t addr, uint32_t *val); +uint8_t swd_write_word(uint32_t addr, uint32_t val); #ifdef __cplusplus } diff --git a/source/target/realtek/rtl8195am/flash_blob.c b/source/target/realtek/rtl8195am/flash_blob.c new file mode 100644 index 000000000..5599cf081 --- /dev/null +++ b/source/target/realtek/rtl8195am/flash_blob.c @@ -0,0 +1,89 @@ +/* Flash OS Routines (Automagically Generated) + * Copyright (c) 2009-2015 ARM Limited + * + * 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. + */ + +static const uint32_t rtl8195am_flash_prog_blob[] = { + 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, + 0x01f8e92d, 0x8400f8df, 0x46172200, 0x0604f1a8, 0x4cff4dfe, 0x0c04f108, 0x5330f247, 0xf8cc2000, + 0x20010000, 0x0000f8c8, 0x21002005, 0x1000f8cc, 0xf4216831, 0xf4412170, 0x60317140, 0x20017020, + 0x0000f8cc, 0x97002000, 0x1c406829, 0x0101f001, 0x42989100, 0x2900d801, 0x7820d1f6, 0xf8cc2100, + 0xf0101000, 0xd0060f01, 0x42931c52, 0xe8bdd8d6, 0x200001f8, 0xe8bd4770, 0x200101f8, 0xe92d4770, + 0xb0814df7, 0xffbcf7ff, 0x20004ee2, 0xf1a66030, 0x20010b04, 0x0000f8cb, 0x21002005, 0xf1ab6031, + 0x468a0704, 0xf4216839, 0xf4412170, 0x60397140, 0x835cf8df, 0x0000f888, 0x60302001, 0x20004cd3, + 0x5530f247, 0xa000f8cd, 0x1c406821, 0x0101f001, 0x42a89100, 0x2900d801, 0xf898d1f6, 0x21000000, + 0xf0106031, 0xd1420f02, 0x21002006, 0x4aca6031, 0x60112101, 0xf4216839, 0xf4217140, 0x60392170, + 0x0000f888, 0x60302001, 0xf8cd2000, 0x6821a000, 0xf0011c40, 0x91000101, 0xd80142a8, 0xd1f62900, + 0xff6ef7ff, 0x60302000, 0xf8cb2001, 0x20050000, 0x60312100, 0xf4216839, 0xf4412170, 0x60397140, + 0x0000f888, 0x60302001, 0xf8cd2000, 0x6821a000, 0xf0011c40, 0x91000101, 0xd80142a8, 0xd1f62900, + 0x0000f898, 0x60312100, 0x0f02f010, 0xe9ddd0bc, 0x23000102, 0x60339a01, 0xc29cf8df, 0xf8cc2301, + 0x683b3000, 0x7340f423, 0x2370f423, 0xf888603b, 0x22002000, 0xd9062800, 0xf8885c8b, 0x1c523000, + 0x4290b2d2, 0x2001d8f8, 0x20006030, 0xa000f8cd, 0x1c406821, 0x0101f001, 0x42a89100, 0x2900d801, + 0xf7ffd1f6, 0x2000ff1d, 0x20016030, 0x0000f8cb, 0x21002005, 0x68396031, 0x2170f421, 0x7140f441, + 0xf8886039, 0x20010000, 0x20006030, 0xa000f8cd, 0x1c406821, 0x0101f001, 0x42a89100, 0x2900d801, + 0xf898d1f6, 0x21000000, 0xf0106031, 0xd1da0f02, 0xe8bdb004, 0x4a818df0, 0x2000b081, 0x91006811, + 0xd0042921, 0x60112121, 0x28141c40, 0x487cdbf6, 0xf0416801, 0x60010101, 0x680b497a, 0x0310f043, + 0x4979600b, 0xf443680b, 0x600b7380, 0xf443680b, 0x600b7300, 0x68194b75, 0x0120f041, 0x68016019, + 0x0106f021, 0x68106001, 0x1002f3c0, 0xbf282803, 0x4a6f2003, 0xf1a2444a, 0xf8120c04, 0xeb021020, + 0xf88c0080, 0x78421000, 0x2001f88c, 0xf88c7880, 0x48680002, 0xf0106800, 0xd0160f01, 0x68004866, + 0x0f20f010, 0x4865d011, 0xf0136803, 0xd00c7f80, 0xf3c06800, 0xf0004007, 0xeb03031f, 0xf88c0343, + 0xeb023002, 0xf88c1050, 0x23010001, 0xf88c4a51, 0x20003003, 0x485a6010, 0x1f006001, 0x49596003, + 0x90006808, 0x3001f89c, 0x000ff36f, 0x60084318, 0x68084955, 0xf89c9000, 0xf0203002, 0x431800ff, + 0x20046008, 0x60081f11, 0x1f0b2000, 0xf4216819, 0x9100117c, 0x60106019, 0x21384a4c, 0x4a4c6011, + 0x601121eb, 0x68114a4b, 0x71fff421, 0xb0016011, 0x20004770, 0x22004770, 0x0382eb00, 0x43d0f1a3, + 0xf841681b, 0x1c523022, 0x6f80f5b2, 0xf44fd3f4, 0x47705080, 0x45f8e92d, 0xf8df2400, 0x460e80b0, + 0x46a24607, 0x5530f247, 0x0084eb07, 0x40d0f1a0, 0x1024f856, 0x22006001, 0xa000f8cd, 0x0000f8d8, + 0xf0001c52, 0x90000001, 0xd80142aa, 0xd1f52800, 0xfe36f7ff, 0xf5b41c64, 0xd3e56f80, 0x5080f44f, + 0x85f8e8bd, 0x39080b01, 0xbf9c2902, 0x47702000, 0xf1a0b508, 0x0c0140d0, 0x1000f88d, 0xf88d0a01, + 0xf88d1001, 0x466a0002, 0x20202103, 0xfe57f7ff, 0xbd082000, 0x2700b5f8, 0x7000f88d, 0x7001f88d, + 0x4d1e4e1d, 0xf88d4c1e, 0x466a7002, 0x20202103, 0xfe45f7ff, 0xf88d2004, 0xf88d0000, 0xf88d7001, + 0x466a7002, 0xe02d2103, 0x40006004, 0x40006028, 0x40006060, 0x40006008, 0x40006118, 0x40000014, + 0x400002c0, 0x40000210, 0x40000230, 0x40000320, 0x00000008, 0x400001f4, 0x400000e0, 0x40000038, + 0x40006014, 0x4000611c, 0x40000300, 0x40006104, 0x400060f0, 0x40006120, 0x1fff8000, 0x1fff9000, + 0x1fffa000, 0xf7ff2020, 0xf44ffe0a, 0x46324300, 0xeb032000, 0xf1a10180, 0x680941d0, 0x1020f842, + 0xf5b01c40, 0xd3f46f80, 0x4310f44f, 0x2000462a, 0x0180eb03, 0x41d0f1a1, 0xf8426809, 0x1c401020, + 0x6f80f5b0, 0xf44fd3f4, 0x46214320, 0xeb032000, 0xf1a20280, 0x681242d0, 0x2020f841, 0xf5b01c40, + 0xd3f46f80, 0x46112200, 0xf7ff20c7, 0x4631fdd8, 0x4000f44f, 0xff3ef7ff, 0xf44f4629, 0xf7ff4010, + 0x4621ff39, 0x4020f44f, 0xff34f7ff, 0xbdf82000, 0x4ff8e92d, 0x000e4615, 0xf04f4607, 0xd01c0400, + 0x8078f8df, 0xf24746a3, 0x19385a30, 0x40d0f1a0, 0x60016829, 0xf8cd2000, 0xf8d8b000, 0x1c401000, + 0x0101f001, 0x45509100, 0x2900d801, 0xf7ffd1f5, 0x1d24fd67, 0x42b41d2d, 0x2000d3e7, 0x8ff8e8bd, + 0xf5a0b410, 0xf5b34300, 0xd9145f40, 0xebb32300, 0xd2100f91, 0x0c83eb00, 0x4cd0f1ac, 0xc000f8dc, + 0x4023f852, 0xd00245a4, 0x2001bc10, 0x1c5b4770, 0x0f91ebb3, 0xbc10d3ee, 0x47702000, 0x40006028, + 0x00000000, 0x00000000, 0x005e0101, 0x00000101, 0x00230201, 0x00050501 +}; + +static const program_target_t flash = { + 0x10007237, // Init + 0x10007353, // UnInit + 0x100073f5, // EraseChip + 0x100073c5, // EraseSector + 0x10007511, // ProgramPage + + 0x10007561, // Verify + + // BKPT : start of blob + 1 + // RSB : blob start + header + rw data offset + // RSP : stack pointer + { + 0x10007001, + 0x100075a0, + 0x10007800 + }, + + 0x10007000 + 0x00000A00, // mem buffer location + 0x10007000, // location to write prog_blob in target RAM + sizeof(rtl8195am_flash_prog_blob), // prog_blob size + rtl8195am_flash_prog_blob, // address of prog_blob + 0x00000400 // ram_to_flash_bytes_to_be_written +}; diff --git a/source/target/realtek/rtl8195am/target.c b/source/target/realtek/rtl8195am/target.c new file mode 100644 index 000000000..38a86423b --- /dev/null +++ b/source/target/realtek/rtl8195am/target.c @@ -0,0 +1,97 @@ +/** + * @file target.c + * @brief Target information for Realtek RTL8195AM + * + * DAPLink Interface Firmware + * Copyright (c) 2016-2017, Realtek Semiconductor Corp., 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. + */ + +#include "target_config.h" + +// The file flash_blob.c must only be included in target.c +#include "flash_blob.c" + +// target information +target_cfg_t target_device = { + .sector_size = KB(4), + .sector_cnt = MB(2) / KB(4), + .flash_start = 0x00000000, + .flash_end = 0x00000000 + MB(2), + .ram_start = 0x10007000, + .ram_end = 0x10070000, + .flash_algo = (program_target_t *) &flash, + .erase_reset = 0, +}; + +// RTL8195AM's main cpu can only talk 38400 with DAP UART +//#include "string.h" +#include "RTL.h" +#include "rl_usb.h" +#include "usb_for_lib.h" + +extern int32_t data_send_access; +extern int32_t data_send_active; +extern int32_t data_send_zlp; +extern int32_t data_to_send_wr; +extern int32_t data_to_send_rd; +extern uint8_t *ptr_data_to_send; +extern uint8_t *ptr_data_sent; +extern int32_t data_read_access; +extern int32_t data_receive_int_access; +extern int32_t data_received_pending_pckts; +extern int32_t data_no_space_for_receive; +extern uint8_t *ptr_data_received; +extern uint8_t *ptr_data_read; +extern uint16_t control_line_state; +extern CDC_LINE_CODING line_coding; + +extern int32_t USBD_CDC_ACM_PortReset(void); +extern int32_t USBD_CDC_ACM_PortSetLineCoding(CDC_LINE_CODING *line_coding); + +int32_t USBD_CDC_ACM_Reset(void) +{ + data_send_access = 0; + data_send_active = 0; + data_send_zlp = 0; + data_to_send_wr = 0; + data_to_send_rd = 0; + ptr_data_to_send = USBD_CDC_ACM_SendBuf; + ptr_data_sent = USBD_CDC_ACM_SendBuf; + data_read_access = 0; + data_receive_int_access = 0; + data_received_pending_pckts = 0; + data_no_space_for_receive = 0; + ptr_data_received = USBD_CDC_ACM_ReceiveBuf; + ptr_data_read = USBD_CDC_ACM_ReceiveBuf; + control_line_state = 0; + USBD_CDC_ACM_PortReset(); + line_coding.dwDTERate = 38400; + line_coding.bCharFormat = 0; + line_coding.bParityType = 0; + line_coding.bDataBits = 8; + + return (USBD_CDC_ACM_PortSetLineCoding(&line_coding)); +} + +int32_t USBD_CDC_ACM_SetLineCoding(void) +{ + line_coding.dwDTERate = 38400; + line_coding.bCharFormat = USBD_EP0Buf[4]; + line_coding.bParityType = USBD_EP0Buf[5]; + line_coding.bDataBits = USBD_EP0Buf[6]; + + return (USBD_CDC_ACM_PortSetLineCoding(&line_coding)); +} diff --git a/source/target/realtek/rtl8195am/target_reset.c b/source/target/realtek/rtl8195am/target_reset.c new file mode 100644 index 000000000..c7d168588 --- /dev/null +++ b/source/target/realtek/rtl8195am/target_reset.c @@ -0,0 +1,54 @@ +/* CMSIS-DAP Interface Firmware + * Copyright (c) 2015-2017 Realtek Semiconductor Corp. + * + * 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. + */ +#include +#include "target_reset.h" +#include "swd_host.h" +#include "DAP_Config.h" + +void target_before_init_debug(void) +{ + return; +} + +uint8_t target_unlock_sequence(void) +{ + return 1; +} + +uint8_t target_set_state(TARGET_RESET_STATE state) +{ + return swd_set_target_state_hw(state); +} + +uint8_t security_bits_set(uint32_t addr, uint8_t *data, uint32_t size) +{ + return 0; +} + +void swd_set_target_reset(uint8_t asserted) +{ + if (asserted) { + swd_write_word(0xE000ED0C, 0x05FA0004); + } +} + +uint8_t validate_bin_nvic(const uint8_t *buf) +{ + const char header[] = {0x99, 0x99, 0x96, 0x96, 0x3F, 0xCC, 0x66, 0xFC, + 0xC0, 0x33, 0xCC, 0x03, 0xE5, 0xDC, 0x31, 0x62}; + + return !memcmp(header, buf, sizeof(header)); +} diff --git a/test/info.py b/test/info.py index 96099c69d..d31f8aa52 100644 --- a/test/info.py +++ b/test/info.py @@ -88,6 +88,7 @@ ("lpc11u35_vbluno51_if", False, 0x0000, "bin" ), ('lpc11u35_mtconnect04s_if', False, 0x0000, "bin" ), ('lpc11u35_mbed_cloud_connect_if', False, 0x0000, "bin" ), + ("lpc11u35_rtl8195am_if", False, 0x0000, "bin" ), ("lpc11u35_96b_nitrogen_if", False, 0x0000, "bin" ), ('lpc11u35_mtb_mxchip_emw3166_if', False, 0x0000, "bin" ), ('lpc11u35_mtb_nina_b112_if', False, 0x0000, "bin" ), @@ -169,6 +170,7 @@ ( 0x1200, 'sam3u2c_ncs36510rf_if', 'sam3u2c_bl', None ),# TODO - Set to 'ncs36510' when non-zero flash addresses are supported ( 0x1238, 'kl26z_nina_b1_if', 'kl26z_bl', 'u-blox-NINA-B1' ), ( 0x2410, 'lpc11u35_mbed_cloud_connect_if', None, None ), + ( 0x4600, 'lpc11u35_rtl8195am_if', None, 'REALTEK-RTL8195AM' ), ( 0x5050, 'lpc11u35_arm_watch_stm32f411_if', None, None ), ( 0x5051, 'lpc11u35_arm_watch_efm32_if', None, None ), ( 0x5052, 'lpc11u35_arm_watch_nrf51_if', None, None ), @@ -268,7 +270,8 @@ 'SSCI-MBIT', 'BlueNinja', 'U-BLOX-EVK-NINA-B1', - 'VNG-VBLUno51'] + 'VNG-VBLUno51', + 'REALTEK-RTL8195AM'] BOARD_ID_TO_BUILD_TARGET = {config[0]: config[3] for config in SUPPORTED_CONFIGURATIONS} From b11af16de59a697accee98df45c5d83983498fc7 Mon Sep 17 00:00:00 2001 From: zzw Date: Wed, 19 Sep 2018 11:51:04 +0800 Subject: [PATCH 3/3] updates "target.c" 1, remove "extern" and "USBD_CDC_ACM_Reset" --- source/target/realtek/rtl8195am/target.c | 61 ++++-------------------- 1 file changed, 8 insertions(+), 53 deletions(-) diff --git a/source/target/realtek/rtl8195am/target.c b/source/target/realtek/rtl8195am/target.c index 38a86423b..585d4cf00 100644 --- a/source/target/realtek/rtl8195am/target.c +++ b/source/target/realtek/rtl8195am/target.c @@ -37,61 +37,16 @@ target_cfg_t target_device = { }; // RTL8195AM's main cpu can only talk 38400 with DAP UART -//#include "string.h" -#include "RTL.h" -#include "rl_usb.h" -#include "usb_for_lib.h" - -extern int32_t data_send_access; -extern int32_t data_send_active; -extern int32_t data_send_zlp; -extern int32_t data_to_send_wr; -extern int32_t data_to_send_rd; -extern uint8_t *ptr_data_to_send; -extern uint8_t *ptr_data_sent; -extern int32_t data_read_access; -extern int32_t data_receive_int_access; -extern int32_t data_received_pending_pckts; -extern int32_t data_no_space_for_receive; -extern uint8_t *ptr_data_received; -extern uint8_t *ptr_data_read; -extern uint16_t control_line_state; -extern CDC_LINE_CODING line_coding; - -extern int32_t USBD_CDC_ACM_PortReset(void); -extern int32_t USBD_CDC_ACM_PortSetLineCoding(CDC_LINE_CODING *line_coding); - -int32_t USBD_CDC_ACM_Reset(void) -{ - data_send_access = 0; - data_send_active = 0; - data_send_zlp = 0; - data_to_send_wr = 0; - data_to_send_rd = 0; - ptr_data_to_send = USBD_CDC_ACM_SendBuf; - ptr_data_sent = USBD_CDC_ACM_SendBuf; - data_read_access = 0; - data_receive_int_access = 0; - data_received_pending_pckts = 0; - data_no_space_for_receive = 0; - ptr_data_received = USBD_CDC_ACM_ReceiveBuf; - ptr_data_read = USBD_CDC_ACM_ReceiveBuf; - control_line_state = 0; - USBD_CDC_ACM_PortReset(); - line_coding.dwDTERate = 38400; - line_coding.bCharFormat = 0; - line_coding.bParityType = 0; - line_coding.bDataBits = 8; - - return (USBD_CDC_ACM_PortSetLineCoding(&line_coding)); -} +#include "uart.h" +static UART_Configuration UART_Config; int32_t USBD_CDC_ACM_SetLineCoding(void) { - line_coding.dwDTERate = 38400; - line_coding.bCharFormat = USBD_EP0Buf[4]; - line_coding.bParityType = USBD_EP0Buf[5]; - line_coding.bDataBits = USBD_EP0Buf[6]; + UART_Config.Baudrate = 38400; + UART_Config.DataBits = UART_DATA_BITS_8; + UART_Config.Parity = UART_PARITY_NONE; + UART_Config.StopBits = UART_STOP_BITS_1; + UART_Config.FlowControl = UART_FLOW_CONTROL_NONE; - return (USBD_CDC_ACM_PortSetLineCoding(&line_coding)); + return uart_set_configuration(&UART_Config); }