Skip to content

Commit

Permalink
Merge branch 'feature/dis_wdt' into 'main'
Browse files Browse the repository at this point in the history
Disable WDTs, add flashing over JTAG

See merge request idf/esp32c3-direct-boot-example!3
  • Loading branch information
igrr committed Jul 17, 2023
2 parents 4fdf1ab + fbd8572 commit 6c03de3
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ To debug the examples using JTAG and GDB, follow these steps:
2. Add openocd to `PATH`
3. Build one of the examples (for instance, `blink`), then launch GDB like this:
```
riscv-none-elf-gdb -x ../../gdbinit build/blink
riscv-none-elf-gdb -x gdbinit build/blink
```
This will use the provided [gdbinit](gdbinit) file to:
This will use the provided gdbinit file to:
- 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`.
- Flash the program over JTAG
- Reset the target
- Set a temporary breakpoint at `main`
- Run until the breakpoint
Expand Down
5 changes: 2 additions & 3 deletions examples/blink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.12)
include(FetchContent)

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

add_subdirectory(${ROOT_DIR}/common common)
add_subdirectory(hal)
add_subdirectory(${ROOT_DIR}/hal hal)

target_link_libraries(blink PRIVATE common hal)

target_compile_options(blink PRIVATE -g -Og)
target_link_options(blink PRIVATE -g)

target_compile_options(blink PUBLIC -Wall -Werror -Wextra)
target_compile_options(blink PRIVATE -Wall -Werror -Wextra)

include(${ROOT_DIR}/utils.cmake)
add_linker_scripts(blink)
Expand Down
12 changes: 12 additions & 0 deletions examples/blink/blink.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#include <stdio.h>
#include "hal/gpio_hal.h"
#include "hal/wdt_hal.h"

static void delay(void);

int main(void)
{
// Disable the watchdogs
wdt_hal_context_t rwdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
wdt_hal_write_protect_disable(&rwdt_ctx);
wdt_hal_disable(&rwdt_ctx);
wdt_hal_set_flashboot_en(&rwdt_ctx, false);
wdt_hal_context_t mwdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&mwdt_ctx);
wdt_hal_disable(&mwdt_ctx);
wdt_hal_set_flashboot_en(&mwdt_ctx, false);
// Super WDT is still enabled; no HAL API for it yet

// Connect an LED between 3V3 and GPIO2.
// Note that the LED on ESP32-C3-DevKitM-1 is a addressable one,
// so it can't be used with this example.
Expand Down
7 changes: 7 additions & 0 deletions examples/blink/gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set remotetimeout 10
target extended-remote | openocd -c "gdb_port pipe" -c "set ESP_RTOS none" -f "board/esp32c3-builtin.cfg" -c "init; reset halt"
mon gdb_breakpoint_override hard
mon flash write_image build/blink.bin 0 bin
mon reset halt
tb main
c
3 changes: 0 additions & 3 deletions examples/blink/hal/README.md

This file was deleted.

9 changes: 7 additions & 2 deletions examples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ project(hello_world)
add_executable(hello_world hello_world.c)

add_subdirectory(${ROOT_DIR}/common common)
target_link_libraries(hello_world PRIVATE common)
add_subdirectory(${ROOT_DIR}/hal hal)

target_compile_options(hello_world PUBLIC -Wall -Werror -Wextra)
target_link_libraries(hello_world PRIVATE common hal)

target_compile_options(hello_world PRIVATE -g -Og)
target_link_options(hello_world PRIVATE -g)

target_compile_options(hello_world PRIVATE -Wall -Werror -Wextra)

include(${ROOT_DIR}/utils.cmake)
add_linker_scripts(hello_world)
Expand Down
7 changes: 7 additions & 0 deletions examples/hello_world/gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set remotetimeout 10
target extended-remote | openocd -c "gdb_port pipe" -c "set ESP_RTOS none" -f "board/esp32c3-builtin.cfg" -c "init; reset halt"
mon gdb_breakpoint_override hard
mon flash write_image build/hello_world.bin 0 bin
mon reset halt
tb main
c
26 changes: 25 additions & 1 deletion examples/hello_world/hello_world.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
#include <stdio.h>
#include "hal/wdt_hal.h"

static void delay(void);

int main(void)
{
printf("Hello, world!\n");
// Disable the watchdogs
wdt_hal_context_t mwdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
wdt_hal_write_protect_disable(&mwdt_ctx);
wdt_hal_disable(&mwdt_ctx);
wdt_hal_set_flashboot_en(&mwdt_ctx, false);
wdt_hal_context_t rwdt_ctx = RWDT_HAL_CONTEXT_DEFAULT();
wdt_hal_write_protect_disable(&rwdt_ctx);
wdt_hal_disable(&rwdt_ctx);
wdt_hal_set_flashboot_en(&rwdt_ctx, false);
// Super WDT is still enabled; no HAL API for it yet

while(1) {
printf("Hello, world!\n");
delay();
}
return 0;
}

static void delay(void)
{
for (int i = 0; i < 300000; i++) {
asm volatile ("nop");
}
}
5 changes: 0 additions & 5 deletions gdbinit

This file was deleted.

5 changes: 5 additions & 0 deletions examples/blink/hal/CMakeLists.txt → hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include(FetchContent)
message(STATUS "Downloading esp-hal-components...")
FetchContent_Declare(
esp-hal-components
Expand Down Expand Up @@ -33,12 +34,16 @@ target_include_directories(hal PUBLIC
${esp_hal_components_srcdir}/components/hal/platform_port/include
# FIXME: soc component depends on esp_common for ESP_ASSERT
${esp_hal_components_srcdir}/components/esp_common/include
# FIXME: hal component depends on esp_rom due to efuse_ll.h
${esp_hal_components_srcdir}/components/esp_rom/include
${esp_hal_components_srcdir}/components/esp_rom/${target}
${config_dir}
)

target_sources(hal PRIVATE
${esp_hal_components_srcdir}/components/soc/${target}/gpio_periph.c
${esp_hal_components_srcdir}/components/hal/gpio_hal.c
${esp_hal_components_srcdir}/components/hal/wdt_hal_iram.c
)

# FIXME: hal component can't be compiled with -Wall -Wextra -Werror:
Expand Down
7 changes: 7 additions & 0 deletions hal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This component provides a HAL for functions such as:
* GPIO
* WDT

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.

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 comments on commit 6c03de3

Please sign in to comment.