| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import os |
| 18 |
import sys |
| 19 |
from time import sleep |
| 20 |
from random import randrange |
| 21 |
import math |
| 22 |
import logging |
| 23 |
|
| 24 |
from pyocd.core.helpers import ConnectHelper |
| 25 |
from pyocd.flash.file_programmer import FileProgrammer |
| 26 |
from test_util import ( |
| 27 |
get_session_options, |
| 28 |
get_test_binary_path, |
| 29 |
) |
| 30 |
|
| 31 |
logging.basicConfig(level=logging.WARNING) |
| 32 |
|
| 33 |
print("\n\n------ Test attaching to locked board ------") |
| 34 |
for i in range(0, 10): |
| 35 |
with ConnectHelper.session_with_chosen_probe(**get_session_options()) as session: |
| 36 |
board = session.board |
| 37 |
flash = session.target.memory_map.get_boot_memory().flash |
| 38 |
|
| 39 |
board.target.reset_and_halt() |
| 40 |
flash.init(flash.Operation.ERASE) |
| 41 |
flash.erase_all() |
| 42 |
flash.cleanup() |
| 43 |
board.target.reset() |
| 44 |
|
| 45 |
print("\n\n------ Testing Attaching to board ------") |
| 46 |
for i in range(0, 100): |
| 47 |
with ConnectHelper.session_with_chosen_probe(**get_session_options()) as session: |
| 48 |
board = session.board |
| 49 |
board.target.halt() |
| 50 |
sleep(0.01) |
| 51 |
board.target.resume() |
| 52 |
sleep(0.01) |
| 53 |
|
| 54 |
print("\n\n------ Flashing new code ------") |
| 55 |
with ConnectHelper.session_with_chosen_probe(**get_session_options()) as session: |
| 56 |
board = session.board |
| 57 |
binary_file = get_test_binary_path(board.test_binary) |
| 58 |
board.target.reset_and_halt() |
| 59 |
FileProgrammer(session).program(binary_file) |
| 60 |
|
| 61 |
print("\n\n------ Testing Attaching to regular board ------") |
| 62 |
for i in range(0, 10): |
| 63 |
with ConnectHelper.session_with_chosen_probe(**get_session_options()) as session: |
| 64 |
board = session.board |
| 65 |
board.target.reset_and_halt() |
| 66 |
board.target.halt() |
| 67 |
sleep(0.2) |
| 68 |
board.target.resume() |
| 69 |
sleep(0.2) |