-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ner build fixups #180
Ner build fixups #180
Changes from all commits
def286a
99a4dc9
dce8453
15b31c1
e2af96b
b23e493
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
adapter driver ftdi | ||
ftdi vid_pid 0x0403 0x6010 | ||
ftdi_vid_pid 0x0403 0x6010 | ||
|
||
# Initial state: Assuming 0x0008 doesn't interfere with your setup | ||
# and 0x000b sets the required initial states for your other signals. | ||
ftdi layout_init 0x0008 0x000b | ||
ftdi_layout_init 0x0008 0x000b | ||
|
||
ftdi layout_signal LED_Tx -data 0x00F0 -oe 0x00F0 | ||
ftdi layout_signal LED_Rx -data 0x00F0 -oe 0x00F0 | ||
ftdi_layout_signal LED_Tx -data 0x00F0 -oe 0x00F0 | ||
ftdi_layout_signal LED_Rx -data 0x00F0 -oe 0x00F0 | ||
|
||
# Configure GPIOL0 (ADBUS4) as nSRST, assuming active low reset | ||
# Setting `-data` for active low, `-oe` to enable output. | ||
# If tri-state isn't supported, this configures the pin as push-pull. | ||
ftdi layout_signal nSRST -data 0x0010 -oe 0x0010 | ||
ftdi_layout_signal nSRST -data 0x0010 -oe 0x0010 | ||
|
||
transport select jtag | ||
transport select jtag |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,12 @@ | |
# To see a list of available commands and additional configuration options, run `ner --help` | ||
# ============================================================================== | ||
import argparse | ||
import platform | ||
import subprocess | ||
import sys | ||
import os | ||
import glob | ||
import time | ||
|
||
# custom modules for functinality that is too large to be included in this script directly | ||
from .miniterm import main as miniterm | ||
|
@@ -31,7 +34,7 @@ def build(args): | |
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", "clean"] | ||
else: | ||
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", f"-j{os.cpu_count()}"] | ||
run_command(command) | ||
run_command(command, stream_output=True) | ||
|
||
# ============================================================================== | ||
# Clang command | ||
|
@@ -55,7 +58,53 @@ def clang(args): | |
# ============================================================================== | ||
|
||
def debug(args): | ||
pass | ||
|
||
command = [] | ||
#if args.docker: | ||
# print("Dockerized openocd unsupported for gdb") | ||
# sys.exit(1) | ||
|
||
command = command + ["openocd"] | ||
|
||
current_directory = os.getcwd() | ||
if args.ftdi: | ||
ftdi_path = os.path.join(current_directory, "Drivers", "Embedded-Base", "ftdi_flash.cfg") | ||
command = command + ["-f", ftdi_path] | ||
else: | ||
command = command + ["-f", "interface/cmsis-dap.cfg"] | ||
|
||
build_directory = os.path.join("build", "*.elf") | ||
elf_files = glob.glob(build_directory) | ||
if not elf_files: | ||
print("Error: No ELF file found in ./build/") | ||
sys.exit(1) | ||
|
||
elf_file = os.path.basename(os.path.normpath(elf_files[0])) # Take the first ELF file found | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats this basename command for. I trust it works ig but i thought u could just directly do elf_files[0] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filepath is different inside of docker. |
||
print(f"Found ELF file: {elf_file}") | ||
|
||
halt_command = command + ["-f", "flash.cfg", "-f", os.path.join(current_directory, "Drivers", "Embedded-Base", "openocd.cfg"), | ||
"-c", "init", "-c", "reset halt"] | ||
ocd = subprocess.Popen(halt_command) | ||
time.sleep(1) | ||
|
||
# for some reason the host docker internal thing is broken on linux despite compose being set correctly, hence this hack | ||
gdb_uri = "host.docker.internal" | ||
if platform.system() == "Linux" and is_wsl() == 0: | ||
gdb_uri = "localhost" | ||
|
||
send_command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "arm-none-eabi-gdb", f"/home/app/build/{elf_file}", "-ex", f"target extended-remote {gdb_uri}:3333"] | ||
|
||
subprocess.run(send_command) | ||
|
||
# make terminal clearer | ||
time.sleep(4) | ||
print("\nKilling openocd...") | ||
ocd.terminate() | ||
time.sleep(1) | ||
|
||
|
||
|
||
|
||
|
||
# ============================================================================== | ||
# Flash command | ||
|
@@ -64,6 +113,10 @@ def debug(args): | |
def flash(args): | ||
|
||
command = [] | ||
if args.docker and args.ftdi: | ||
print("Cannot flash ftdi from docker") | ||
sys.exit(1) | ||
|
||
if args.docker: | ||
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm"] | ||
|
||
|
@@ -75,8 +128,18 @@ def flash(args): | |
command = command + ["-f", ftdi_path] | ||
else: | ||
command = command + ["-f", "interface/cmsis-dap.cfg"] | ||
|
||
command = command + ["-f", "flash.cfg"] | ||
|
||
|
||
build_directory = os.path.join("build", "*.elf") | ||
elf_files = glob.glob(build_directory) | ||
if not elf_files: | ||
print("Error: No ELF file found in ./build/") | ||
sys.exit(1) | ||
|
||
elf_file = elf_files[0] # Take the first ELF file found | ||
print(f"Found ELF file: {elf_file}") | ||
|
||
command = command + ["-f", "flash.cfg", "-c", f"program {elf_file} verify reset exit"] | ||
|
||
run_command(command, stream_output=True) | ||
|
||
|
@@ -206,6 +269,11 @@ def main(): | |
# ============================================================================== | ||
|
||
parser_debug = subparsers.add_parser('debug', help="Start a debug session") | ||
parser_debug.add_argument( | ||
'--ftdi', | ||
action="store_true", | ||
help="Set this flag if the device uses an FTDI chip", | ||
) | ||
parser_debug.set_defaults(func=debug) | ||
|
||
# ============================================================================== | ||
|
@@ -257,21 +325,7 @@ def run_command(command, stream_output=False, exit_on_fail=True): | |
|
||
if stream_output: | ||
|
||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
|
||
# Stream the output in real-time | ||
while True: | ||
output = process.stdout.readline() | ||
if output == '' and process.poll() is not None: | ||
break | ||
if output: | ||
print(output.strip()) | ||
|
||
# Capture any remaining output | ||
stderr_output = process.stderr.read() | ||
if stderr_output: | ||
print(stderr_output, file=sys.stderr) | ||
|
||
process = subprocess.Popen(command, text=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did we find a way to get this streaming to work without that while loop? i thought we added that explicitly to get some form of sreamed output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just don't use PIPE. Everything apparently works as long as the code doesn't need to access the output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idk I tested before adding this and running flash showed nothing on output, but if u tested this then alright |
||
|
||
returncode = process.wait() | ||
if returncode != 0: | ||
|
@@ -294,6 +348,18 @@ def disconnect_usbip(): | |
command = ["sudo", "usbip", "detach", "-p", "0"] | ||
run_command(command, exit_on_fail=False) | ||
|
||
def is_wsl(v: str = platform.uname().release) -> int: | ||
""" | ||
detects if Python is running in WSL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are better ways to detect WSL: if platform.system() == "Linux" and "microsoft" in platform.uname().release.lower(): or if 'WSL_DISTRO_NAME' in os.environ: id rather us use one of these, seems cleaner than ur method |
||
""" | ||
|
||
if v.endswith("-Microsoft"): | ||
return 1 | ||
elif v.endswith("microsoft-standard-WSL2"): | ||
return 2 | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$_TARGETNAME configure -event gdb-detach { | ||
reset run | ||
shutdown | ||
} | ||
|
||
init | ||
reset halt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we clean out unused code comments