-
Notifications
You must be signed in to change notification settings - Fork 84
hslink: add button trigger reset #67
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
93e293a
feat: trigger a reset when click button
kaidegit 2eb523a
Commit submodule changes - by UGit
kaidegit fda1263
enhance: add async for reset
kaidegit 079f8fa
fix: srst level
kaidegit 96b813f
fix: por reset change to modify setting temporarily
kaidegit 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
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 |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
#include <stdint.h> | ||
|
||
uint8_t software_reset(void); | ||
void por_reset(void); | ||
|
||
|
||
#endif //HSLINK_PRO_DP_COMMON_H |
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,64 @@ | ||
// | ||
// Created by yekai on 2025/8/5. | ||
// | ||
|
||
#include "reset_way.h" | ||
|
||
#include <MultiTimer.h> | ||
|
||
#include "DAP_config.h" | ||
#include "DAP.h" | ||
#include "hpm_spi_drv.h" | ||
#include "hpm_clock_drv.h" | ||
#include "swd_host.h" | ||
#include "HSLink_Pro_expansion.h" | ||
|
||
// Use the CMSIS-Core definition if available. | ||
#if !defined(SCB_AIRCR_PRIGROUP_Pos) | ||
#define SCB_AIRCR_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ | ||
#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP Mask */ | ||
#endif | ||
|
||
uint8_t software_reset(void) { | ||
if (DAP_Data.debug_port != DAP_PORT_SWD) { | ||
return 1; | ||
} | ||
uint8_t ret = 0; | ||
uint32_t val; | ||
ret |= swd_read_word(NVIC_AIRCR, &val); | ||
ret |= swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | SYSRESETREQ); | ||
return ret; | ||
} | ||
|
||
void por_reset(void) { | ||
if ((!VREF_ENABLE && HSLink_Setting.power.power_on) | ||
|| VREF_ENABLE) { | ||
// we change the settings temporarily to turn off the power | ||
// TODO this is temporarily solution and cannot control when using vref | ||
HSLink_Setting.power.power_on = false; | ||
static MultiTimer timer_; | ||
static auto timer_cb = [](MultiTimer *timer, void *user_data) { | ||
HSLink_Setting.power.power_on = true; | ||
}; | ||
multiTimerStart(&timer_, 50, false, timer_cb, NULL); | ||
} | ||
} | ||
|
||
void srst_reset(void) { | ||
gpio_write_pin( | ||
HPM_FGPIO, | ||
GPIO_GET_PORT_INDEX(PIN_SRST), | ||
GPIO_GET_PIN_INDEX(PIN_SRST), | ||
HSLink_Global.reset_level | ||
); | ||
static MultiTimer timer_; | ||
static auto timer_cb = [](MultiTimer *timer, void *user_data) { | ||
gpio_write_pin( | ||
HPM_FGPIO, | ||
GPIO_GET_PORT_INDEX(PIN_SRST), | ||
GPIO_GET_PIN_INDEX(PIN_SRST), | ||
!HSLink_Global.reset_level | ||
); | ||
}; | ||
multiTimerStart(&timer_, 50, false, timer_cb, NULL); | ||
} |
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,22 @@ | ||
// | ||
// Created by yekai on 2025/8/5. | ||
// | ||
|
||
#ifndef RESET_WAY_H | ||
#define RESET_WAY_H | ||
|
||
#include "stdint.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
uint8_t software_reset(void); | ||
void por_reset(void); | ||
void srst_reset(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //RESET_WAY_H |
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
2 changes: 2 additions & 0 deletions
2
projects/HSLink-Pro/third_party_components/MultiTimer/CMakeLists.txt
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,2 @@ | ||
sdk_app_inc(MultiTimer) | ||
sdk_app_src(MultiTimer/MultiTimer.c) |
1 change: 1 addition & 0 deletions
1
projects/HSLink-Pro/third_party_components/MultiTimer/MultiTimer
Submodule MultiTimer
added at
fe7748
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.
💡 Verification agent
🧩 Analysis chain
Verify reset function ISR safety.
The button callback now calls reset functions (
srst_reset()
,software_reset()
,por_reset()
) which will execute in ISR context due to the timer-driven approach. Ensure these functions are ISR-safe and don't perform blocking operations.🏁 Script executed:
Length of output: 275
🏁 Script executed:
Length of output: 9914
Heavy reset calls in ISR: software_reset() and por_reset() are not ISR-safe
software_reset() (reset_way.cpp:22–31) invokes swd_read_word() and swd_write_word(), which perform bit-banged SWD transfers with inherent delays.
por_reset() (reset_way.cpp:33–43) calls Power_Turn() and multiTimerStart(), scheduling timers and manipulating power rails.
These operations can block or re-enter timer APIs and must not run in interrupt context.
• srst_reset() (reset_way.cpp:45–50) merely toggles a GPIO and is ISR-safe.
• Defer software_reset() and por_reset() to a task or the main loop (e.g., post an event or set a flag) so they execute outside the ISR.
🤖 Prompt for AI Agents