From 3870b86a31f4fdb19eea20628673492d46c924ac Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sun, 15 Mar 2020 10:46:40 -0400 Subject: [PATCH] JTAG debugging script work now. - release under the build directory, a number of new files will be written with prefixes like flash_dbg_* and dbg_*. These can be used to debug using jtag. the flash_dbg* files will flash the binaries to the dbg target and, if necessary, set the offset for debugging (e.g. when running squeezelite, the debugger needs to know that it's running in an offset that's not the same as recovery). These files can be used in a command like : xtensa-esp32-elf-gdb.exe --command=build/flash_dbg_squeezelite --- components/driver_bt/bt_app_core.c | 2 +- components/driver_bt/bt_app_sink.c | 62 +++++++++++---------------- components/driver_bt/bt_app_sink.h | 2 +- components/driver_bt/bt_app_source.c | 2 +- components/squeezelite/CMakeLists.txt | 3 +- components/squeezelite/component.mk | 2 +- generate_debug_scripts.cmake | 9 ++-- squeezelite.cmake | 16 ++++--- 8 files changed, 46 insertions(+), 52 deletions(-) diff --git a/components/driver_bt/bt_app_core.c b/components/driver_bt/bt_app_core.c index 7c189699..a9b1b8f1 100644 --- a/components/driver_bt/bt_app_core.c +++ b/components/driver_bt/bt_app_core.c @@ -6,7 +6,7 @@ CONDITIONS OF ANY KIND, either express or implied. */ -#include "platform_bt_core.h" +#include "bt_app_core.h" #include #include "esp_system.h" diff --git a/components/driver_bt/bt_app_sink.c b/components/driver_bt/bt_app_sink.c index e0d4d34d..5e2cc5c2 100644 --- a/components/driver_bt/bt_app_sink.c +++ b/components/driver_bt/bt_app_sink.c @@ -22,7 +22,7 @@ #include "esp_a2dp_api.h" #include "esp_avrc_api.h" #include "nvs.h" -#include "config.h" +#include "platform_config.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "trace.h" @@ -71,7 +71,8 @@ static esp_avrc_rn_evt_cap_mask_t s_avrc_peer_rn_cap; static _lock_t s_volume_lock; static uint8_t s_volume = 0; static bool s_volume_notify; -static enum { AUDIO_IDLE, AUDIO_CONNECTED, AUDIO_PLAYING } s_audio = AUDIO_IDLE; +static bool s_playing = false; +static enum { AUDIO_IDLE, AUDIO_CONNECTED, AUDIO_ACTIVATED } s_audio = AUDIO_IDLE; static int s_sample_rate; static int tl; @@ -101,7 +102,7 @@ static void bt_volume_down(void) { } static void bt_toggle(void) { - if (s_audio == AUDIO_PLAYING) esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); + if (s_playing) esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); else esp_avrc_ct_send_passthrough_cmd(tl++, ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STATE_PRESSED); } @@ -138,14 +139,14 @@ const static actrls_t controls = { /* disconnection */ void bt_disconnect(void) { displayer_control(DISPLAYER_SHUTDOWN); - if (s_audio == AUDIO_PLAYING) esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); + if (s_playing) esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); actrls_unset(); - ESP_LOGI(BT_AV_TAG, "forced disconnection %d", s_audio); + ESP_LOGI(BT_AV_TAG, "forced disconnection"); } /* update metadata if any */ void update_metadata(bool force) { - if ((s_metadata.updated || force) && s_audio == AUDIO_PLAYING) { + if ((s_metadata.updated || force) && s_audio == AUDIO_ACTIVATED) { (*bt_app_a2d_cmd_cb)(BT_SINK_PROGRESS, -1, s_metadata.duration); (*bt_app_a2d_cmd_cb)(BT_SINK_METADATA, s_metadata.artist, s_metadata.album, s_metadata.title); s_metadata.updated = false; @@ -289,17 +290,18 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param) // verify that we can take control if ((*bt_app_a2d_cmd_cb)(BT_SINK_AUDIO_STARTED, s_sample_rate)) { + // resynchronize events as¨PLAY might be sent before STARTED ... + s_audio = AUDIO_ACTIVATED; - // if PLAY is sent before AUDIO_STARTED, generate the event here - s_audio = AUDIO_PLAYING; - (*bt_app_a2d_cmd_cb)(BT_SINK_PLAY); + // send PLAY there, in case it was sent before AUDIO_STATE + if (s_playing) (*bt_app_a2d_cmd_cb)(BT_SINK_PLAY); // force metadata update update_metadata(true); actrls_set(controls, NULL); - } else { - // if decoder is busy, stop it (would be better to not ACK this command, but don't know how) + } else if (s_playing) { + // if decoder is busy but BT is playing, stop it (would be better to not ACK this command, but don't know how) esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); } } else if (ESP_A2D_AUDIO_STATE_STOPPED == a2d->audio_stat.state || @@ -380,33 +382,19 @@ void bt_av_notify_evt_handler(uint8_t event_id, esp_avrc_rn_param_t *event_param break; case ESP_AVRC_RN_PLAY_STATUS_CHANGE: ESP_LOGI(BT_AV_TAG, "Playback status changed: 0x%x", event_parameter->playback); - if (s_audio != AUDIO_IDLE) { - switch (event_parameter->playback) { - case ESP_AVRC_PLAYBACK_PLAYING: - // if decoder is busy then stop (would be better to not ACK this command, but don't know how) - if (s_audio != AUDIO_PLAYING && !(*bt_app_a2d_cmd_cb)(BT_SINK_PLAY)) { - ESP_LOGW(BT_AV_TAG, "Player busy with another controller"); - esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); - } else { - s_audio = AUDIO_PLAYING; - update_metadata(false); - } - break; - case ESP_AVRC_PLAYBACK_PAUSED: - s_audio = AUDIO_CONNECTED; - (*bt_app_a2d_cmd_cb)(BT_SINK_PAUSE); - break; - case ESP_AVRC_PLAYBACK_STOPPED: - s_audio = AUDIO_CONNECTED; - (*bt_app_a2d_cmd_cb)(BT_SINK_PROGRESS, 0, -1); - (*bt_app_a2d_cmd_cb)(BT_SINK_STOP); - break; - default: - ESP_LOGI(BT_AV_TAG, "Un-handled event"); - break; + // re-synchronize events + s_playing = (event_parameter->playback == ESP_AVRC_PLAYBACK_PLAYING); + if (event_parameter->playback == ESP_AVRC_PLAYBACK_PLAYING && s_audio != AUDIO_IDLE) { + // if decoder is busy then stop (would be better to not ACK this command, but don't know how) + if (s_audio == AUDIO_CONNECTED || !(*bt_app_a2d_cmd_cb)(BT_SINK_PLAY)) { + esp_avrc_ct_send_passthrough_cmd(tl++ & 0x0f, ESP_AVRC_PT_CMD_STOP, ESP_AVRC_PT_CMD_STATE_PRESSED); + } else { + update_metadata(false); } - } else { - ESP_LOGW(BT_AV_TAG, "Not yet in BT connected mode: 0x%x", event_parameter->playback); + } else if (event_parameter->playback == ESP_AVRC_PLAYBACK_PAUSED) (*bt_app_a2d_cmd_cb)(BT_SINK_PAUSE); + else if (event_parameter->playback == ESP_AVRC_PLAYBACK_STOPPED) { + (*bt_app_a2d_cmd_cb)(BT_SINK_PROGRESS, 0, -1); + (*bt_app_a2d_cmd_cb)(BT_SINK_STOP); } bt_av_playback_changed(); break; diff --git a/components/driver_bt/bt_app_sink.h b/components/driver_bt/bt_app_sink.h index 8be8f57a..d02aa51c 100644 --- a/components/driver_bt/bt_app_sink.h +++ b/components/driver_bt/bt_app_sink.h @@ -11,7 +11,7 @@ #include -#include "platform_bt_core.h" +#include "bt_app_core.h" typedef enum { BT_SINK_CONNECTED, BT_SINK_DISCONNECTED, BT_SINK_AUDIO_STARTED, BT_SINK_AUDIO_STOPPED, BT_SINK_PLAY, BT_SINK_STOP, BT_SINK_PAUSE, BT_SINK_RATE, BT_SINK_VOLUME, BT_SINK_METADATA, BT_SINK_PROGRESS } bt_sink_cmd_t; diff --git a/components/driver_bt/bt_app_source.c b/components/driver_bt/bt_app_source.c index ed4c28d8..84f5bba1 100644 --- a/components/driver_bt/bt_app_source.c +++ b/components/driver_bt/bt_app_source.c @@ -3,7 +3,7 @@ #include #include -#include "platform_bt_core.h" +#include "bt_app_core.h" #include "esp_log.h" #include "esp_bt.h" #include "esp_bt_device.h" diff --git a/components/squeezelite/CMakeLists.txt b/components/squeezelite/CMakeLists.txt index 0e58cef4..4dc5a2f3 100644 --- a/components/squeezelite/CMakeLists.txt +++ b/components/squeezelite/CMakeLists.txt @@ -8,8 +8,7 @@ idf_component_register( SRC_DIRS . external a1s tas57xx esp_common esp-dsp platform_config - bluetooth - + driver_bt services raop display diff --git a/components/squeezelite/component.mk b/components/squeezelite/component.mk index ed38471f..c30f0ffa 100644 --- a/components/squeezelite/component.mk +++ b/components/squeezelite/component.mk @@ -13,7 +13,7 @@ CFLAGS += -O3 -DLINKALL -DLOOPBACK -DNO_FAAD -DRESAMPLE16 -DEMBEDDED -DTREMOR_ON -I$(COMPONENT_PATH)/../tools \ -I$(COMPONENT_PATH)/../codecs/inc/opus \ -I$(COMPONENT_PATH)/../codecs/inc/opusfile \ - -I$(COMPONENT_PATH)/../bluetooth \ + -I$(COMPONENT_PATH)/../driver_bt \ -I$(COMPONENT_PATH)/../raop \ -I$(COMPONENT_PATH)/../services diff --git a/generate_debug_scripts.cmake b/generate_debug_scripts.cmake index 1088ccee..786dd0b9 100644 --- a/generate_debug_scripts.cmake +++ b/generate_debug_scripts.cmake @@ -30,7 +30,7 @@ function(___output_debug_target bin_name ) if( ${CMAKE_MATCH_COUNT} GREATER 0 ) set(found_offset "${CMAKE_MATCH_1}") set(found_bin "${CMAKE_MATCH_2}") - if( ( "${bin_name}" MATCHES "${found_bin}" ) OR ( "${bin_name}" STREQUAL "_" ) ) + if( ( "${found_bin}" MATCHES "${bin_name}" ) OR ( "${bin_name}" STREQUAL "_" ) ) list(APPEND flash_dbg_cmds "${line_prefix}${found_bin} ${found_offset}") endif() if( ( "${bin_name}" MATCHES "recovery" ) AND ( "${found_bin}" MATCHES "ota_data_initial" ) ) @@ -38,7 +38,7 @@ function(___output_debug_target bin_name ) list(APPEND flash_dbg_cmds "${line_prefix}${found_bin} ${found_offset}") endif() - if( ( "${bin_name}" MATCHES "${found_bin}" ) ) + if( ( "${found_bin}" MATCHES "${bin_name}" ) ) list(APPEND dbg_cmds "mon esp32 appoffset ${found_offset}") endif() endif() @@ -58,12 +58,13 @@ function(___output_debug_target bin_name ) STRING(REGEX REPLACE ";" "\n" full_flash_dbg_cmds "${full_flash_dbg_cmds}") message("Writing: ${debug_file} with ${full_dbg_cmds}") - file(GENERATE OUTPUT "${debug_file}" CONTENT "${full_dbg_cmds}") + file(WRITE "${debug_file}" "${full_dbg_cmds}") message("Writing: ${flash_debug_file} with : ${full_flash_dbg_cmds}") - file(GENERATE OUTPUT "${flash_debug_file}" CONTENT "${full_flash_dbg_cmds}") + file(WRITE "${flash_debug_file}" "${full_flash_dbg_cmds}") endfunction() + message("Generating debug script files") ___output_debug_target("_") ___output_debug_target("squeezelite") diff --git a/squeezelite.cmake b/squeezelite.cmake index 41d6ec7b..18b542dd 100644 --- a/squeezelite.cmake +++ b/squeezelite.cmake @@ -53,12 +53,18 @@ function(___create_new_target target_name) endfunction() + + ___create_new_target(squeezelite ) ___register_flash(squeezelite ota_0) -add_custom_command( - TARGET "squeezelite.elf" - POST_BUILD - COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake" - ) +#add_custom_target(_jtag_scripts ALL +# BYPRODUCTS flash_dbg_project_args +# COMMAND ${CMAKE_COMMAND} +# DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build/partition_table/partition-table.bin" ) +add_custom_target(_jtag_scripts ALL + BYPRODUCTS "flash_dbg_project_args" + POST_BUILD + COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake") +add_dependencies(partition_table _jtag_scripts)