-
Notifications
You must be signed in to change notification settings - Fork 5
Feat: Add cpu clock increase #42
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif // __cplusplus | ||
|
|
||
| /** | ||
| * @brief Initialize clock to higher CPU frequency if possible | ||
| */ | ||
| void stub_lib_clock_init(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif // __cplusplus | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| */ | ||
|
|
||
| #include <target/clock.h> | ||
|
|
||
| void stub_lib_clock_init(void) | ||
| { | ||
| stub_target_clock_init(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdbool.h> | ||
|
Collaborator
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. No need to include stdbool.h |
||
|
|
||
| /** | ||
| * @brief Initialize clock | ||
| */ | ||
| void stub_target_clock_init(void); | ||
|
|
||
| /** | ||
| * @brief Get CPU frequency | ||
| * | ||
| * @return CPU frequency in Hz | ||
| */ | ||
| uint32_t stub_target_get_cpu_freq(void); | ||
|
|
||
| /** | ||
| * @brief Get APB frequency | ||
| * | ||
| * @return APB frequency in Hz | ||
| */ | ||
| uint32_t stub_target_get_apb_freq(void); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,14 @@ | |
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| #include <stddef.h> | ||
| #include <target/clock.h> | ||
| #include <target/uart.h> | ||
|
|
||
| extern void esp_rom_set_cpu_ticks_per_us(uint32_t ticks_per_us); | ||
| extern uint32_t esp_rom_get_cpu_freq(void); | ||
| extern void esp_rom_uart_set_as_console(uint8_t uart_no); | ||
| extern void esp_rom_uart_tx_wait_idle(uint8_t uart_num); | ||
| extern void esp_rom_uart_div_modify(uint8_t uart_no, uint32_t divisor); | ||
| extern void esp_rom_uart_flush_tx(uint8_t uart_no); | ||
| extern uint32_t esp_rom_get_xtal_freq(void); | ||
|
|
||
| void __attribute__((weak)) stub_target_uart_wait_idle(uint8_t uart_num) | ||
| { | ||
|
|
@@ -23,20 +23,23 @@ void __attribute__((weak)) stub_target_uart_wait_idle(uint8_t uart_num) | |
|
|
||
| void __attribute__((weak)) stub_target_uart_init(uint8_t uart_num) | ||
| { | ||
| esp_rom_set_cpu_ticks_per_us(esp_rom_get_cpu_freq() / 1000000); | ||
| stub_target_rom_uart_attach(NULL); | ||
| uint32_t clock = esp_rom_get_cpu_freq(); | ||
| uint32_t clock = esp_rom_get_xtal_freq(); | ||
| stub_target_rom_uart_init(uart_num, clock); | ||
| esp_rom_uart_set_as_console(uart_num); | ||
| } | ||
|
|
||
| void __attribute__((weak)) stub_target_uart_rominit_set_baudrate(uint8_t uart_num, uint32_t baudrate) | ||
| { | ||
| uint32_t clock = esp_rom_get_cpu_freq() << 4; | ||
| uint32_t divisor = clock / baudrate; | ||
| extern void stub_lib_delay_us(uint32_t us); | ||
|
Collaborator
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. #include <esp-stub-lib/rom_wrappers.h> Or without wrapper |
||
|
|
||
| stub_lib_delay_us(5 * 1000); | ||
|
|
||
| uint32_t clk_div = (esp_rom_get_xtal_freq() << 4) / baudrate; | ||
| stub_target_uart_wait_idle(uart_num); | ||
| esp_rom_uart_div_modify(uart_num, divisor); | ||
| // TODO: Consider decimal part | ||
| esp_rom_uart_div_modify(uart_num, clk_div); | ||
|
|
||
| stub_lib_delay_us(5 * 1000); | ||
| } | ||
|
|
||
| void __attribute__((weak)) stub_target_uart_tx_flush(uint8_t uart_no) | ||
|
|
||
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 need to include