|
| 1 | +<!-- |
| 2 | + DAPjs |
| 3 | + Copyright Arm Limited 2018 |
| 4 | + Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + of this software and associated documentation files (the "Software"), to deal |
| 6 | + in the Software without restriction, including without limitation the rights |
| 7 | + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + copies of the Software, and to permit persons to whom the Software is |
| 9 | + furnished to do so, subject to the following conditions: |
| 10 | + The above copyright notice and this permission notice shall be included in all |
| 11 | + copies or substantial portions of the Software. |
| 12 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 18 | + SOFTWARE. |
| 19 | +--> |
| 20 | + |
| 21 | +<!DOCTYPE html> |
| 22 | +<html> |
| 23 | +<body> |
| 24 | + <button id="read">Read Registers</button> |
| 25 | + |
| 26 | + <script type="text/javascript" src="../../dist/dap.umd.js"></script> |
| 27 | + <script> |
| 28 | + const count = 16; |
| 29 | + |
| 30 | + const readRegisters = async (device, count) => { |
| 31 | + const transport = new DAPjs.WebUSB(device); |
| 32 | + const processor = new DAPjs.CortexM(transport); |
| 33 | + |
| 34 | + await processor.connect(); |
| 35 | + await processor.halt(); |
| 36 | + |
| 37 | + const registers = Array.from({ length: count }, (_, index) => index); |
| 38 | + const values = await processor.readCoreRegisters(registers); |
| 39 | + |
| 40 | + await processor.resume(); |
| 41 | + await processor.disconnect(); |
| 42 | + |
| 43 | + const result = values.map(register => ("00000000" + register.toString(16)).slice(-8)); |
| 44 | + return result; |
| 45 | + }; |
| 46 | + |
| 47 | + document.getElementById("read").onclick = async () => { |
| 48 | + const device = await navigator.usb.requestDevice({ |
| 49 | + filters: [{vendorId: 0xD28}] |
| 50 | + }); |
| 51 | + const values = await readRegisters(device, count); |
| 52 | + values.forEach((value, index) => { |
| 53 | + const registerEl = document.getElementById(`r${index}`); |
| 54 | + registerEl.innerHTML = `Register ${index}: ${value}`; |
| 55 | + }); |
| 56 | + }; |
| 57 | + |
| 58 | + for (let index = 0; index < count; index++) { |
| 59 | + const registerEl = document.createElement("div"); |
| 60 | + registerEl.id = `r${index}`; |
| 61 | + registerEl.innerHTML = `Register ${index}: None`; |
| 62 | + document.body.appendChild(registerEl); |
| 63 | + } |
| 64 | + </script> |
| 65 | +</body> |
| 66 | +</html> |
0 commit comments