Skip to content

Commit 6c03de3

Browse files
committed
Merge branch 'feature/dis_wdt' into 'main'
Disable WDTs, add flashing over JTAG See merge request idf/esp32c3-direct-boot-example!3
2 parents 4fdf1ab + fbd8572 commit 6c03de3

File tree

12 files changed

+75
-16
lines changed

12 files changed

+75
-16
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ To debug the examples using JTAG and GDB, follow these steps:
102102
2. Add openocd to `PATH`
103103
3. Build one of the examples (for instance, `blink`), then launch GDB like this:
104104
```
105-
riscv-none-elf-gdb -x ../../gdbinit build/blink
105+
riscv-none-elf-gdb -x gdbinit build/blink
106106
```
107-
This will use the provided [gdbinit](gdbinit) file to:
107+
This will use the provided gdbinit file to:
108108
- Launch OpenOCD in pipe mode. Adjust the `gdbinit` file if you need to change OpenOCD launch configuration. You can also launch OpenOCD manually, in that case use `target extended-remote :3333` in `gdbinit`.
109+
- Flash the program over JTAG
109110
- Reset the target
110111
- Set a temporary breakpoint at `main`
111112
- Run until the breakpoint

examples/blink/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cmake_minimum_required(VERSION 3.12)
2-
include(FetchContent)
32

43
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../)
54
set(CMAKE_TOOLCHAIN_FILE ${ROOT_DIR}/toolchain-rv32.cmake)
@@ -9,14 +8,14 @@ project(blink)
98
add_executable(blink blink.c)
109

1110
add_subdirectory(${ROOT_DIR}/common common)
12-
add_subdirectory(hal)
11+
add_subdirectory(${ROOT_DIR}/hal hal)
1312

1413
target_link_libraries(blink PRIVATE common hal)
1514

1615
target_compile_options(blink PRIVATE -g -Og)
1716
target_link_options(blink PRIVATE -g)
1817

19-
target_compile_options(blink PUBLIC -Wall -Werror -Wextra)
18+
target_compile_options(blink PRIVATE -Wall -Werror -Wextra)
2019

2120
include(${ROOT_DIR}/utils.cmake)
2221
add_linker_scripts(blink)

examples/blink/blink.c

+12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
#include <stdio.h>
22
#include "hal/gpio_hal.h"
3+
#include "hal/wdt_hal.h"
34

45
static void delay(void);
56

