From b9773d0b9c42b1cce7fea6baac6de9c8f5d77b5f Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Thu, 4 Jun 2020 20:44:50 +0200 Subject: [PATCH] Reorganised project source directories (Closes #976) --- CMakeLists.txt | 60 ++--- inc/CMakeLists.txt | 9 + {include => inc}/stlink.h | 0 {include => inc}/stm32.h | 0 {include/stlink => inc}/version.h.in | 0 include/CMakeLists.txt | 9 - {include/stlink => src}/backend.h | 0 {include/stlink => src}/commands.h | 0 src/common.c | 6 +- src/{ => mmap}/mmap.c | 0 src/{ => mmap}/mmap.h | 0 {include/stlink => src}/reg.h | 0 src/{tools => st-flash}/flash.c | 2 +- .../stlink/tools => src/st-flash}/flash.h | 0 src/{tools => st-flash}/flash_opts.c | 2 +- src/{tools => st-info}/info.c | 0 src/{ => st-link-lib}/chipid.c | 2 +- {include/stlink => src/st-link-lib}/chipid.h | 0 src/{ => st-link-lib}/flash_loader.c | 243 +++++++++--------- .../stlink => src/st-link-lib}/flash_loader.h | 0 src/{ => st-link-lib}/logging.c | 0 src/{ => st-link-lib}/logging.h | 0 src/{ => st-link-lib}/md5.c | 0 src/{ => st-link-lib}/md5.h | 0 src/{ => st-link-lib}/sg.c | 1 + src/{ => st-link-lib}/sg.h | 2 +- src/{ => st-link-lib}/usb.c | 3 +- src/{ => st-link-lib}/usb.h | 2 +- src/st-util/semihosting.c | 59 ++--- tests/CMakeLists.txt | 2 +- 30 files changed, 187 insertions(+), 215 deletions(-) create mode 100644 inc/CMakeLists.txt rename {include => inc}/stlink.h (100%) rename {include => inc}/stm32.h (100%) rename {include/stlink => inc}/version.h.in (100%) delete mode 100644 include/CMakeLists.txt rename {include/stlink => src}/backend.h (100%) rename {include/stlink => src}/commands.h (100%) rename src/{ => mmap}/mmap.c (100%) rename src/{ => mmap}/mmap.h (100%) rename {include/stlink => src}/reg.h (100%) rename src/{tools => st-flash}/flash.c (99%) rename {include/stlink/tools => src/st-flash}/flash.h (100%) rename src/{tools => st-flash}/flash_opts.c (99%) rename src/{tools => st-info}/info.c (100%) rename src/{ => st-link-lib}/chipid.c (99%) rename {include/stlink => src/st-link-lib}/chipid.h (100%) rename src/{ => st-link-lib}/flash_loader.c (71%) rename {include/stlink => src/st-link-lib}/flash_loader.h (100%) rename src/{ => st-link-lib}/logging.c (100%) rename src/{ => st-link-lib}/logging.h (100%) rename src/{ => st-link-lib}/md5.c (100%) rename src/{ => st-link-lib}/md5.h (100%) rename src/{ => st-link-lib}/sg.c (99%) rename src/{ => st-link-lib}/sg.h (98%) rename src/{ => st-link-lib}/usb.c (99%) rename src/{ => st-link-lib}/usb.h (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0538f3b14..08543f35f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,43 +81,41 @@ endif () ## Define include directories to avoid absolute paths for header defines include_directories(${LIBUSB_INCLUDE_DIR}) -# ==== -include_directories(${PROJECT_SOURCE_DIR}/include) ### TODO: Clean this up... -include_directories(${PROJECT_BINARY_DIR}/include/stlink) -include_directories(${PROJECT_SOURCE_DIR}/include/stlink) -include_directories(${PROJECT_SOURCE_DIR}/include/stlink/tools) -# ==== +include_directories(${PROJECT_SOURCE_DIR}/inc) # contains top-level header files +include_directories(${PROJECT_BINARY_DIR}/inc) # contains version.h include_directories(src) -include_directories(src/tools) ### TODO: Clean this up... +include_directories(src/mmap) +include_directories(src/st-flash) +include_directories(src/st-link-lib) set(STLINK_HEADERS - include/stlink.h - include/stlink/backend.h - include/stlink/chipid.h - include/stlink/commands.h - include/stlink/flash_loader.h - include/stlink/reg.h - src/logging.h - src/md5.h - src/sg.h - src/usb.h + inc/stlink.h + src/backend.h + src/commands.h + src/reg.h + src/st-link-lib/chipid.h + src/st-link-lib/flash_loader.h + src/st-link-lib/logging.h + src/st-link-lib/md5.h + src/st-link-lib/sg.h + src/st-link-lib/usb.h ) set(STLINK_SOURCE src/common.c - src/chipid.c - src/flash_loader.c - src/logging.c - src/md5.c - src/sg.c - src/usb.c + src/st-link-lib/chipid.c + src/st-link-lib/flash_loader.c + src/st-link-lib/logging.c + src/st-link-lib/md5.c + src/st-link-lib/sg.c + src/st-link-lib/usb.c ) if (WIN32 OR MINGW OR MSYS) include_directories(src/mingw) - set(STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c") - set(STLINK_HEADERS "${STLINK_HEADERS};src/mmap.h;src/mingw/mingw.h") + set(STLINK_SOURCE "${STLINK_SOURCE};src/mmap/mmap.c;src/mingw/mingw.c") + set(STLINK_HEADERS "${STLINK_HEADERS};src/mmap/mmap.h;src/mingw/mingw.h") endif () if (MSVC) @@ -221,6 +219,8 @@ install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}) # Build toolset executables ### +set(ST-FLASH_SOURCES src/st-flash/flash.c src/st-flash/flash_opts.c) +set(ST-INFO_SOURCES src/st-info/info.c) set(ST-UTIL_SOURCES src/st-util/gdb-remote.c src/st-util/gdb-server.c src/st-util/semihosting.c) if (MSVC) @@ -228,8 +228,8 @@ if (MSVC) set(ST-UTIL_SOURCES "${ST-UTIL_SOURCES};src/getopt/getopt.c") endif () -add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c) -add_executable(st-info src/tools/info.c) +add_executable(st-flash ${ST-FLASH_SOURCES}) +add_executable(st-info ${ST-INFO_SOURCES}) add_executable(st-util ${ST-UTIL_SOURCES}) if (WIN32 OR APPLE) @@ -267,11 +267,7 @@ endif () # Additional build tasks ### -# ==== -add_subdirectory(include) # contains subordinate CMakeLists for version config and old header includes - ### TODO: Clean this up ... -# ==== - +add_subdirectory(inc) # contains subordinate CMakeLists for version config add_subdirectory(src/stlink-gui) # contains subordinate CMakeLists to build GUI add_subdirectory(tests) # contains subordinate CMakeLists to build test executables add_subdirectory(cmake/packaging) # contains subordinate CMakeLists to build packages diff --git a/inc/CMakeLists.txt b/inc/CMakeLists.txt new file mode 100644 index 000000000..66af7e33f --- /dev/null +++ b/inc/CMakeLists.txt @@ -0,0 +1,9 @@ +configure_file( + "${PROJECT_SOURCE_DIR}/inc/version.h.in" + "${CMAKE_BINARY_DIR}/inc/version.h" + ) + +file(GLOB STLINK_HEADERS "src/st-link-lib/*.h" "${CMAKE_BINARY_DIR}/inc/version.h") +install(FILES ${STLINK_HEADERS} DESTINATION ${STLINK_INCLUDE_PATH}) +install(FILES ${CMAKE_SOURCE_DIR}/inc/stlink.h DESTINATION ${STLINK_INCLUDE_PATH}) +install(FILES ${CMAKE_SOURCE_DIR}/inc/stm32.h DESTINATION ${STLINK_INCLUDE_PATH}) diff --git a/include/stlink.h b/inc/stlink.h similarity index 100% rename from include/stlink.h rename to inc/stlink.h diff --git a/include/stm32.h b/inc/stm32.h similarity index 100% rename from include/stm32.h rename to inc/stm32.h diff --git a/include/stlink/version.h.in b/inc/version.h.in similarity index 100% rename from include/stlink/version.h.in rename to inc/version.h.in diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt deleted file mode 100644 index 6cf397659..000000000 --- a/include/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -configure_file( - "${PROJECT_SOURCE_DIR}/include/stlink/version.h.in" - "${CMAKE_BINARY_DIR}/include/stlink/version.h" - ) - -file(GLOB STLINK_HEADERS "stlink/*.h" "${CMAKE_BINARY_DIR}/include/stlink/*.h") -install(FILES ${CMAKE_SOURCE_DIR}/include/stlink.h DESTINATION ${STLINK_INCLUDE_PATH}) -install(FILES ${CMAKE_SOURCE_DIR}/include/stm32.h DESTINATION ${STLINK_INCLUDE_PATH}) -install(FILES ${STLINK_HEADERS} DESTINATION ${STLINK_INCLUDE_PATH}/stlink) diff --git a/include/stlink/backend.h b/src/backend.h similarity index 100% rename from include/stlink/backend.h rename to src/backend.h diff --git a/include/stlink/commands.h b/src/commands.h similarity index 100% rename from include/stlink/commands.h rename to src/commands.h diff --git a/src/common.c b/src/common.c index e8f7cebc6..fb669e255 100644 --- a/src/common.c +++ b/src/common.c @@ -12,9 +12,9 @@ #include #include -#include "mmap.h" -#include "logging.h" -#include "md5.h" +#include +#include +#include #ifndef O_BINARY #define O_BINARY 0 diff --git a/src/mmap.c b/src/mmap/mmap.c similarity index 100% rename from src/mmap.c rename to src/mmap/mmap.c diff --git a/src/mmap.h b/src/mmap/mmap.h similarity index 100% rename from src/mmap.h rename to src/mmap/mmap.h diff --git a/include/stlink/reg.h b/src/reg.h similarity index 100% rename from include/stlink/reg.h rename to src/reg.h diff --git a/src/tools/flash.c b/src/st-flash/flash.c similarity index 99% rename from src/tools/flash.c rename to src/st-flash/flash.c index 3a83daf8a..fc62bcf15 100644 --- a/src/tools/flash.c +++ b/src/st-flash/flash.c @@ -9,7 +9,7 @@ #include #include -#include +#include "flash.h" static stlink_t *connected_stlink = NULL; diff --git a/include/stlink/tools/flash.h b/src/st-flash/flash.h similarity index 100% rename from include/stlink/tools/flash.h rename to src/st-flash/flash.h diff --git a/src/tools/flash_opts.c b/src/st-flash/flash_opts.c similarity index 99% rename from src/tools/flash_opts.c rename to src/st-flash/flash_opts.c index c8d7841de..9d8d3225b 100644 --- a/src/tools/flash_opts.c +++ b/src/st-flash/flash_opts.c @@ -2,7 +2,7 @@ #include #include -#include +#include "flash.h" static bool starts_with(const char * str, const char * prefix) { size_t n = strlen(prefix); diff --git a/src/tools/info.c b/src/st-info/info.c similarity index 100% rename from src/tools/info.c rename to src/st-info/info.c diff --git a/src/chipid.c b/src/st-link-lib/chipid.c similarity index 99% rename from src/chipid.c rename to src/st-link-lib/chipid.c index fcc1c55eb..e6a82a2a9 100644 --- a/src/chipid.c +++ b/src/st-link-lib/chipid.c @@ -1,5 +1,5 @@ #include -#include +#include "chipid.h" static const struct stlink_chipid_params devices[] = { { diff --git a/include/stlink/chipid.h b/src/st-link-lib/chipid.h similarity index 100% rename from include/stlink/chipid.h rename to src/st-link-lib/chipid.h diff --git a/src/flash_loader.c b/src/st-link-lib/flash_loader.c similarity index 71% rename from src/flash_loader.c rename to src/st-link-lib/flash_loader.c index a2c5879ce..b97a6edaa 100644 --- a/src/flash_loader.c +++ b/src/st-link-lib/flash_loader.c @@ -3,6 +3,7 @@ #include #include +#include "flash_loader.h" #define FLASH_REGS_BANK2_OFS 0x40 #define FLASH_BANK2_START_ADDR 0x08080000 @@ -11,164 +12,164 @@ /* flashloaders/stm32f0.s -- compiled with thumb2 */ static const uint8_t loader_code_stm32vl[] = { - 0x16, 0x4f, 0x3c, 0x68, - 0x16, 0x4f, 0x3e, 0x68, - 0x36, 0x19, 0x16, 0x4f, - 0x3d, 0x68, 0x2d, 0x19, - 0x4f, 0xf0, 0x01, 0x07, - 0x33, 0x68, 0x3b, 0x43, - 0x33, 0x60, 0x03, 0x88, - 0x0b, 0x80, 0x4f, 0xf0, - 0x02, 0x07, 0xc0, 0x19, - 0xc9, 0x19, 0x4f, 0xf0, - 0x01, 0x07, 0x2b, 0x68, - 0x3b, 0x42, 0xfa, 0xd0, - 0x4f, 0xf0, 0x04, 0x07, - 0x3b, 0x42, 0x04, 0xd1, - 0x4f, 0xf0, 0x01, 0x07, - 0xd2, 0x1b, 0x00, 0x2a, - 0xe6, 0xd1, 0x4f, 0xf0, - 0x01, 0x07, 0x33, 0x68, - 0xbb, 0x43, 0x33, 0x60, - 0x00, 0xbe, 0x00, 0xbf, - 0x00, 0x20, 0x02, 0x40, - 0x10, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x20, - 0x54, 0x00, 0x00, 0x20, + 0x16, 0x4f, 0x3c, 0x68, + 0x16, 0x4f, 0x3e, 0x68, + 0x36, 0x19, 0x16, 0x4f, + 0x3d, 0x68, 0x2d, 0x19, + 0x4f, 0xf0, 0x01, 0x07, + 0x33, 0x68, 0x3b, 0x43, + 0x33, 0x60, 0x03, 0x88, + 0x0b, 0x80, 0x4f, 0xf0, + 0x02, 0x07, 0xc0, 0x19, + 0xc9, 0x19, 0x4f, 0xf0, + 0x01, 0x07, 0x2b, 0x68, + 0x3b, 0x42, 0xfa, 0xd0, + 0x4f, 0xf0, 0x04, 0x07, + 0x3b, 0x42, 0x04, 0xd1, + 0x4f, 0xf0, 0x01, 0x07, + 0xd2, 0x1b, 0x00, 0x2a, + 0xe6, 0xd1, 0x4f, 0xf0, + 0x01, 0x07, 0x33, 0x68, + 0xbb, 0x43, 0x33, 0x60, + 0x00, 0xbe, 0x00, 0xbf, + 0x00, 0x20, 0x02, 0x40, + 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x00, 0x20, + 0x54, 0x00, 0x00, 0x20, 0x58, 0x00, 0x00, 0x20 }; /* flashloaders/stm32f0.s -- thumb1 only, same sequence as for STM32VL, bank ignored */ static const uint8_t loader_code_stm32f0[] = { - 0xc0, 0x46, 0xc0, 0x46, - 0x13, 0x4f, 0x3c, 0x68, - 0x13, 0x4f, 0x3e, 0x68, - 0x36, 0x19, 0x13, 0x4f, - 0x3d, 0x68, 0x2d, 0x19, - 0x12, 0x4f, 0x33, 0x68, - 0x3b, 0x43, 0x33, 0x60, - 0x03, 0x88, 0x0b, 0x80, - 0x10, 0x4f, 0xc0, 0x19, - 0xc9, 0x19, 0x0e, 0x4f, - 0x2b, 0x68, 0x3b, 0x42, - 0xfb, 0xd0, 0x0e, 0x4f, - 0x3b, 0x42, 0x03, 0xd1, - 0x0a, 0x4f, 0xd2, 0x1b, - 0x00, 0x2a, 0xeb, 0xd1, - 0x08, 0x4f, 0x33, 0x68, - 0xbb, 0x43, 0x33, 0x60, - 0x00, 0xbe, 0xc0, 0x46, - 0x00, 0x20, 0x02, 0x40, - 0x10, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, - 0x48, 0x00, 0x00, 0x20, - 0x4c, 0x00, 0x00, 0x20, - 0x50, 0x00, 0x00, 0x20, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, + 0xc0, 0x46, 0xc0, 0x46, + 0x13, 0x4f, 0x3c, 0x68, + 0x13, 0x4f, 0x3e, 0x68, + 0x36, 0x19, 0x13, 0x4f, + 0x3d, 0x68, 0x2d, 0x19, + 0x12, 0x4f, 0x33, 0x68, + 0x3b, 0x43, 0x33, 0x60, + 0x03, 0x88, 0x0b, 0x80, + 0x10, 0x4f, 0xc0, 0x19, + 0xc9, 0x19, 0x0e, 0x4f, + 0x2b, 0x68, 0x3b, 0x42, + 0xfb, 0xd0, 0x0e, 0x4f, + 0x3b, 0x42, 0x03, 0xd1, + 0x0a, 0x4f, 0xd2, 0x1b, + 0x00, 0x2a, 0xeb, 0xd1, + 0x08, 0x4f, 0x33, 0x68, + 0xbb, 0x43, 0x33, 0x60, + 0x00, 0xbe, 0xc0, 0x46, + 0x00, 0x20, 0x02, 0x40, + 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x20, + 0x4c, 0x00, 0x00, 0x20, + 0x50, 0x00, 0x00, 0x20, + 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 }; static const uint8_t loader_code_stm32l[] = { // flashloaders/stm32lx.s - 0x03, 0x68, 0x0b, 0x60, - 0x4f, 0xf0, 0x04, 0x07, - 0x38, 0x44, 0x39, 0x44, - 0x4f, 0xf0, 0x01, 0x07, - 0xd2, 0x1b, 0x00, 0x2a, + 0x03, 0x68, 0x0b, 0x60, + 0x4f, 0xf0, 0x04, 0x07, + 0x38, 0x44, 0x39, 0x44, + 0x4f, 0xf0, 0x01, 0x07, + 0xd2, 0x1b, 0x00, 0x2a, 0xf4, 0xd1, 0x00, 0xbe, }; static const uint8_t loader_code_stm32f4[] = { // flashloaders/stm32f4.s - 0xdf, 0xf8, 0x28, 0xc0, - 0xdf, 0xf8, 0x28, 0xa0, - 0xe2, 0x44, 0x03, 0x68, - 0x0b, 0x60, 0x00, 0xf1, - 0x04, 0x00, 0x01, 0xf1, - 0x04, 0x01, 0xba, 0xf8, - 0x00, 0x30, 0x13, 0xf0, - 0x01, 0x0f, 0xfa, 0xd0, - 0xa2, 0xf1, 0x01, 0x02, - 0x00, 0x2a, 0xf0, 0xd1, - 0x00, 0xbe, 0x00, 0xbf, - 0x00, 0x3c, 0x02, 0x40, + 0xdf, 0xf8, 0x28, 0xc0, + 0xdf, 0xf8, 0x28, 0xa0, + 0xe2, 0x44, 0x03, 0x68, + 0x0b, 0x60, 0x00, 0xf1, + 0x04, 0x00, 0x01, 0xf1, + 0x04, 0x01, 0xba, 0xf8, + 0x00, 0x30, 0x13, 0xf0, + 0x01, 0x0f, 0xfa, 0xd0, + 0xa2, 0xf1, 0x01, 0x02, + 0x00, 0x2a, 0xf0, 0xd1, + 0x00, 0xbe, 0x00, 0xbf, + 0x00, 0x3c, 0x02, 0x40, 0x0e, 0x00, 0x00, 0x00 }; static const uint8_t loader_code_stm32f4_lv[] = { // flashloaders/stm32f4lv.s - 0xdf, 0xf8, 0x2c, 0xc0, - 0xdf, 0xf8, 0x2c, 0xa0, - 0xe2, 0x44, 0x4f, 0xea, - 0x82, 0x02, 0x03, 0x78, - 0x0b, 0x70, 0x00, 0xf1, - 0x01, 0x00, 0x01, 0xf1, - 0x01, 0x01, 0xba, 0xf8, - 0x00, 0x30, 0x13, 0xf0, - 0x01, 0x0f, 0xfa, 0xd0, - 0xa2, 0xf1, 0x01, 0x02, - 0x00, 0x2a, 0xf0, 0xd1, - 0x00, 0xbe, 0x00, 0xbf, - 0x00, 0x3c, 0x02, 0x40, + 0xdf, 0xf8, 0x2c, 0xc0, + 0xdf, 0xf8, 0x2c, 0xa0, + 0xe2, 0x44, 0x4f, 0xea, + 0x82, 0x02, 0x03, 0x78, + 0x0b, 0x70, 0x00, 0xf1, + 0x01, 0x00, 0x01, 0xf1, + 0x01, 0x01, 0xba, 0xf8, + 0x00, 0x30, 0x13, 0xf0, + 0x01, 0x0f, 0xfa, 0xd0, + 0xa2, 0xf1, 0x01, 0x02, + 0x00, 0x2a, 0xf0, 0xd1, + 0x00, 0xbe, 0x00, 0xbf, + 0x00, 0x3c, 0x02, 0x40, 0x0e, 0x00, 0x00, 0x00 }; static const uint8_t loader_code_stm32l4[] = { // flashloaders/stm32l4.s - 0xdf, 0xf8, 0x2c, 0xc0, - 0xdf, 0xf8, 0x2c, 0xa0, - 0xe2, 0x44, 0x03, 0x68, - 0x44, 0x68, 0x0b, 0x60, - 0x4c, 0x60, 0x00, 0xf1, - 0x08, 0x00, 0x01, 0xf1, - 0x08, 0x01, 0xba, 0xf8, - 0x00, 0x30, 0x13, 0xf0, - 0x01, 0x0f, 0xfa, 0xd0, - 0xa2, 0xf1, 0x01, 0x02, - 0x00, 0x2a, 0xee, 0xd1, - 0x00, 0xbe, 0x00, 0xbf, - 0x00, 0x20, 0x02, 0x40, + 0xdf, 0xf8, 0x2c, 0xc0, + 0xdf, 0xf8, 0x2c, 0xa0, + 0xe2, 0x44, 0x03, 0x68, + 0x44, 0x68, 0x0b, 0x60, + 0x4c, 0x60, 0x00, 0xf1, + 0x08, 0x00, 0x01, 0xf1, + 0x08, 0x01, 0xba, 0xf8, + 0x00, 0x30, 0x13, 0xf0, + 0x01, 0x0f, 0xfa, 0xd0, + 0xa2, 0xf1, 0x01, 0x02, + 0x00, 0x2a, 0xee, 0xd1, + 0x00, 0xbe, 0x00, 0xbf, + 0x00, 0x20, 0x02, 0x40, 0x12, 0x00, 0x00, 0x00 }; static const uint8_t loader_code_stm32f7[] = { // flashloaders/stm32f7.s - 0xdf, 0xf8, 0x2c, 0xc0, - 0xdf, 0xf8, 0x2c, 0xa0, - 0xe2, 0x44, 0x03, 0x68, - 0x0b, 0x60, 0x00, 0xf1, - 0x04, 0x00, 0x01, 0xf1, - 0x04, 0x01, 0xbf, 0xf3, - 0x4f, 0x8f, 0xba, 0xf8, - 0x00, 0x30, 0x13, 0xf0, - 0x01, 0x0f, 0xfa, 0xd0, - 0xa2, 0xf1, 0x01, 0x02, - 0x00, 0x2a, 0xee, 0xd1, - 0x00, 0xbe, 0x00, 0xbf, - 0x00, 0x3c, 0x02, 0x40, + 0xdf, 0xf8, 0x2c, 0xc0, + 0xdf, 0xf8, 0x2c, 0xa0, + 0xe2, 0x44, 0x03, 0x68, + 0x0b, 0x60, 0x00, 0xf1, + 0x04, 0x00, 0x01, 0xf1, + 0x04, 0x01, 0xbf, 0xf3, + 0x4f, 0x8f, 0xba, 0xf8, + 0x00, 0x30, 0x13, 0xf0, + 0x01, 0x0f, 0xfa, 0xd0, + 0xa2, 0xf1, 0x01, 0x02, + 0x00, 0x2a, 0xee, 0xd1, + 0x00, 0xbe, 0x00, 0xbf, + 0x00, 0x3c, 0x02, 0x40, 0x0e, 0x00, 0x00, 0x00 }; static const uint8_t loader_code_stm32f7_lv[] = { // flashloaders/stm32f7lv.s - 0xdf, 0xf8, 0x30, 0xc0, - 0xdf, 0xf8, 0x30, 0xa0, - 0xe2, 0x44, 0x4f, 0xea, - 0x82, 0x02, 0x03, 0x78, - 0x0b, 0x70, 0x00, 0xf1, - 0x01, 0x00, 0x01, 0xf1, - 0x01, 0x01, 0xbf, 0xf3, - 0x4f, 0x8f, 0xba, 0xf8, - 0x00, 0x30, 0x13, 0xf0, - 0x01, 0x0f, 0xfa, 0xd0, - 0xa2, 0xf1, 0x01, 0x02, - 0x00, 0x2a, 0xee, 0xd1, - 0x00, 0xbe, 0x00, 0xbf, - 0x00, 0x3c, 0x02, 0x40, + 0xdf, 0xf8, 0x30, 0xc0, + 0xdf, 0xf8, 0x30, 0xa0, + 0xe2, 0x44, 0x4f, 0xea, + 0x82, 0x02, 0x03, 0x78, + 0x0b, 0x70, 0x00, 0xf1, + 0x01, 0x00, 0x01, 0xf1, + 0x01, 0x01, 0xbf, 0xf3, + 0x4f, 0x8f, 0xba, 0xf8, + 0x00, 0x30, 0x13, 0xf0, + 0x01, 0x0f, 0xfa, 0xd0, + 0xa2, 0xf1, 0x01, 0x02, + 0x00, 0x2a, 0xee, 0xd1, + 0x00, 0xbe, 0x00, 0xbf, + 0x00, 0x3c, 0x02, 0x40, 0x0e, 0x00, 0x00, 0x00 }; diff --git a/include/stlink/flash_loader.h b/src/st-link-lib/flash_loader.h similarity index 100% rename from include/stlink/flash_loader.h rename to src/st-link-lib/flash_loader.h diff --git a/src/logging.c b/src/st-link-lib/logging.c similarity index 100% rename from src/logging.c rename to src/st-link-lib/logging.c diff --git a/src/logging.h b/src/st-link-lib/logging.h similarity index 100% rename from src/logging.h rename to src/st-link-lib/logging.h diff --git a/src/md5.c b/src/st-link-lib/md5.c similarity index 100% rename from src/md5.c rename to src/st-link-lib/md5.c diff --git a/src/md5.h b/src/st-link-lib/md5.h similarity index 100% rename from src/md5.h rename to src/st-link-lib/md5.h diff --git a/src/sg.c b/src/st-link-lib/sg.c similarity index 99% rename from src/sg.c rename to src/st-link-lib/sg.c index 798cda9ab..7fae19976 100644 --- a/src/sg.c +++ b/src/st-link-lib/sg.c @@ -84,6 +84,7 @@ #include #include "logging.h" +#include "sg.h" #define STLINK_OK 0x80 #define STLINK_FALSE 0x81 diff --git a/src/sg.h b/src/st-link-lib/sg.h similarity index 98% rename from src/sg.h rename to src/st-link-lib/sg.h index 3a8a7a239..811b339c7 100644 --- a/src/sg.h +++ b/src/st-link-lib/sg.h @@ -8,8 +8,8 @@ #ifndef STLINK_SG_H #define STLINK_SG_H -#include "libusb_settings.h" #include +#include #ifdef __cplusplus extern "C" { diff --git a/src/usb.c b/src/st-link-lib/usb.c similarity index 99% rename from src/usb.c rename to src/st-link-lib/usb.c index a711749da..b76639731 100644 --- a/src/usb.c +++ b/src/st-link-lib/usb.c @@ -14,6 +14,7 @@ #include #endif #include +#include "usb.h" enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80}; @@ -1147,7 +1148,7 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STL if (reset == 2) { stlink_jtag_reset(sl,0); - if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) stlink_enter_swd_mode(sl); + if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) stlink_enter_swd_mode(sl); stlink_force_debug(sl); stlink_jtag_reset(sl,1); usleep(10000); diff --git a/src/usb.h b/src/st-link-lib/usb.h similarity index 98% rename from src/usb.h rename to src/st-link-lib/usb.h index 5c1f5b7ca..3581eabf1 100644 --- a/src/usb.h +++ b/src/st-link-lib/usb.h @@ -11,7 +11,7 @@ #include #include -#include "libusb_settings.h" +#include #include "logging.h" #ifdef __cplusplus diff --git a/src/st-util/semihosting.c b/src/st-util/semihosting.c index fed66ab60..cb03868cd 100644 --- a/src/st-util/semihosting.c +++ b/src/st-util/semihosting.c @@ -9,70 +9,52 @@ #include #include "semihosting.h" -static int mem_read_u8(stlink_t *sl, uint32_t addr, uint8_t *data) -{ +static int mem_read_u8(stlink_t *sl, uint32_t addr, uint8_t *data) { int offset = addr % 4; int len = 4; - if (sl == NULL || data == NULL) { - return -1; - } + if (sl == NULL || data == NULL) return -1; /* Read address and length must be aligned */ - if (stlink_read_mem32(sl, addr - offset, len) != 0) { - return -1; - } + if (stlink_read_mem32(sl, addr - offset, len) != 0) return -1; *data = sl->q_buf[offset]; return 0; } #ifdef UNUSED -static int mem_read_u16(stlink_t *sl, uint32_t addr, uint16_t *data) -{ +static int mem_read_u16(stlink_t *sl, uint32_t addr, uint16_t *data) { int offset = addr % 4; int len = (offset > 2 ? 8 : 4); - if (sl == NULL || data == NULL) { - return -1; - } + if (sl == NULL || data == NULL) return -1; /* Read address and length must be aligned */ - if (stlink_read_mem32(sl, addr - offset, len) != 0) { - return -1; - } + if (stlink_read_mem32(sl, addr - offset, len) != 0) return -1; memcpy(data, &sl->q_buf[offset], sizeof(*data)); return 0; } -static int mem_read_u32(stlink_t *sl, uint32_t addr, uint32_t *data) -{ +static int mem_read_u32(stlink_t *sl, uint32_t addr, uint32_t *data) { int offset = addr % 4; int len = (offset > 0 ? 8 : 4); - if (sl == NULL || data == NULL) { - return -1; - } + if (sl == NULL || data == NULL) return -1; /* Read address and length must be aligned */ - if (stlink_read_mem32(sl, addr - offset, len) != 0) { - return -1; - } + if (stlink_read_mem32(sl, addr - offset, len) != 0) return -1; memcpy(data, &sl->q_buf[offset], sizeof(*data)); return 0; } #endif -static int mem_read(stlink_t *sl, uint32_t addr, void *data, uint16_t len) -{ +static int mem_read(stlink_t *sl, uint32_t addr, void *data, uint16_t len) { int offset = addr % 4; int read_len = len + offset; - if (sl == NULL || data == NULL) { - return -1; - } + if (sl == NULL || data == NULL) return -1; /* Align read size */ if ((read_len % 4) != 0) { @@ -80,16 +62,13 @@ static int mem_read(stlink_t *sl, uint32_t addr, void *data, uint16_t len) } /* Address and length must be aligned */ - if (stlink_read_mem32(sl, addr - offset, read_len) != 0) { - return -1; - } + if (stlink_read_mem32(sl, addr - offset, read_len) != 0) return -1; memcpy(data, &sl->q_buf[offset], len); return 0; } -static int mem_write(stlink_t *sl, uint32_t addr, void *data, uint16_t len) -{ +static int mem_write(stlink_t *sl, uint32_t addr, void *data, uint16_t len) { // Note: this function can write more than it is asked to! // If addr is not an even 32 bit boundary, or len is not a multiple of 4. // @@ -106,9 +85,7 @@ static int mem_write(stlink_t *sl, uint32_t addr, void *data, uint16_t len) int offset = addr % 4; int write_len = len + offset; - if (sl == NULL || data == NULL) { - return -1; - } + if (sl == NULL || data == NULL) return -1; /* Align read size */ if ((write_len % 4) != 0) { @@ -118,9 +95,7 @@ static int mem_write(stlink_t *sl, uint32_t addr, void *data, uint16_t len) memcpy(&sl->q_buf[offset], data, len); /* Address and length must be aligned */ - if (stlink_write_mem32(sl, addr - offset, write_len) != 0) { - return -1; - } + if (stlink_write_mem32(sl, addr - offset, write_len) != 0) return -1; return 0; } @@ -162,9 +137,7 @@ static int saved_errno = 0; int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) { - if (sl == NULL || ret == NULL) { - return -1; - } + if (sl == NULL || ret == NULL) return -1; DLOG("Do semihosting R0=0x%08x R1=0x%08x\n", r0, r1); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6e60fdd5a..a3011fc7e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,6 +11,6 @@ foreach (test ${TESTEXEC}) add_test(test-${test} ${CMAKE_BINARY_DIR}/bin/test-${test}) endforeach () -add_executable(test-flash flash.c "${CMAKE_SOURCE_DIR}/src/tools/flash_opts.c") +add_executable(test-flash flash.c "${CMAKE_SOURCE_DIR}/src/st-flash/flash_opts.c") target_link_libraries(test-flash ${STLINK_LIB_SHARED} ${SSP_LIB}) add_test(test-flash ${CMAKE_BINARY_DIR}/bin/test-flash)