-
Notifications
You must be signed in to change notification settings - Fork 7.8k
boards: pjrc: Added Support for the Teensy CLI Tools soft reboot functionality #88024
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
Open
jbehrensnx
wants to merge
3
commits into
zephyrproject-rtos:main
Choose a base branch
from
tiacsys:teensy-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2025 Navimatix GmbH. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <soc.h> | ||
#include <zephyr/drivers/uart/cdc_acm.h> | ||
#include <zephyr/drivers/usb/usb_dc.h> | ||
#include <zephyr/init.h> | ||
#include <zephyr/usb/class/usb_cdc.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
LOG_MODULE_REGISTER(reset, CONFIG_SOC_LOG_LEVEL); | ||
|
||
#define TEENSY_RESET_BAUDRATE 134 | ||
#define TEENSY_RESET_COMMAND "bkpt #251" | ||
#define TEENSY_VID 0x16c0 | ||
#define TEENSY_PID 0x0483 | ||
|
||
static void teensy_reset(const struct device *dev, uint32_t rate) | ||
{ | ||
if (rate != TEENSY_RESET_BAUDRATE) { | ||
return; | ||
} | ||
|
||
/* The programmer set the baud rate to 134 baud. Reset into the | ||
* bootloader. | ||
*/ | ||
__ASM volatile(TEENSY_RESET_COMMAND); | ||
} | ||
|
||
void board_late_init_hook(void) | ||
{ | ||
const struct device *dev = device_get_binding(CONFIG_BOOTLOADER_TEENSY_DEVICE_NAME); | ||
|
||
if (dev == NULL) { | ||
LOG_ERR("Could not find reset signal device with name %s", | ||
CONFIG_BOOTLOADER_TEENSY_DEVICE_NAME); | ||
return; | ||
} | ||
|
||
if ((CONFIG_USB_DEVICE_VID != TEENSY_VID) || (CONFIG_USB_DEVICE_PID != TEENSY_PID)) { | ||
LOG_ERR("Incorrect USB VID or PID. CONFIG_USB_DEVICE_VID should be 0x%x and " | ||
"CONFIG_USB_DEVICE_PID should be 0x%x.", | ||
TEENSY_VID, TEENSY_PID); | ||
return; | ||
} | ||
|
||
cdc_acm_dte_rate_callback_set(dev, teensy_reset); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.. _snippet-pjrc-teensy-bootloader: | ||
|
||
PJRC Teensy Bootloader (pjrc-teensy-bootloader) | ||
############################################### | ||
|
||
.. code-block:: console | ||
|
||
west build -S pjrc-teensy-bootloader [...] | ||
|
||
Overview | ||
******** | ||
|
||
This snippet makes the nessecary configurations to allow flashing of Teensy 4 | ||
based boards without triggering the reset pin. This is done via a CDC ACM UART. | ||
|
||
Requirements | ||
************ | ||
|
||
A board that supports flashing via the teensy cli tools. | ||
|
||
A devicetree node with node label ``zephyr_udc0`` that points to an enabled USB | ||
device node with driver support. This should look roughly like this in | ||
:ref:`your devicetree <get-devicetree-outputs>`: | ||
|
||
.. code-block:: DTS | ||
|
||
usb1: zephyr_udc0: usbd@402e0000 { | ||
compatible = "nxp,ehci"; | ||
/* ... */ | ||
}; | ||
|
||
The Teensy 4.0 and 4.1 boards have this node by default, but others might not. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CONFIG_BOOTLOADER_TEENSY=y | ||
CONFIG_USB_DEVICE_VID=0x16c0 | ||
CONFIG_USB_DEVICE_PID=0x0483 | ||
|
||
CONFIG_USB_DEVICE_STACK=y | ||
CONFIG_USB_CDC_ACM=y | ||
CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT=y | ||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y | ||
Comment on lines
+5
to
+8
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. This is about to become deprecated. 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. What would be the new way to do this? |
||
CONFIG_BOARD_LATE_INIT_HOOK=y |
12 changes: 12 additions & 0 deletions
12
snippets/pjrc-teensy-bootloader/pjrc-teensy-bootloader.overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2025 Navimatix GmbH | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&zephyr_udc0 { | ||
snippet_pjrc_teensy_bootloader_uart { | ||
compatible = "zephyr,cdc-acm-uart"; | ||
label = "USB CDC-ACM"; | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: pjrc-teensy-bootloader | ||
append: | ||
EXTRA_CONF_FILE: pjrc-teensy-bootloader.conf | ||
EXTRA_DTC_OVERLAY_FILE: pjrc-teensy-bootloader.overlay |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We cannot use someone else's vendor ID in the tree.
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.
The thing is, it needs to be there, as the teensy cli looks for this specific VID/PID combination to send the soft-reboot command to.
I honestly have no idea what the process would be for getting permission to use the vendor id for this use case.
There are a handfull of uses of specific vendor ids in the tree, but I dont know their background.
Some other potential solutions, if we can not get permission to use the vendor id, would be to note the correct vendor id in the snippet readme, or look if we can get support for the zephyr vendor id in the teensy cli.
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.
No, it does not need to be there. It is entirely the "teensy cli" problem.
"Each Vendor ID Number is assigned to one company for its sole and exclusive use, along with associated Product ID Numbers. They may not be sold, transferred, or used by others, directly or indirectly, except in special circumstances and then only upon prior written approval by USB-IF. Unauthorized use of assigned or unassigned USB Vendor ID Numbers and associated Product ID Numbers are strictly prohibited." [0]
Also, I am not going to write about Vendor ID
0x16c0
, but you can find some information about it on your own.I see only one left. I will remove it as well.
It would not help you with your custom firmware/product because of [0]. I guess "teensy cli" could be improved to accept VID/PID arguments, but that is not an issue for the Zephyr Project.
[0] https://www.usb.org/sites/default/files/usb-if_member_agreement_080618_1.pdf
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.
Thanks for the clarification.
I did some investigation into teensy_cli, but the required changes are more difficult than they first appeared, so I currently don't plan on pursuing that avenue any further.
At this point it looks to me like the best option is to remove the vendor id from the snippet conf file and mention the correct vendor id in the readme instead.
I am also thinking about adding information about the snippet/soft reboot to the flashing section of the board readme.