67
int main(void)
78
{
9+
// Disable the watchdogs
10+
wdt_hal_context_t rwdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
11+
wdt_hal_write_protect_disable(&rwdt_ctx);
12+
wdt_hal_disable(&rwdt_ctx);
13+
wdt_hal_set_flashboot_en(&rwdt_ctx, false);
14+
wdt_hal_context_t mwdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
15+
wdt_hal_write_protect_disable(&mwdt_ctx);
16+
wdt_hal_disable(&mwdt_ctx);
17+
wdt_hal_set_flashboot_en(&mwdt_ctx, false);
18+
// Super WDT is still enabled; no HAL API for it yet
19+
820
// Connect an LED between 3V3 and GPIO2.
921
// Note that the LED on ESP32-C3-DevKitM-1 is a addressable one,
1022
// so it can't be used with this example.

examples/blink/gdbinit

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set remotetimeout 10
2+
target extended-remote | openocd -c "gdb_port pipe" -c "set ESP_RTOS none" -f "board/esp32c3-builtin.cfg" -c "init; reset halt"
3+
mon gdb_breakpoint_override hard
4+
mon flash write_image build/blink.bin 0 bin
5+
mon reset halt
6+
tb main
7+
c

examples/blink/hal/README.md

-3
This file was deleted.

examples/hello_world/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ project(hello_world)
88
add_executable(hello_world hello_world.c)
99

1010
add_subdirectory(${ROOT_DIR}/common common)
11-
target_link_libraries(hello_world PRIVATE common)
11+
add_subdirectory(${ROOT_DIR}/hal hal)
1212

13-
target_compile_options(hello_world PUBLIC -Wall -Werror -Wextra)
13+
target_link_libraries(hello_world PRIVATE common hal)
14+
15+
target_compile_options(hello_world PRIVATE -g -Og)
16+
target_link_options(hello_world PRIVATE -g)
17+
18+
target_compile_options(hello_world PRIVATE -Wall -Werror -Wextra)
1419

1520
include(${ROOT_DIR}/utils.cmake)
1621
add_linker_scripts(hello_world)

examples/hello_world/gdbinit

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set remotetimeout 10
2+
target extended-remote | openocd -c "gdb_port pipe" -c "set ESP_RTOS none" -f "board/esp32c3-builtin.cfg" -c "init; reset halt"
3+
mon gdb_breakpoint_override hard
4+
mon flash write_image build/hello_world.bin 0 bin
5+
mon reset halt
6+
tb main
7+
c

examples/hello_world/hello_world.c

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
#include <stdio.h>
2+
#include "hal/wdt_hal.h"
3+
4+
static void delay(void);
25

36
int main(void)
47
{
5-
printf("Hello, world!\n");
8+
// Disable the watchdogs
9+
wdt_hal_context_t mwdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
10+
wdt_hal_write_protect_disable(&mwdt_ctx);
11+
wdt_hal_disable(&mwdt_ctx);
12+
wdt_hal_set_flashboot_en(&mwdt_ctx, false);
13+
wdt_hal_context_t rwdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
14+
wdt_hal_write_protect_disable(&rwdt_ctx);
15+
wdt_hal_disable(&rwdt_ctx);
16+
wdt_hal_set_flashboot_en(&rwdt_ctx, false);
17+
// Super WDT is still enabled; no HAL API for it yet
18+
19+
while(1) {
20+
printf("Hello, world!\n");
21+
delay();
22+
}
623
return 0;
724
}
25+
26+
static void delay(void)
27+
{
28+
for (int i = 0; i < 300000; i++) {
29+
asm volatile ("nop");
30+
}
31+
}

gdbinit

-5
This file was deleted.

examples/blink/hal/CMakeLists.txt renamed to hal/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include(FetchContent)
12
message(STATUS "Downloading esp-hal-components...")
23
FetchContent_Declare(
34
esp-hal-components
@@ -33,12 +34,16 @@ target_include_directories(hal PUBLIC
3334
${esp_hal_components_srcdir}/components/hal/platform_port/include
3435
# FIXME: soc component depends on esp_common for ESP_ASSERT
3536
${esp_hal_components_srcdir}/components/esp_common/include
37+
# FIXME: hal component depends on esp_rom due to efuse_ll.h
38+
${esp_hal_components_srcdir}/components/esp_rom/include
39+
${esp_hal_components_srcdir}/components/esp_rom/${target}
3640
${config_dir}
3741
)
3842

3943
target_sources(hal PRIVATE
4044
${esp_hal_components_srcdir}/components/soc/${target}/gpio_periph.c
4145
${esp_hal_components_srcdir}/components/hal/gpio_hal.c
46+
${esp_hal_components_srcdir}/components/hal/wdt_hal_iram.c
4247
)
4348

4449
# FIXME: hal component can't be compiled with -Wall -Wextra -Werror:

hal/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This component provides a HAL for functions such as:
2+
* GPIO
3+
* WDT
4+
5+
So that we don't have to implement the HAL from scratch, the source from https://github.com/espressif/esp-hal-components/tree/sync-3-master is used. Since the upstream CMakeLists.txt files can't yet be used a normal CMake library, the [CMakeLists.txt](CMakeLists.txt) of this component manually adds the right set of include directories and source files to the build.
6+
7+
Note: this is done just for demonstration purposes, to be used in the examples. This component isn't intended to provide the HAL for all peripherals and all chips.
File renamed without changes.

0 commit comments

Comments
 (0)