Skip to content
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

Registering a new target #981

Open
ksigurdsson opened this issue Oct 13, 2020 · 2 comments
Open

Registering a new target #981

ksigurdsson opened this issue Oct 13, 2020 · 2 comments

Comments

@ksigurdsson
Copy link

ksigurdsson commented Oct 13, 2020

I've defined a new (CoreSightTarget subclass) target and successfully tested it by following the instructions in adding_new_targets.md to add it to the list of builtin targets

Is there a way to import the new target source file without changing the contents of pyocd/target/builtin?

It would be nice if I could just point to this new file in the pyocd.yaml file in a similar way you can point to a CMSIS pack
e.g.

target:
- <path_to>/target_<device>.py

@flit
Copy link
Member

flit commented Oct 18, 2020

Yeah, I totally agree it would be nice to easily add additional targets externally to pyocd. Both the option you suggested via config, as well as by dropping a target file in a specific directory.

Right now the best way to do this is by putting the new target module(s) in a directory with a pyocd_user.py script that looks like this:

import sys
import os

# Add this directory to python path.
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

# Add the new target.
import my_new_target

Each target module should include this (in addition to the target class, of course):

from pyocd.target import TARGET
TARGET['my-new-target-name'] = MyNewTargetClass

(This could be done instead in the pyocd_user.py script.)

You may also wish to include a pyocd.yaml that sets target_override appropriately. Then you can set the --project-directory argument to the directory and everything will auto-load.

Not the simplest, but it works for now. There are plenty of variants of this technique.

@ksigurdsson
Copy link
Author

I've been able to add the new target as suggested. This works well.
Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants