Whitespace cleanup

pull/934/head
nightwalker-87 2020-04-15 16:20:17 +02:00
rodzic 308fccb048
commit 6f934a396e
22 zmienionych plików z 335 dodań i 335 usunięć

Wyświetl plik

@ -101,8 +101,8 @@ set(STLINK_SOURCE
)
if (WIN32 OR MSYS OR MINGW)
set (STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c")
set (STLINK_HEADERS "${STLINK_HEADERS};src/mingw/mingw.h")
set(STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c")
set(STLINK_HEADERS "${STLINK_HEADERS};src/mingw/mingw.h")
endif ()
include_directories(${LIBUSB_INCLUDE_DIR})

Wyświetl plik

@ -1,7 +1,7 @@
if(MSVC)
if (MSVC)
message(STATUS "MSVC C Flags override to /MT")
set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()
endif ()

Wyświetl plik

@ -11,7 +11,7 @@ function(add_cflag_if_supported flag)
if (C_SUPPORTS${flagclean})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endif ()
endfunction()
add_cflag_if_supported("-std=gnu11")
@ -41,10 +41,10 @@ if (NOT WIN32)
add_cflag_if_supported("-fPIC")
endif ()
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_cflag_if_supported("-ggdb")
add_cflag_if_supported("-O0")
else()
add_cflag_if_supported("-O2")
add_cflag_if_supported("-Werror")
endif()
endif ()

Wyświetl plik

@ -1,27 +1,27 @@
set (CPACK_PACKAGE_NAME ${PROJECT_NAME})
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set (CPACK_SET_DESTDIR "ON")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SET_DESTDIR "ON")
if (APPLE)
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-macosx-amd64")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/dist/osx")
set (CPACK_INSTALL_PREFIX "")
set(CPACK_INSTALL_PREFIX "")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/dist/osx")
elseif (WIN32)
set(CPACK_GENERATOR "ZIP")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/dist/windows")
set (CPACK_INSTALL_PREFIX "")
set(CPACK_INSTALL_PREFIX "")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/dist/windows")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS "/etc/debian_version")
message(STATUS "Debian-based Linux OS detected")
set(CPACK_GENERATOR "DEB")
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-amd64" )
endif()
endif ()
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/stlink-org/stlink")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Luca Boccassi")
set(CPACK_PACKAGE_CONTACT "bluca@debian.org")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "STM32 STlink programmer tools")
endif()
endif ()

Wyświetl plik

@ -77,7 +77,7 @@ else () # all other OS
LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS /usr /usr/local /opt
)
endif()
endif ()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)

Wyświetl plik

@ -42,10 +42,10 @@
include(CMakeParseArguments)
if(NOT EXISTS ${PANDOC_EXECUTABLE})
if (NOT EXISTS ${PANDOC_EXECUTABLE})
find_program(PANDOC_EXECUTABLE pandoc)
mark_as_advanced(PANDOC_EXECUTABLE)
endif()
endif ()
###############################################################################
# Based on code from UseLATEX
@ -133,7 +133,7 @@ This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
Please delete them:
$ rm -r CMakeFiles/ CmakeCache.txt
")
ENDIF()
ENDif ()
endfunction()
# This builds a document
@ -171,7 +171,7 @@ function(add_document target_name)
if (NOT PANDOC_EXECUTABLE)
message(WARNING "Pandoc not found. Install Pandoc (http://johnmacfarlane.net/pandoc/) or set cache variable PANDOC_EXECUTABLE.")
return()
endif()
endif ()
set(options EXPORT_ARCHIVE NO_EXPORT_PRODUCT EXPORT_PDF DIRECT_TEX_TO_PDF VERBOSE)
set(oneValueArgs PRODUCT_DIRECTORY)
@ -188,29 +188,29 @@ function(add_document target_name)
if (NOT "${target_extension}" STREQUAL ".tex" AND NOT "${target_extension}" STREQUAL ".latex")
# if (NOT "${target_extension}" STREQUAL ".tex")
MESSAGE(FATAL_ERROR "Target '${target_name}': Cannot use 'EXPORT_PDF' for target of type '${target_extension}': target type must be '.tex' or '.latex'")
endif()
endif()
endif ()
endif ()
if (${ADD_DOCUMENT_DIRECT_TEX_TO_PDF})
list(LENGTH ${ADD_DOCUMENT_SOURCES} SOURCE_LEN)
if (SOURCE_LEN GREATER 1)
MESSAGE(FATAL_ERROR "Target '${target_name}': Only one source can be specified when using the 'DIRECT_TEX_TO_PDF' option")
endif()
endif ()
# set(ADD_DOCUMENT_SOURCES, list(GET ${ADD_DOCUMENT_SOURCES} 1))
pandocology_get_file_stemname(source_stemname ${ADD_DOCUMENT_SOURCES})
pandocology_get_file_extension(source_extension ${ADD_DOCUMENT_SOURCES})
if (NOT "${source_extension}" STREQUAL ".tex" AND NOT "${source_extension}" STREQUAL ".latex")
MESSAGE(FATAL_ERROR "Target '${target_name}': Cannot use 'DIRECT_TEX_TO_PDF' for source of type '${source_extension}': source type must be '.tex' or '.latex'")
endif()
endif ()
SET(check_target ${source_stemname}.pdf)
IF (NOT ${check_target} STREQUAL ${target_name})
MESSAGE(FATAL_ERROR "Target '${target_name}': Must use target name of '${check_target}' if using 'DIRECT_TEX_TO_PDF'")
endif()
endif()
endif ()
endif ()
## set up output directory
if ("${ADD_DOCUMENT_PRODUCT_DIRECTORY}" STREQUAL "")
set(ADD_DOCUMENT_PRODUCT_DIRECTORY "product")
endif()
endif ()
get_filename_component(product_directory ${CMAKE_BINARY_DIR}/${ADD_DOCUMENT_PRODUCT_DIRECTORY} ABSOLUTE)
# get_filename_component(absolute_product_path ${product_directory}/${target_name} ABSOLUTE)
@ -232,7 +232,7 @@ function(add_document target_name)
pandocology_add_input_dir(${CMAKE_CURRENT_SOURCE_DIR}/${resource_dir} ${CMAKE_CURRENT_BINARY_DIR} build_resources)
if (${ADD_DOCUMENT_EXPORT_ARCHIVE})
pandocology_add_input_dir(${CMAKE_CURRENT_SOURCE_DIR}/${resource_dir} ${product_directory} exported_resources)
endif()
endif ()
endforeach()
## primary command
@ -255,7 +255,7 @@ function(add_document target_name)
# we produce the target in the source directory, in case other build targets require it as a source
COMMAND latexmk -gg -halt-on-error -interaction=nonstopmode -file-line-error -pdf ${build_sources} 2>/dev/null >/dev/null || (grep --no-messages -A8 ".*:[0-9]*:.*" ${target_stemname}.log && false)
)
endif()
endif ()
add_to_make_clean(${CMAKE_CURRENT_BINARY_DIR}/${target_name})
else()
add_custom_command(
@ -267,7 +267,7 @@ function(add_document target_name)
COMMAND ${PANDOC_EXECUTABLE} ${build_sources} ${ADD_DOCUMENT_PANDOC_DIRECTIVES} -o ${target_name}
)
add_to_make_clean(${CMAKE_CURRENT_BINARY_DIR}/${target_name})
endif()
endif ()
## figure out what all is going to be produced by this build set, and set
## those as dependencies of the primary target
@ -275,14 +275,14 @@ function(add_document target_name)
set(primary_target_dependencies ${primary_target_dependencies} ${CMAKE_CURRENT_BINARY_DIR}/${target_name})
if (NOT ${ADD_DOCUMENT_NO_EXPORT_PRODUCT})
set(primary_target_dependencies ${primary_target_dependencies} ${product_directory}/${target_name})
endif()
endif ()
if (${ADD_DOCUMENT_EXPORT_PDF})
set(primary_target_dependencies ${primary_target_dependencies} ${CMAKE_CURRENT_BINARY_DIR}/${target_stemname}.pdf)
set(primary_target_dependencies ${primary_target_dependencies} ${product_directory}/${target_stemname}.pdf)
endif()
endif ()
if (${ADD_DOCUMENT_EXPORT_ARCHIVE})
set(primary_target_dependencies ${primary_target_dependencies} ${product_directory}/${target_stemname}.tbz)
endif()
endif ()
## primary target
# # target cannot have same (absolute name) as dependencies:
@ -326,7 +326,7 @@ function(add_document target_name)
)
add_to_make_clean(${CMAKE_CURRENT_BINARY_DIR}/${target_stemname}.pdf)
add_to_make_clean(${product_directory}/${target_stemname}.pdf)
endif()
endif ()
## copy products
if (NOT ${ADD_DOCUMENT_NO_EXPORT_PRODUCT})
@ -336,7 +336,7 @@ function(add_document target_name)
COMMAND ${CMAKE_COMMAND} -E copy ${target_name} ${product_directory}
)
add_to_make_clean(${product_directory}/${target_name})
endif()
endif ()
## copy resources
if (${ADD_DOCUMENT_EXPORT_ARCHIVE})
@ -359,7 +359,7 @@ function(add_document target_name)
# ALL
# DEPENDS ${product_directory}/${target_stemname}.tbz
# )
endif()
endif ()
endfunction(add_document)

Wyświetl plik

@ -27,7 +27,7 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
)
if (res EQUAL 1)
set (PROJECT_VERSION "${PROJECT_VERSION}-dirty")
set(PROJECT_VERSION "${PROJECT_VERSION}-dirty")
endif ()
# strip a leading v off of the version as proceeding code expectes just the version numbering.
@ -57,7 +57,7 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
else(GIT_DESCRIBE_RESULT EQUAL 0)
message(WARNING "git describe failed.")
message(WARNING "${GIT_DESCRIBE_ERROR}")
endif(GIT_DESCRIBE_RESULT EQUAL 0)
endif (GIT_DESCRIBE_RESULT EQUAL 0)
else ()
message(STATUS "Git or repo not found.")
endif ()

Wyświetl plik

@ -1,6 +1,6 @@
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif()
endif ()
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")

Wyświetl plik

@ -23,7 +23,7 @@ foreach (manpage ${MANPAGES})
set(f "${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.1")
else()
message(AUTHOR_WARNING "Manpage ${manpage} not generated")
endif()
endif ()
if (f AND NOT WIN32)
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)

Wyświetl plik

@ -546,7 +546,7 @@ static void set_flash_cr_mer(stlink_t *sl, bool v) {
stlink_write_debug32(sl, cr_reg, val);
}
if(v)
if (v)
val |= cr_mer;
else
val &= ~cr_mer;
@ -905,7 +905,7 @@ int stlink_load_device_params(stlink_t *sl) {
sl->flash_size = (flash_size & 0xff) * 1024;
} else if ((sl->chip_id & 0xFFF) == STLINK_CHIPID_STM32_L1_HIGH) {
// 0 is 384k and 1 is 256k
if ( flash_size == 0 ) {
if ( flash_size == 0){
sl->flash_size = 384 * 1024;
} else {
sl->flash_size = 256 * 1024;
@ -923,7 +923,7 @@ int stlink_load_device_params(stlink_t *sl) {
//medium and low devices have the same chipid. ram size depends on flash size.
//STM32F100xx datasheet Doc ID 16455 Table 2
if(sl->chip_id == STLINK_CHIPID_STM32_F1_VL_MEDIUM_LOW && sl->flash_size < 64 * 1024){
if (sl->chip_id == STLINK_CHIPID_STM32_F1_VL_MEDIUM_LOW && sl->flash_size < 64 * 1024){
sl->sram_size = 0x1000;
}
@ -1091,7 +1091,7 @@ int stlink_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {
int stlink_write_mem8(stlink_t *sl, uint32_t addr, uint16_t len) {
DLOG("*** stlink_write_mem8 ***\n");
if (len > 0x40 ) { // !!! never ever: Writing more then 0x40 bytes gives unexpected behaviour
if (len > 0x40){ // !!! never ever: Writing more then 0x40 bytes gives unexpected behaviour
fprintf(stderr, "Error: Data length > 64: +%d byte.\n",
len);
abort();
@ -1374,7 +1374,7 @@ static void md5_calculate(mapped_file_t *mf) {
Md5Update(&md5Context, mf->base, (uint32_t)mf->len);
Md5Finalise(&md5Context, &md5Hash);
printf("md5 checksum: ");
for(int i = 0; i < (int) sizeof(md5Hash); i++) {
for (int i = 0; i < (int) sizeof(md5Hash); i++) {
printf("%x", md5Hash.bytes[i]);
}
printf(", ");
@ -1426,7 +1426,7 @@ int stlink_mwrite_sram(stlink_t * sl, uint8_t* data, uint32_t length, stm32_addr
len = length;
if(len & 3) {
if (len & 3) {
len -= len & 3;
}
@ -1445,7 +1445,7 @@ int stlink_mwrite_sram(stlink_t * sl, uint8_t* data, uint32_t length, stm32_addr
stlink_write_mem32(sl, addr + (uint32_t) off, size);
}
if(length > len) {
if (length > len) {
memcpy(sl->q_buf, data + len, length - len);
stlink_write_mem8(sl, addr + (uint32_t) len, length - len);
}
@ -1492,7 +1492,7 @@ int stlink_fwrite_sram(stlink_t * sl, const char* path, stm32_addr_t addr) {
len = mf.len;
if(len & 3) {
if (len & 3) {
len -= len & 3;
}
@ -1511,7 +1511,7 @@ int stlink_fwrite_sram(stlink_t * sl, const char* path, stm32_addr_t addr) {
stlink_write_mem32(sl, addr + (uint32_t) off, size);
}
if(mf.len > len) {
if (mf.len > len) {
memcpy(sl->q_buf, mf.base + len, mf.len - len);
stlink_write_mem8(sl, addr + (uint32_t) len, mf.len - len);
}
@ -1595,7 +1595,7 @@ struct stlink_fread_ihex_worker_arg {
static bool stlink_fread_ihex_newsegment(struct stlink_fread_ihex_worker_arg* the_arg) {
uint32_t addr = the_arg->addr;
uint8_t sum = 2 + 4 + (uint8_t)((addr & 0xFF000000) >> 24) + (uint8_t)((addr & 0x00FF0000) >> 16);
if(17 != fprintf(the_arg->file, ":02000004%04X%02X\r\n", (addr & 0xFFFF0000) >> 16, (uint8_t)(0x100 - sum)))
if (17 != fprintf(the_arg->file, ":02000004%04X%02X\r\n", (addr & 0xFFFF0000) >> 16, (uint8_t)(0x100 - sum)))
return false;
the_arg->lba = (addr & 0xFFFF0000);
@ -1605,26 +1605,26 @@ static bool stlink_fread_ihex_newsegment(struct stlink_fread_ihex_worker_arg* th
static bool stlink_fread_ihex_writeline(struct stlink_fread_ihex_worker_arg* the_arg) {
uint8_t count = the_arg->buf_pos;
if(count == 0) return true;
if (count == 0) return true;
uint32_t addr = the_arg->addr;
if(the_arg->lba != (addr & 0xFFFF0000)) { // segment changed
if(!stlink_fread_ihex_newsegment(the_arg)) return false;
if (the_arg->lba != (addr & 0xFFFF0000)) { // segment changed
if (!stlink_fread_ihex_newsegment(the_arg)) return false;
}
uint8_t sum = count + (uint8_t)((addr & 0x0000FF00) >> 8) + (uint8_t)(addr & 0x000000FF);
if(9 != fprintf(the_arg->file, ":%02X%04X00", count, (addr & 0x0000FFFF)))
if (9 != fprintf(the_arg->file, ":%02X%04X00", count, (addr & 0x0000FFFF)))
return false;
for(uint8_t i = 0; i < count; ++i) {
for (uint8_t i = 0; i < count; ++i) {
uint8_t b = the_arg->buf[i];
sum += b;
if(2 != fprintf(the_arg->file, "%02X", b))
if (2 != fprintf(the_arg->file, "%02X", b))
return false;
}
if(4 != fprintf(the_arg->file, "%02X\r\n", (uint8_t)(0x100 - sum)))
if (4 != fprintf(the_arg->file, "%02X\r\n", (uint8_t)(0x100 - sum)))
return false;
the_arg->addr += count;
@ -1645,9 +1645,9 @@ static bool stlink_fread_ihex_init(struct stlink_fread_ihex_worker_arg* the_arg,
static bool stlink_fread_ihex_worker(void* arg, uint8_t* block, ssize_t len) {
struct stlink_fread_ihex_worker_arg* the_arg = (struct stlink_fread_ihex_worker_arg*)arg;
for(ssize_t i = 0; i < len; ++i) {
if(the_arg->buf_pos == sizeof(the_arg->buf)) { // line is full
if(!stlink_fread_ihex_writeline(the_arg)) return false;
for (ssize_t i = 0; i < len; ++i) {
if (the_arg->buf_pos == sizeof(the_arg->buf)) { // line is full
if (!stlink_fread_ihex_writeline(the_arg)) return false;
}
the_arg->buf[the_arg->buf_pos++] = block[i];
@ -1657,11 +1657,11 @@ static bool stlink_fread_ihex_worker(void* arg, uint8_t* block, ssize_t len) {
}
static bool stlink_fread_ihex_finalize(struct stlink_fread_ihex_worker_arg* the_arg) {
if(!stlink_fread_ihex_writeline(the_arg)) return false;
if (!stlink_fread_ihex_writeline(the_arg)) return false;
// FIXME do we need the Start Linear Address?
if(13 != fprintf(the_arg->file, ":00000001FF\r\n")) // EoF
if (13 != fprintf(the_arg->file, ":00000001FF\r\n")) // EoF
return false;
return (0 == fclose(the_arg->file));
@ -1678,11 +1678,11 @@ int stlink_fread(stlink_t* sl, const char* path, bool is_ihex, stm32_addr_t addr
return -1;
}
if(is_ihex) {
if (is_ihex) {
struct stlink_fread_ihex_worker_arg arg;
if(stlink_fread_ihex_init(&arg, fd, addr)) {
if (stlink_fread_ihex_init(&arg, fd, addr)) {
error = stlink_read(sl, addr, size, &stlink_fread_ihex_worker, &arg);
if(!stlink_fread_ihex_finalize(&arg))
if (!stlink_fread_ihex_finalize(&arg))
error = -1;
}
else {
@ -1722,18 +1722,18 @@ uint32_t calculate_F4_sectornum(uint32_t flashaddr){
flashaddr -= 0x100000;
}
if (flashaddr<0x4000) return (offset + 0);
else if(flashaddr<0x8000) return(offset + 1);
else if(flashaddr<0xc000) return(offset + 2);
else if(flashaddr<0x10000) return(offset + 3);
else if(flashaddr<0x20000) return(offset + 4);
else if (flashaddr<0x8000) return(offset + 1);
else if (flashaddr<0xc000) return(offset + 2);
else if (flashaddr<0x10000) return(offset + 3);
else if (flashaddr<0x20000) return(offset + 4);
else return offset + (flashaddr/0x20000) +4;
}
uint32_t calculate_F7_sectornum(uint32_t flashaddr){
flashaddr &= ~STM32_FLASH_BASE; //Page now holding the actual flash address
if(flashaddr<0x20000) return(flashaddr/0x8000);
else if(flashaddr<0x40000) return(4);
if (flashaddr<0x20000) return(flashaddr/0x8000);
else if (flashaddr<0x40000) return(4);
else return(flashaddr/0x40000) +4;
}
@ -1778,14 +1778,14 @@ uint32_t stlink_calculate_pagesize(stlink_t *sl, uint32_t flashaddr){
sector -= 12;
}
if (sector<4) sl->flash_pgsz=0x4000;
else if(sector<5) sl->flash_pgsz=0x10000;
else if (sector<5) sl->flash_pgsz=0x10000;
else sl->flash_pgsz=0x20000;
}
else if (sl->chip_id == STLINK_CHIPID_STM32_F7 ||
sl->chip_id == STLINK_CHIPID_STM32_F7XXXX) {
uint32_t sector=calculate_F7_sectornum(flashaddr);
if (sector<4) sl->flash_pgsz=0x8000;
else if(sector<5) sl->flash_pgsz=0x20000;
else if (sector<5) sl->flash_pgsz=0x20000;
else sl->flash_pgsz=0x40000;
}
return (uint32_t) sl->flash_pgsz;
@ -1866,7 +1866,7 @@ int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
/* check if the locks are set */
stlink_read_debug32(sl, flash_regs_base + FLASH_PECR_OFF, &val);
if((val & (1<<0))||(val & (1<<1))) {
if ((val & (1<<0))||(val & (1<<1))) {
/* disable pecr protection */
stlink_write_debug32(sl, flash_regs_base + FLASH_PEKEYR_OFF, 0x89abcdef);
stlink_write_debug32(sl, flash_regs_base + FLASH_PEKEYR_OFF, 0x02030405);
@ -1903,7 +1903,7 @@ int stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr)
*/
do {
stlink_read_debug32(sl, STM32L_FLASH_SR, &val)
} while((val & (1 << 0)) != 0);
} while ((val & (1 << 0)) != 0);
#endif /* fix_to_be_confirmed */
@ -2265,7 +2265,7 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t
(sl->chip_id != STLINK_CHIPID_STM32_L496X) &&
(sl->chip_id != STLINK_CHIPID_STM32_L4RX)) {
if( sl->version.stlink_v == 1 ) {
if ( sl->version.stlink_v == 1){
printf("STLINK V1 cannot read voltage, defaulting to 32-bit writes on F4 devices\n");
write_flash_cr_psiz(sl, 2);
}
@ -2299,7 +2299,7 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t
set_flash_cr_pg(sl);
size_t buf_size = (sl->sram_size > 0x8000) ? 0x8000 : 0x4000;
for(off = 0; off < len;) {
for (off = 0; off < len;) {
size_t size = len - off > buf_size ? buf_size : len - off;
printf("size: %u\n", (unsigned int)size);
@ -2483,11 +2483,11 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t
// note: length not checked
static uint8_t stlink_parse_hex(const char* hex) {
uint8_t d[2];
for(int i = 0; i < 2; ++i) {
for (int i = 0; i < 2; ++i) {
char c = *(hex + i);
if(c >= '0' && c <= '9') d[i] = c - '0';
else if(c >= 'A' && c <= 'F') d[i] = c - 'A' + 10;
else if(c >= 'a' && c <= 'f') d[i] = c - 'a' + 10;
if (c >= '0' && c <= '9') d[i] = c - '0';
else if (c >= 'A' && c <= 'F') d[i] = c - 'A' + 10;
else if (c >= 'a' && c <= 'f') d[i] = c - 'a' + 10;
else return 0; // error
}
return (d[0] << 4) | (d[1]);
@ -2500,15 +2500,15 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
uint32_t end = 0;
bool eof_found = false;
for(int scan = 0; (res == 0) && (scan < 2); ++scan) { // parse file two times - first to find memory range, second - to fill it
if(scan == 1) {
if(!eof_found) {
for (int scan = 0; (res == 0) && (scan < 2); ++scan) { // parse file two times - first to find memory range, second - to fill it
if (scan == 1) {
if (!eof_found) {
ELOG("No EoF recond\n");
res = -1;
break;
}
if(*begin >= end) {
if (*begin >= end) {
ELOG("No data found in file\n");
res = -1;
break;
@ -2516,7 +2516,7 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
*size = (end - *begin) + 1;
data = calloc(*size, 1); // use calloc to get NULL if out of memory
if(!data) {
if (!data) {
ELOG("Cannot allocate %d bytes\n", *size);
res = -1;
break;
@ -2526,7 +2526,7 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
}
FILE* file = fopen(path, "r");
if(!file) {
if (!file) {
ELOG("Cannot open file\n");
res = -1;
break;
@ -2535,17 +2535,17 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
uint32_t lba = 0;
char line[1 + 5*2 + 255*2 + 2];
while(fgets(line, sizeof(line), file)) {
if(line[0] == '\n' || line[0] == '\r') continue; // skip empty lines
if(line[0] != ':') { // no marker - wrong file format
while (fgets(line, sizeof(line), file)) {
if (line[0] == '\n' || line[0] == '\r') continue; // skip empty lines
if (line[0] != ':') { // no marker - wrong file format
ELOG("Wrong file format - no marker\n");
res = -1;
break;
}
size_t l = strlen(line);
while(l > 0 && (line[l-1] == '\n' || line[l-1] == '\r')) --l; // trim EoL
if((l < 11) || (l == (sizeof(line)-1))) { // line too short or long - wrong file format
while (l > 0 && (line[l-1] == '\n' || line[l-1] == '\r')) --l; // trim EoL
if ((l < 11) || (l == (sizeof(line)-1))) { // line too short or long - wrong file format
ELOG("Wrong file format - wrong line length\n");
res = -1;
break;
@ -2553,17 +2553,17 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
// check sum
uint8_t chksum = 0;
for(size_t i = 1; i < l; i += 2) {
for (size_t i = 1; i < l; i += 2) {
chksum += stlink_parse_hex(line + i);
}
if(chksum != 0) {
if (chksum != 0) {
ELOG("Wrong file format - checksum mismatch\n");
res = -1;
break;
}
uint8_t reclen = stlink_parse_hex(line + 1);
if(((uint32_t)reclen + 5)*2 + 1 != l) {
if (((uint32_t)reclen + 5)*2 + 1 != l) {
ELOG("Wrong file format - record length mismatch\n");
res = -1;
break;
@ -2574,17 +2574,17 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
switch(rectype) {
case 0: // data
if(scan == 0) {
if (scan == 0) {
uint32_t b = lba + offset;
uint32_t e = b + reclen - 1;
if(b < *begin) *begin = b;
if(e > end) end = e;
if (b < *begin) *begin = b;
if (e > end) end = e;
}
else {
for(uint8_t i = 0; i < reclen; ++i) {
for (uint8_t i = 0; i < reclen; ++i) {
uint8_t b = stlink_parse_hex(line + 9 + i*2);
uint32_t addr = lba + offset + i;
if(addr >= *begin && addr <= end) {
if (addr >= *begin && addr <= end) {
data[addr - *begin] = b;
}
}
@ -2604,7 +2604,7 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
break;
case 4: // Extended Linear Address
if(reclen == 2) {
if (reclen == 2) {
lba = ((uint32_t)stlink_parse_hex(line + 9) << 24) | ((uint32_t)stlink_parse_hex(line + 11) << 16);
}
else {
@ -2620,13 +2620,13 @@ int stlink_parse_ihex(const char* path, uint8_t erased_pattern, uint8_t * * mem,
ELOG("Wrong file format - unexpected record type %d\n", rectype);
res = -1;
}
if(res != 0) break;
if (res != 0) break;
}
fclose(file);
}
if(res == 0) {
if (res == 0) {
*mem = data;
}
else {
@ -2655,14 +2655,14 @@ int stlink_mwrite_flash(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr
*/
if (sl->opt) {
idx = (unsigned int)length;
for(num_empty = 0; num_empty != length; ++num_empty) {
for (num_empty = 0; num_empty != length; ++num_empty) {
if (data[--idx] != erased_pattern) {
break;
}
}
/* Round down to words */
num_empty -= (num_empty & 3);
if(num_empty != 0) {
if (num_empty != 0) {
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
}
} else {
@ -2704,14 +2704,14 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
if (sl->opt) {
idx = (unsigned int) mf.len;
for(num_empty = 0; num_empty != mf.len; ++num_empty) {
for (num_empty = 0; num_empty != mf.len; ++num_empty) {
if (mf.base[--idx] != erased_pattern) {
break;
}
}
/* Round down to words */
num_empty -= (num_empty & 3);
if(num_empty != 0) {
if (num_empty != 0) {
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
}
} else {
@ -2740,7 +2740,7 @@ static int stlink_write_option_bytes_g0x(stlink_t *sl, uint8_t* base, uint32_t l
uint32_t val;
if(len != 4) {
if (len != 4) {
ELOG("Wrong length for writing option bytes, must be 4 is %d\n", len);
return -1;
}
@ -2749,7 +2749,7 @@ static int stlink_write_option_bytes_g0x(stlink_t *sl, uint8_t* base, uint32_t l
stlink_core_id(sl);
/* Check if chip is supported and for correct address */
if(sl->chip_id != STLINK_CHIPID_STM32_G0_CAT1 &&
if (sl->chip_id != STLINK_CHIPID_STM32_G0_CAT1 &&
sl->chip_id != STLINK_CHIPID_STM32_G0_CAT2) {
ELOG("Option bytes writing is currently only supported for the STM32G0\n");
return -1;
@ -2833,7 +2833,7 @@ static int stlink_write_option_bytes_l0_cat2(stlink_t *sl, uint8_t* base, uint32
uint32_t val;
if(len != 4) {
if (len != 4) {
ELOG("Wrong length for writting option bytes, must be 4 is %d\n", len);
return -1;
}
@ -2891,7 +2891,7 @@ static int stlink_write_option_bytes_l1(stlink_t *sl, uint8_t* base, stm32_addr_
uint32_t val;
uint32_t data;
if(len != 4 && len != 8) {
if (len != 4 && len != 8) {
ELOG("Wrong length for writting option bytes, must be 4 or 8 is %d\n", len);
return -1;
}
@ -2932,7 +2932,7 @@ static int stlink_write_option_bytes_l1(stlink_t *sl, uint8_t* base, stm32_addr_
/* Write options bytes */
write_uint32((unsigned char*) &data, *(uint32_t*) (base));
if( data != val ) {
if ( data != val ) {
WLOG("Writing option bytes 0x%04x\n", data);
stlink_write_debug32(sl, addr, data);
stlink_read_debug32(sl, addr, &val);
@ -2940,7 +2940,7 @@ static int stlink_write_option_bytes_l1(stlink_t *sl, uint8_t* base, stm32_addr_
}
if(len==8) {
if (len==8) {
/* Clear errors */
stlink_write_debug32(sl, STM32L1_FLASH_REGS_ADDR + FLASH_SR_OFF, 0x00003F00);
@ -2949,7 +2949,7 @@ static int stlink_write_option_bytes_l1(stlink_t *sl, uint8_t* base, stm32_addr_
/* Write options bytes */
write_uint32((unsigned char*) &data, *(uint32_t*) (base+4));
if( data != val ) {
if ( data != val ) {
WLOG("Writing 2nd option bytes 0x%04x\n", data);
stlink_write_debug32(sl, addr+4, data);
stlink_read_debug32(sl, addr+4, &val);
@ -2976,7 +2976,7 @@ static int stlink_write_option_bytes_l496x(stlink_t *sl, uint8_t* base, uint32_t
uint32_t val;
if(len != 4) {
if (len != 4) {
ELOG("Wrong length for writting option bytes, must be 4 is %d\n", len);
return -1;
}
@ -3082,7 +3082,7 @@ static int stlink_write_option_bytes_f2(stlink_t *sl, uint32_t option_byte) {
stlink_read_debug32(sl, FLASH_F2_SR, &val);
WLOG("wait BSY flag to be 0\n");
while(val & 0x00010000){
while (val & 0x00010000){
stlink_read_debug32(sl, FLASH_F2_SR, &val);
}
WLOG("BSY flag is 0\n");
@ -3132,7 +3132,7 @@ static int stlink_write_option_bytes_f4(stlink_t *sl, uint32_t option_byte) {
stlink_read_debug32(sl, FLASH_F4_SR, &val);
WLOG("wait BSY flag to be 0\n");
while(val & 0x00010000){
while (val & 0x00010000){
stlink_read_debug32(sl, FLASH_F4_SR, &val);
}
WLOG("BSY flag is 0\n");
@ -3228,17 +3228,17 @@ int stlink_write_option_bytes(stlink_t *sl, stm32_addr_t addr, uint8_t* base, ui
WLOG("Option bytes write chip_id 0x%08x addr 0x%08x\n",sl->chip_id,addr);
/* Check if chip is supported and for correct address */
if(((sl->chip_id == STLINK_CHIPID_STM32_G0_CAT1) ||
if (((sl->chip_id == STLINK_CHIPID_STM32_G0_CAT1) ||
(sl->chip_id == STLINK_CHIPID_STM32_G0_CAT2)) && (addr == STM32_G0_OPTION_BYTES_BASE)) {
return stlink_write_option_bytes_g0x(sl, base, len);
}
else if((sl->chip_id == STLINK_CHIPID_STM32_L0_CAT2) && (addr == STM32_L0_CAT2_OPTION_BYTES_BASE)) {
else if ((sl->chip_id == STLINK_CHIPID_STM32_L0_CAT2) && (addr == STM32_L0_CAT2_OPTION_BYTES_BASE)) {
return stlink_write_option_bytes_l0_cat2(sl, base, len);
}
else if((sl->chip_id == STLINK_CHIPID_STM32_L496X) && (addr == STM32_L496X_OPTION_BYTES_BASE)) {
else if ((sl->chip_id == STLINK_CHIPID_STM32_L496X) && (addr == STM32_L496X_OPTION_BYTES_BASE)) {
return stlink_write_option_bytes_l496x(sl, base, len);
}
else if(((sl->chip_id == STLINK_CHIPID_STM32_L152_RE) || (sl->chip_id == STLINK_CHIPID_STM32_L1_HIGH) ) &&
else if (((sl->chip_id == STLINK_CHIPID_STM32_L152_RE) || (sl->chip_id == STLINK_CHIPID_STM32_L1_HIGH) ) &&
((addr == STM32_L1_OPTION_BYTES_BASE) || (addr == STM32_L1_OPTION_BYTES_BASE+4))) {
return stlink_write_option_bytes_l1(sl, base, addr, len);
}
@ -3284,9 +3284,9 @@ int stlink_fwrite_option_bytes(stlink_t *sl, const char* path, stm32_addr_t addr
*/
int stlink_fwrite_option_bytes_32bit(stlink_t *sl, uint32_t val) {
if(sl->chip_id == STLINK_CHIPID_STM32_F2){
if (sl->chip_id == STLINK_CHIPID_STM32_F2){
return stlink_write_option_bytes_f2(sl, val);
}else if(sl->chip_id == STLINK_CHIPID_STM32_F446){
} else if (sl->chip_id == STLINK_CHIPID_STM32_F446){
return stlink_write_option_bytes_f4(sl, val);
}
else

Wyświetl plik

@ -226,7 +226,7 @@ static int loader_v_dependent_assignment(stlink_t *sl,
{
int retval = 0;
if( sl->version.stlink_v == 1 ) {
if ( sl->version.stlink_v == 1){
printf("STLINK V1 cannot read voltage, defaulting to 32-bit writes\n");
*loader_code = high_v_loader;
*loader_size = high_v_loader_size;

Wyświetl plik

@ -27,7 +27,7 @@ int gdb_send_packet(int fd, char* data) {
packet[0] = '$';
uint8_t cksum = 0;
for(unsigned int i = 0; i < data_length; i++) {
for (unsigned int i = 0; i < data_length; i++) {
packet[i + 1] = data[i];
cksum += data[i];
}
@ -36,19 +36,19 @@ int gdb_send_packet(int fd, char* data) {
packet[length - 2] = hex[cksum >> 4];
packet[length - 1] = hex[cksum & 0xf];
while(1) {
if(write(fd, packet, length) != length) {
while (1) {
if (write(fd, packet, length) != length) {
free(packet);
return -2;
}
char ack;
if(read(fd, &ack, 1) != 1) {
if (read(fd, &ack, 1) != 1) {
free(packet);
return -2;
}
if(ack == '+') {
if (ack == '+') {
free(packet);
return 0;
}
@ -64,7 +64,7 @@ int gdb_recv_packet(int fd, char** buffer) {
char* packet_buffer = malloc(packet_size);
unsigned state;
if(packet_buffer == NULL)
if (packet_buffer == NULL)
return -2;
start:
@ -79,15 +79,15 @@ start:
*/
char c;
while(state != 4) {
if(read(fd, &c, 1) != 1) {
while (state != 4) {
if (read(fd, &c, 1) != 1) {
free(packet_buffer);
return -2;
}
switch(state) {
case 0:
if(c != '$') {
if (c != '$') {
// ignore
} else {
state = 1;
@ -95,16 +95,16 @@ start:
break;
case 1:
if(c == '#') {
if (c == '#') {
state = 2;
} else {
packet_buffer[packet_idx++] = c;
cksum += c;
if(packet_idx == packet_size) {
if (packet_idx == packet_size) {
packet_size += ALLOC_STEP;
void* p = realloc(packet_buffer, packet_size);
if(p != NULL)
if (p != NULL)
packet_buffer = p;
else {
free(packet_buffer);
@ -127,9 +127,9 @@ start:
}
uint8_t recv_cksum_int = strtoul(recv_cksum, NULL, 16);
if(recv_cksum_int != cksum) {
if (recv_cksum_int != cksum) {
char nack = '-';
if(write(fd, &nack, 1) != 1) {
if (write(fd, &nack, 1) != 1) {
free(packet_buffer);
return -2;
}
@ -137,7 +137,7 @@ start:
goto start;
} else {
char ack = '+';
if(write(fd, &ack, 1) != 1) {
if (write(fd, &ack, 1) != 1) {
free(packet_buffer);
return -2;
}
@ -157,13 +157,13 @@ int gdb_check_for_interrupt(int fd) {
pfd.fd = fd;
pfd.events = POLLIN;
if(poll(&pfd, 1, 0) != 0) {
if (poll(&pfd, 1, 0) != 0) {
char c;
if(read(fd, &c, 1) != 1)
if (read(fd, &c, 1) != 1)
return -2;
if(c == '\x03') // ^C
if (c == '\x03') // ^C
return 1;
}

Wyświetl plik

@ -89,10 +89,10 @@ static stlink_t* do_connect(st_state_t *st) {
stlink_t *ret = NULL;
switch (st->stlink_version) {
case 2:
if(serial_specified){
if (serial_specified){
ret = stlink_open_usb(st->logging_level, st->reset, serialnumber);
}
else{
else {
ret = stlink_open_usb(st->logging_level, st->reset, NULL);
}
break;
@ -199,8 +199,8 @@ int parse_options(int argc, char** argv, st_state_t *st) {
/** @todo This is not really portable, as strlen really returns size_t we need to obey and not cast it to a signed type. */
int j = (int)strlen(optarg);
int length = j / 2; //the length of the destination-array
if(j % 2 != 0) return -1;
for(size_t k = 0; j >= 0 && k < sizeof(serialnumber); ++k, j -= 2) {
if (j % 2 != 0) return -1;
for (size_t k = 0; j >= 0 && k < sizeof(serialnumber); ++k, j -= 2) {
char buffer[3] = {0};
memcpy(buffer, optarg + j, 2);
serialnumber[length - k] = (uint8_t)strtol(buffer, NULL, 16);
@ -234,7 +234,7 @@ int main(int argc, char** argv) {
printf("st-util %s\n", STLINK_VERSION);
sl = do_connect(&state);
if(sl == NULL) return 1;
if (sl == NULL) return 1;
connected_stlink = sl;
signal(SIGINT, &cleanup);
@ -255,7 +255,7 @@ int main(int argc, char** argv) {
#if defined(__MINGW32__) || defined(_MSC_VER)
WSADATA wsadata;
if (WSAStartup(MAKEWORD(2,2),&wsadata) !=0 ) {
if (WSAStartup(MAKEWORD(2,2),&wsadata) !=0){
goto winsock_error;
}
#endif
@ -532,27 +532,27 @@ char* make_memory_map(stlink_t *sl) {
char* map = malloc(sz);
map[0] = '\0';
if(sl->chip_id==STLINK_CHIPID_STM32_F4 || sl->chip_id==STLINK_CHIPID_STM32_F446 || sl->chip_id==STLINK_CHIPID_STM32_F411RE) {
if (sl->chip_id==STLINK_CHIPID_STM32_F4 || sl->chip_id==STLINK_CHIPID_STM32_F446 || sl->chip_id==STLINK_CHIPID_STM32_F411RE) {
strcpy(map, memory_map_template_F4);
} else if(sl->chip_id==STLINK_CHIPID_STM32_F4_DE) {
} else if (sl->chip_id==STLINK_CHIPID_STM32_F4_DE) {
strcpy(map, memory_map_template_F4_DE);
} else if(sl->core_id==STM32F7_CORE_ID) {
} else if (sl->core_id==STM32F7_CORE_ID) {
snprintf(map, sz, memory_map_template_F7,
(unsigned int)sl->sram_size);
} else if(sl->chip_id==STLINK_CHIPID_STM32_F4_HD) {
} else if (sl->chip_id==STLINK_CHIPID_STM32_F4_HD) {
strcpy(map, memory_map_template_F4_HD);
} else if(sl->chip_id==STLINK_CHIPID_STM32_F2) {
} else if (sl->chip_id==STLINK_CHIPID_STM32_F2) {
snprintf(map, sz, memory_map_template_F2,
(unsigned int)sl->flash_size,
(unsigned int)sl->sram_size,
(unsigned int)sl->flash_size - 0x20000,
(unsigned int)sl->sys_base, (unsigned int)sl->sys_size);
} else if((sl->chip_id==STLINK_CHIPID_STM32_L4) ||
} else if ((sl->chip_id==STLINK_CHIPID_STM32_L4) ||
(sl->chip_id==STLINK_CHIPID_STM32_L43X) ||
(sl->chip_id==STLINK_CHIPID_STM32_L46X)) {
snprintf(map, sz, memory_map_template_L4,
(unsigned int)sl->flash_size, (unsigned int)sl->flash_size);
} else if(sl->chip_id==STLINK_CHIPID_STM32_L496X) {
} else if (sl->chip_id==STLINK_CHIPID_STM32_L496X) {
snprintf(map, sz, memory_map_template_L496,
(unsigned int)sl->flash_size, (unsigned int)sl->flash_size);
} else {
@ -603,7 +603,7 @@ static void init_data_watchpoints(stlink_t *sl) {
stlink_write_debug32(sl, 0xE000EDFC, data);
// make sure all watchpoints are cleared
for(int i = 0; i < DATA_WATCH_NUM; i++) {
for (int i = 0; i < DATA_WATCH_NUM; i++) {
data_watches[i].fun = WATCHDISABLED;
stlink_write_debug32(sl, 0xe0001028 + i * 16, 0);
}
@ -620,15 +620,15 @@ static int add_data_watchpoint(stlink_t *sl, enum watchfun wf,
mask = -1;
i = len;
while(i) {
while (i) {
i >>= 1;
mask++;
}
if((mask != (uint32_t)-1) && (mask < 16)) {
for(i = 0; i < DATA_WATCH_NUM; i++) {
if ((mask != (uint32_t)-1) && (mask < 16)) {
for (i = 0; i < DATA_WATCH_NUM; i++) {
// is this an empty slot ?
if(data_watches[i].fun == WATCHDISABLED) {
if (data_watches[i].fun == WATCHDISABLED) {
DLOG("insert watchpoint %d addr %x wf %u mask %u len %d\n", i, addr, wf, mask, len);
data_watches[i].fun = wf;
@ -659,8 +659,8 @@ static int delete_data_watchpoint(stlink_t *sl, stm32_addr_t addr)
{
int i;
for(i = 0 ; i < DATA_WATCH_NUM; i++) {
if((data_watches[i].addr == addr) && (data_watches[i].fun != WATCHDISABLED)) {
for (i = 0 ; i < DATA_WATCH_NUM; i++) {
if ((data_watches[i].addr == addr) && (data_watches[i].fun != WATCHDISABLED)) {
DLOG("delete watchpoint %d addr %x\n", i, addr);
data_watches[i].fun = WATCHDISABLED;
@ -698,7 +698,7 @@ static void init_code_breakpoints(stlink_t *sl) {
ILOG("Found %i hw breakpoint registers\n", code_break_num);
for(int i = 0; i < code_break_num; i++) {
for (int i = 0; i < code_break_num; i++) {
code_breaks[i].type = 0;
stlink_write_debug32(sl, STLINK_REG_CM3_FP_COMP0 + i * 4, 0);
}
@ -706,7 +706,7 @@ static void init_code_breakpoints(stlink_t *sl) {
static int has_breakpoint(stm32_addr_t addr)
{
for(int i = 0; i < code_break_num; i++) {
for (int i = 0; i < code_break_num; i++) {
if (code_breaks[i].addr == addr) {
return 1;
}
@ -719,7 +719,7 @@ static int update_code_breakpoint(stlink_t *sl, stm32_addr_t addr, int set) {
uint32_t mask;
int type = (addr & 0x2) ? CODE_BREAK_HIGH : CODE_BREAK_LOW;
if(addr & 1) {
if (addr & 1) {
ELOG("update_code_breakpoint: unaligned address %08x\n", addr);
return -1;
}
@ -731,16 +731,16 @@ static int update_code_breakpoint(stlink_t *sl, stm32_addr_t addr, int set) {
}
int id = -1;
for(int i = 0; i < code_break_num; i++) {
if(fpb_addr == code_breaks[i].addr ||
for (int i = 0; i < code_break_num; i++) {
if (fpb_addr == code_breaks[i].addr ||
(set && code_breaks[i].type == 0)) {
id = i;
break;
}
}
if(id == -1) {
if(set) return -1; // Free slot not found
if (id == -1) {
if (set) return -1; // Free slot not found
else return 0; // Breakpoint is already removed
}
@ -749,18 +749,18 @@ static int update_code_breakpoint(stlink_t *sl, stm32_addr_t addr, int set) {
bp->addr = fpb_addr;
if (sl->core_id==STM32F7_CORE_ID) {
if(set) bp->type = type;
if (set) bp->type = type;
else bp->type = 0;
mask = (bp->addr) | 1;
} else {
if(set) bp->type |= type;
if (set) bp->type |= type;
else bp->type &= ~type;
mask = (bp->addr) | 1 | (bp->type << 30);
}
if(bp->type == 0) {
if (bp->type == 0) {
DLOG("clearing hw break %d\n", id);
stlink_write_debug32(sl, 0xe0002008 + id * 4, 0);
@ -789,13 +789,13 @@ static struct flash_block* flash_root;
static int flash_add_block(stm32_addr_t addr, unsigned length, stlink_t *sl) {
if(addr < FLASH_BASE || addr + length > FLASH_BASE + sl->flash_size) {
if (addr < FLASH_BASE || addr + length > FLASH_BASE + sl->flash_size) {
ELOG("flash_add_block: incorrect bounds\n");
return -1;
}
stlink_calculate_pagesize(sl, addr);
if(addr % FLASH_PAGE != 0 || length % FLASH_PAGE != 0) {
if (addr % FLASH_PAGE != 0 || length % FLASH_PAGE != 0) {
ELOG("flash_add_block: unaligned block\n");
return -1;
}
@ -815,7 +815,7 @@ static int flash_add_block(stm32_addr_t addr, unsigned length, stlink_t *sl) {
static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
unsigned int fit_blocks = 0, fit_length = 0;
for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
for (struct flash_block* fb = flash_root; fb; fb = fb->next) {
/* Block: ------X------Y--------
* Data: a-----b
* a--b
@ -826,7 +826,7 @@ static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
unsigned X = fb->addr, Y = fb->addr + fb->length;
unsigned a = addr, b = addr + length;
if(a < Y && b > X) {
if (a < Y && b > X) {
// from start of the block
unsigned start = (a > X ? a : X) - X;
unsigned end = (b > Y ? Y : b) - X;
@ -838,12 +838,12 @@ static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
}
}
if(fit_blocks == 0) {
if (fit_blocks == 0) {
ELOG("Unfit data block %08x -> %04x\n", addr, length);
return -1;
}
if(fit_length != length) {
if (fit_length != length) {
WLOG("data block %08x -> %04x truncated to %04x\n",
addr, length, fit_length);
WLOG("(this is not an error, just a GDB glitch)\n");
@ -859,10 +859,10 @@ static int flash_go(stlink_t *sl) {
stlink_reset(sl);
stlink_force_debug(sl);
for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
for (struct flash_block* fb = flash_root; fb; fb = fb->next) {
DLOG("flash_do: block %08x -> %04x\n", fb->addr, fb->length);
for(stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += (uint32_t)FLASH_PAGE) {
for (stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += (uint32_t)FLASH_PAGE) {
unsigned length = fb->length - (page - fb->addr);
//Update FLASH_PAGE
@ -881,7 +881,7 @@ static int flash_go(stlink_t *sl) {
error = 0;
error:
for(struct flash_block* fb = flash_root, *next; fb; fb = next) {
for (struct flash_block* fb = flash_root, *next; fb; fb = next) {
next = fb->next;
free(fb->data);
free(fb);
@ -956,7 +956,7 @@ static void init_cache (stlink_t *sl) {
int i;
/* Assume only F7 has a cache. */
if(sl->core_id!=STM32F7_CORE_ID)
if (sl->core_id!=STM32F7_CORE_ID)
return;
stlink_read_debug32(sl, CLIDR, &clidr);
@ -972,14 +972,14 @@ static void init_cache (stlink_t *sl) {
(clidr >> 27) & 7, (clidr >> 24) & 7, (clidr >> 21) & 7);
ILOG(" cache: ctr: %08x, DminLine: %u bytes, IminLine: %u bytes\n", ctr,
cache_desc.dminline, cache_desc.iminline);
for(i = 0; i < 7; i++)
for (i = 0; i < 7; i++)
{
unsigned int ct = (clidr >> (3 * i)) & 0x07;
cache_desc.dcache[i].width = 0;
cache_desc.icache[i].width = 0;
if(ct == 2 || ct == 3 || ct == 4)
if (ct == 2 || ct == 3 || ct == 4)
{
/* Data. */
stlink_write_debug32(sl, CSSELR, i << 1);
@ -987,7 +987,7 @@ static void init_cache (stlink_t *sl) {
read_cache_level_desc(sl, &cache_desc.dcache[i]);
}
if(ct == 1 || ct == 3)
if (ct == 1 || ct == 3)
{
/* Instruction. */
stlink_write_debug32(sl, CSSELR, (i << 1) | 1);
@ -1035,7 +1035,7 @@ static void cache_sync(stlink_t *sl)
{
unsigned ccr;
if(sl->core_id!=STM32F7_CORE_ID)
if (sl->core_id!=STM32F7_CORE_ID)
return;
if (!cache_modified)
return;
@ -1063,7 +1063,7 @@ static size_t unhexify(const char *in, char *out, size_t out_count)
int serve(stlink_t *sl, st_state_t *st) {
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
if(!IS_SOCK_VALID(sock)) {
if (!IS_SOCK_VALID(sock)) {
perror("socket");
return 1;
}
@ -1077,13 +1077,13 @@ int serve(stlink_t *sl, st_state_t *st) {
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(st->listen_port);
if(bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
if (bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
perror("bind");
close_socket(sock);
return 1;
}
if(listen(sock, 5) < 0) {
if (listen(sock, 5) < 0) {
perror("listen");
close_socket(sock);
return 1;
@ -1093,7 +1093,7 @@ int serve(stlink_t *sl, st_state_t *st) {
SOCKET client = accept(sock, NULL, NULL);
//signal (SIGINT, SIG_DFL);
if(!IS_SOCK_VALID(client)) {
if (!IS_SOCK_VALID(client)) {
perror("accept");
close_socket(sock);
return 1;
@ -1120,12 +1120,12 @@ int serve(stlink_t *sl, st_state_t *st) {
*/
int critical_error = 0;
int ret;
while(1) {
while (1) {
ret = 0;
char* packet;
int status = gdb_recv_packet(client, &packet);
if(status < 0) {
if (status < 0) {
ELOG("cannot recv: %d\n", status);
close_socket(client);
return 1;
@ -1138,13 +1138,13 @@ int serve(stlink_t *sl, st_state_t *st) {
switch(packet[0]) {
case 'q': {
if(packet[1] == 'P' || packet[1] == 'C' || packet[1] == 'L') {
if (packet[1] == 'P' || packet[1] == 'C' || packet[1] == 'L') {
reply = strdup("");
break;
}
char *separator = strstr(packet, ":"), *params = "";
if(separator == NULL) {
if (separator == NULL) {
separator = packet + strlen(packet);
} else {
params = separator + 1;
@ -1156,8 +1156,8 @@ int serve(stlink_t *sl, st_state_t *st) {
DLOG("query: %s;%s\n", queryName, params);
if(!strcmp(queryName, "Supported")) {
if(sl->chip_id==STLINK_CHIPID_STM32_F4
if (!strcmp(queryName, "Supported")) {
if (sl->chip_id==STLINK_CHIPID_STM32_F4
|| sl->chip_id==STLINK_CHIPID_STM32_F4_HD
|| sl->core_id==STM32F7_CORE_ID) {
reply = strdup("PacketSize=3fff;qXfer:memory-map:read+;qXfer:features:read+");
@ -1165,7 +1165,7 @@ int serve(stlink_t *sl, st_state_t *st) {
else {
reply = strdup("PacketSize=3fff;qXfer:memory-map:read+");
}
} else if(!strcmp(queryName, "Xfer")) {
} else if (!strcmp(queryName, "Xfer")) {
char *type, *op, *__s_addr, *s_length;
char *tok = params;
char *annex __attribute__((unused));
@ -1184,18 +1184,18 @@ int serve(stlink_t *sl, st_state_t *st) {
const char* data = NULL;
if(!strcmp(type, "memory-map") && !strcmp(op, "read"))
if (!strcmp(type, "memory-map") && !strcmp(op, "read"))
data = current_memory_map;
if(!strcmp(type, "features") && !strcmp(op, "read"))
if (!strcmp(type, "features") && !strcmp(op, "read"))
data = target_description_F4;
if(data) {
if (data) {
unsigned data_length = (unsigned int) strlen(data);
if(addr + length > data_length)
if (addr + length > data_length)
length = data_length - addr;
if(length == 0) {
if (length == 0) {
reply = strdup("l");
} else {
reply = calloc(length + 2, 1);
@ -1203,11 +1203,11 @@ int serve(stlink_t *sl, st_state_t *st) {
strncpy(&reply[1], data, length);
}
}
} else if(!strncmp(queryName, "Rcmd,",4)) {
} else if (!strncmp(queryName, "Rcmd,",4)) {
// Rcmd uses the wrong separator
separator = strstr(packet, ",");
params = "";
if(separator == NULL) {
if (separator == NULL) {
separator = packet + strlen(packet);
} else {
params = separator + 1;
@ -1328,7 +1328,7 @@ int serve(stlink_t *sl, st_state_t *st) {
free(cmd);
}
if(reply == NULL)
if (reply == NULL)
reply = strdup("");
free(queryName);
@ -1342,7 +1342,7 @@ int serve(stlink_t *sl, st_state_t *st) {
cmdName++; // vCommand -> Command
if(!strcmp(cmdName, "FlashErase")) {
if (!strcmp(cmdName, "FlashErase")) {
char *__s_addr, *s_length;
char *tok = params;
@ -1355,12 +1355,12 @@ int serve(stlink_t *sl, st_state_t *st) {
DLOG("FlashErase: addr:%08x,len:%04x\n",
addr, length);
if(flash_add_block(addr, length, sl) < 0) {
if (flash_add_block(addr, length, sl) < 0) {
reply = strdup("E00");
} else {
reply = strdup("OK");
}
} else if(!strcmp(cmdName, "FlashWrite")) {
} else if (!strcmp(cmdName, "FlashWrite")) {
char *__s_addr, *data;
char *tok = params;
@ -1375,8 +1375,8 @@ int serve(stlink_t *sl, st_state_t *st) {
// Additional byte is reserved for alignment fix.
uint8_t *decoded = calloc(data_length + 1, 1);
unsigned dec_index = 0;
for(unsigned int i = 0; i < data_length; i++) {
if(data[i] == 0x7d) {
for (unsigned int i = 0; i < data_length; i++) {
if (data[i] == 0x7d) {
i++;
decoded[dec_index++] = data[i] ^ 0x20;
} else {
@ -1385,31 +1385,31 @@ int serve(stlink_t *sl, st_state_t *st) {
}
// Fix alignment
if(dec_index % 2 != 0)
if (dec_index % 2 != 0)
dec_index++;
DLOG("binary packet %d -> %d\n", data_length, dec_index);
if(flash_populate(addr, decoded, dec_index) < 0) {
if (flash_populate(addr, decoded, dec_index) < 0) {
reply = strdup("E00");
} else {
reply = strdup("OK");
}
free(decoded);
} else if(!strcmp(cmdName, "FlashDone")) {
if(flash_go(sl) < 0) {
} else if (!strcmp(cmdName, "FlashDone")) {
if (flash_go(sl) < 0) {
reply = strdup("E00");
} else {
reply = strdup("OK");
}
} else if(!strcmp(cmdName, "Kill")) {
} else if (!strcmp(cmdName, "Kill")) {
attached = 0;
reply = strdup("OK");
}
if(reply == NULL)
if (reply == NULL)
reply = strdup("");
break;
@ -1422,15 +1422,15 @@ int serve(stlink_t *sl, st_state_t *st) {
DLOG("Semihost: run failed\n");
}
while(1) {
while (1) {
status = gdb_check_for_interrupt(client);
if(status < 0) {
if (status < 0) {
ELOG("cannot check for int: %d\n", status);
close_socket(client);
return 1;
}
if(status == 1) {
if (status == 1) {
stlink_force_debug(sl);
break;
}
@ -1439,7 +1439,7 @@ int serve(stlink_t *sl, st_state_t *st) {
if (ret) {
DLOG("Semihost: status failed\n");
}
if(sl->core_stat == STLINK_CORE_HALTED) {
if (sl->core_stat == STLINK_CORE_HALTED) {
struct stlink_reg reg;
stm32_addr_t pc;
stm32_addr_t addr;
@ -1526,7 +1526,7 @@ int serve(stlink_t *sl, st_state_t *st) {
break;
case '?':
if(attached) {
if (attached) {
reply = strdup("S05"); // TRAP
} else {
/* Stub shall reply OK if not attached. */
@ -1541,7 +1541,7 @@ int serve(stlink_t *sl, st_state_t *st) {
}
reply = calloc(8 * 16 + 1, 1);
for(int i = 0; i < 16; i++)
for (int i = 0; i < 16; i++)
sprintf(&reply[i * 8], "%08x", (uint32_t)htonl(regp.r[i]));
break;
@ -1550,34 +1550,34 @@ int serve(stlink_t *sl, st_state_t *st) {
unsigned id = (unsigned int) strtoul(&packet[1], NULL, 16);
unsigned myreg = 0xDEADDEAD;
if(id < 16) {
if (id < 16) {
ret = stlink_read_reg(sl, id, &regp);
myreg = htonl(regp.r[id]);
} else if(id == 0x19) {
} else if (id == 0x19) {
ret = stlink_read_reg(sl, 16, &regp);
myreg = htonl(regp.xpsr);
} else if(id == 0x1A) {
} else if (id == 0x1A) {
ret = stlink_read_reg(sl, 17, &regp);
myreg = htonl(regp.main_sp);
} else if(id == 0x1B) {
} else if (id == 0x1B) {
ret = stlink_read_reg(sl, 18, &regp);
myreg = htonl(regp.process_sp);
} else if(id == 0x1C) {
} else if (id == 0x1C) {
ret = stlink_read_unsupported_reg(sl, id, &regp);
myreg = htonl(regp.control);
} else if(id == 0x1D) {
} else if (id == 0x1D) {
ret = stlink_read_unsupported_reg(sl, id, &regp);
myreg = htonl(regp.faultmask);
} else if(id == 0x1E) {
} else if (id == 0x1E) {
ret = stlink_read_unsupported_reg(sl, id, &regp);
myreg = htonl(regp.basepri);
} else if(id == 0x1F) {
} else if (id == 0x1F) {
ret = stlink_read_unsupported_reg(sl, id, &regp);
myreg = htonl(regp.primask);
} else if(id >= 0x20 && id < 0x40) {
} else if (id >= 0x20 && id < 0x40) {
ret = stlink_read_unsupported_reg(sl, id, &regp);
myreg = htonl(regp.s[id-0x20]);
} else if(id == 0x40) {
} else if (id == 0x40) {
ret = stlink_read_unsupported_reg(sl, id, &regp);
myreg = htonl(regp.fpscr);
} else {
@ -1605,25 +1605,25 @@ int serve(stlink_t *sl, st_state_t *st) {
unsigned value = (unsigned int) strtoul(s_value, NULL, 16);
if(reg < 16) {
if (reg < 16) {
ret = stlink_write_reg(sl, ntohl(value), reg);
} else if(reg == 0x19) {
} else if (reg == 0x19) {
ret = stlink_write_reg(sl, ntohl(value), 16);
} else if(reg == 0x1A) {
} else if (reg == 0x1A) {
ret = stlink_write_reg(sl, ntohl(value), 17);
} else if(reg == 0x1B) {
} else if (reg == 0x1B) {
ret = stlink_write_reg(sl, ntohl(value), 18);
} else if(reg == 0x1C) {
} else if (reg == 0x1C) {
ret = stlink_write_unsupported_reg(sl, ntohl(value), reg, &regp);
} else if(reg == 0x1D) {
} else if (reg == 0x1D) {
ret = stlink_write_unsupported_reg(sl, ntohl(value), reg, &regp);
} else if(reg == 0x1E) {
} else if (reg == 0x1E) {
ret = stlink_write_unsupported_reg(sl, ntohl(value), reg, &regp);
} else if(reg == 0x1F) {
} else if (reg == 0x1F) {
ret = stlink_write_unsupported_reg(sl, ntohl(value), reg, &regp);
} else if(reg >= 0x20 && reg < 0x40) {
} else if (reg >= 0x20 && reg < 0x40) {
ret = stlink_write_unsupported_reg(sl, ntohl(value), reg, &regp);
} else if(reg == 0x40) {
} else if (reg == 0x40) {
ret = stlink_write_unsupported_reg(sl, ntohl(value), reg, &regp);
} else {
ret = 1;
@ -1632,7 +1632,7 @@ int serve(stlink_t *sl, st_state_t *st) {
if (ret) {
DLOG("P packet: stlink_write_unsupported_reg failed with reg %u\n", reg);
}
if(reply == NULL) {
if (reply == NULL) {
// note that NULL may not be zero
reply = strdup("OK");
}
@ -1641,7 +1641,7 @@ int serve(stlink_t *sl, st_state_t *st) {
}
case 'G':
for(int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++) {
char str[9] = {0};
strncpy(str, &packet[1 + i * 8], 8);
uint32_t reg = (uint32_t) strtoul(str, NULL, 16);
@ -1676,7 +1676,7 @@ int serve(stlink_t *sl, st_state_t *st) {
}
reply = calloc(count * 2 + 1, 1);
for(unsigned int i = 0; i < count; i++) {
for (unsigned int i = 0; i < count; i++) {
reply[i * 2 + 0] = hex[sl->q_buf[i + adj_start] >> 4];
reply[i * 2 + 1] = hex[sl->q_buf[i + adj_start] & 0xf];
}
@ -1693,10 +1693,10 @@ int serve(stlink_t *sl, st_state_t *st) {
unsigned count = (unsigned int) strtoul(s_count, NULL, 16);
int err = 0;
if(start % 4) {
if (start % 4) {
unsigned align_count = 4 - start % 4;
if (align_count > count) align_count = count;
for(unsigned int i = 0; i < align_count; i ++) {
for (unsigned int i = 0; i < align_count; i ++) {
char hextmp[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hextmp, NULL, 16);
sl->q_buf[i] = byte;
@ -1708,10 +1708,10 @@ int serve(stlink_t *sl, st_state_t *st) {
hexdata += 2*align_count;
}
if(count - count % 4) {
if (count - count % 4) {
unsigned aligned_count = count - count % 4;
for(unsigned int i = 0; i < aligned_count; i ++) {
for (unsigned int i = 0; i < aligned_count; i ++) {
char hextmp[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hextmp, NULL, 16);
sl->q_buf[i] = byte;
@ -1723,8 +1723,8 @@ int serve(stlink_t *sl, st_state_t *st) {
hexdata += 2*aligned_count;
}
if(count) {
for(unsigned int i = 0; i < count; i ++) {
if (count) {
for (unsigned int i = 0; i < count; i ++) {
char hextmp[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hextmp, NULL, 16);
sl->q_buf[i] = byte;
@ -1743,7 +1743,7 @@ int serve(stlink_t *sl, st_state_t *st) {
switch (packet[1]) {
case '1':
if(update_code_breakpoint(sl, addr, 1) < 0) {
if (update_code_breakpoint(sl, addr, 1) < 0) {
reply = strdup("E00");
} else {
reply = strdup("OK");
@ -1754,15 +1754,15 @@ int serve(stlink_t *sl, st_state_t *st) {
case '3': // insert read watchpoint
case '4': { // insert access watchpoint
enum watchfun wf;
if(packet[1] == '2') {
if (packet[1] == '2') {
wf = WATCHWRITE;
} else if(packet[1] == '3') {
} else if (packet[1] == '3') {
wf = WATCHREAD;
} else {
wf = WATCHACCESS;
}
if(add_data_watchpoint(sl, wf, addr, len) < 0) {
if (add_data_watchpoint(sl, wf, addr, len) < 0) {
reply = strdup("E00");
} else {
reply = strdup("OK");
@ -1790,7 +1790,7 @@ int serve(stlink_t *sl, st_state_t *st) {
case '2' : // remove write watchpoint
case '3' : // remove read watchpoint
case '4' : // remove access watchpoint
if(delete_data_watchpoint(sl, addr) < 0) {
if (delete_data_watchpoint(sl, addr) < 0) {
reply = strdup("E00");
break;
} else {
@ -1852,7 +1852,7 @@ int serve(stlink_t *sl, st_state_t *st) {
stlink_close(sl);
sl = do_connect(st);
if(sl == NULL) cleanup(0);
if (sl == NULL) cleanup(0);
connected_stlink = sl;
if (st->reset) {
@ -1874,11 +1874,11 @@ int serve(stlink_t *sl, st_state_t *st) {
reply = strdup("");
}
if(reply) {
if (reply) {
DLOG("send: %s\n", reply);
int result = gdb_send_packet(client, reply);
if(result != 0) {
if (result != 0) {
ELOG("cannot send: %d\n", result);
free(reply);
free(packet);

Wyświetl plik

@ -178,7 +178,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
uint32_t name_len;
char *name;
if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
if (mem_read(sl, r1, args, sizeof (args)) != 0){
DLOG("Semihosting SYS_OPEN error: "
"cannot read args from target memory\n");
*ret = -1;
@ -215,7 +215,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
return -1;
}
if (mem_read(sl, name_address, name, name_len) != 0 ) {
if (mem_read(sl, name_address, name, name_len) != 0){
free(name);
*ret = -1;
DLOG("Semihosting SYS_OPEN error: "
@ -238,7 +238,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
uint32_t args[1];
int fd;
if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
if (mem_read(sl, r1, args, sizeof (args)) != 0){
DLOG("Semihosting SYS_CLOSE error: "
"cannot read args from target memory\n");
*ret = -1;
@ -263,7 +263,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
uint32_t buffer_len;
void *buffer;
if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
if (mem_read(sl, r1, args, sizeof (args)) != 0){
DLOG("Semihosting SYS_WRITE error: "
"cannot read args from target memory\n");
*ret = -1;
@ -289,7 +289,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
return -1;
}
if (mem_read(sl, buffer_address, buffer, buffer_len) != 0 ) {
if (mem_read(sl, buffer_address, buffer, buffer_len) != 0){
DLOG("Semihosting SYS_WRITE error: "
"cannot read buffer from target memory\n");
free(buffer);
@ -322,7 +322,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
void *buffer;
ssize_t read_result;
if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
if (mem_read(sl, r1, args, sizeof (args)) != 0){
DLOG("Semihosting SYS_READ error: "
"cannot read args from target memory\n");
*ret = -1;
@ -357,7 +357,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
if (read_result == -1) {
*ret = buffer_len;
} else {
if (mem_write(sl, buffer_address, buffer, read_result) != 0 ) {
if (mem_write(sl, buffer_address, buffer, read_result) != 0){
DLOG("Semihosting SYS_READ error: "
"cannot write buffer to target memory\n");
free(buffer);
@ -385,7 +385,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
uint32_t name_len;
char *name;
if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
if (mem_read(sl, r1, args, sizeof (args)) != 0){
DLOG("Semihosting SYS_REMOVE error: "
"cannot read args from target memory\n");
*ret = -1;
@ -414,7 +414,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
return -1;
}
if (mem_read(sl, name_address, name, name_len) != 0 ) {
if (mem_read(sl, name_address, name, name_len) != 0){
free(name);
*ret = -1;
DLOG("Semihosting SYS_REMOVE error: "
@ -438,7 +438,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
int fd;
off_t offset;
if (mem_read(sl, r1, args, sizeof (args)) != 0 ) {
if (mem_read(sl, r1, args, sizeof (args)) != 0){
DLOG("Semihosting SYS_SEEK error: "
"cannot read args from target memory\n");
*ret = -1;
@ -482,7 +482,7 @@ int do_semihosting (stlink_t *sl, uint32_t r0, uint32_t r1, uint32_t *ret) {
uint8_t buf[WRITE0_BUFFER_SIZE];
while (true) {
if (mem_read(sl, r1, buf, WRITE0_BUFFER_SIZE) != 0 ) {
if (mem_read(sl, r1, buf, WRITE0_BUFFER_SIZE) != 0){
DLOG("Semihosting WRITE0: "
"cannot read target memory at 0x%08x\n", r1);
return -1;

Wyświetl plik

@ -70,7 +70,7 @@ void*
#define GET(n) (ctx->block[(n)])
#define SET(n) (ctx->block[(n)] = \
((uint32_t)ptr[(n)*4 + 0] << 0 ) \
((uint32_t)ptr[(n)*4 + 0] << 0) \
| ((uint32_t)ptr[(n)*4 + 1] << 8 ) \
| ((uint32_t)ptr[(n)*4 + 2] << 16) \
| ((uint32_t)ptr[(n)*4 + 3] << 24) )
@ -167,7 +167,7 @@ void*
d += saved_d;
ptr += 64;
} while( size -= 64 );
} while ( size -= 64 );
ctx->a = a;
ctx->b = b;
@ -223,7 +223,7 @@ void
uint32_t free;
saved_lo = Context->lo;
if( (Context->lo = (saved_lo + BufferSize) & 0x1fffffff) < saved_lo )
if ( (Context->lo = (saved_lo + BufferSize) & 0x1fffffff) < saved_lo )
{
Context->hi++;
}
@ -231,11 +231,11 @@ void
used = saved_lo & 0x3f;
if( used )
if ( used )
{
free = 64 - used;
if( BufferSize < free )
if ( BufferSize < free )
{
memcpy( &Context->buffer[used], Buffer, BufferSize );
return;
@ -247,7 +247,7 @@ void
TransformFunction(Context, Context->buffer, 64);
}
if( BufferSize >= 64 )
if ( BufferSize >= 64 )
{
Buffer = TransformFunction( Context, Buffer, BufferSize & ~(unsigned long)0x3f );
BufferSize &= 0x3f;
@ -278,7 +278,7 @@ void
free = 64 - used;
if(free < 8)
if (free < 8)
{
memset( &Context->buffer[used], 0, free );
TransformFunction( Context, Context->buffer, 64 );

Wyświetl plik

@ -27,11 +27,11 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
FD_ZERO(&efds);
for (i = 0, op = ip = 0; i < nfds; ++i) {
fds[i].revents = 0;
if(fds[i].events & (POLLIN|POLLPRI)) {
if (fds[i].events & (POLLIN|POLLPRI)) {
ip = &ifds;
FD_SET(fds[i].fd, ip);
}
if(fds[i].events & POLLOUT) {
if (fds[i].events & POLLOUT) {
op = &ofds;
FD_SET(fds[i].fd, op);
}
@ -42,7 +42,7 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
#endif
/* Set up the timeval structure for the timeout parameter */
if(timo < 0) {
if (timo < 0) {
toptr = 0;
} else {
toptr = &timeout;
@ -59,17 +59,17 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
printf("Exiting select rc=%d\n", rc);
#endif
if(rc <= 0)
if (rc <= 0)
return rc;
if(rc > 0) {
if (rc > 0) {
for ( i = 0; i < nfds; ++i) {
int fd = fds[i].fd;
if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
if (fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
fds[i].revents |= POLLIN;
if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
if (fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
fds[i].revents |= POLLOUT;
if(FD_ISSET(fd, &efds))
if (FD_ISSET(fd, &efds))
/* Some error was detected ... should be some way to know. */
fds[i].revents |= POLLHUP;
#ifdef DEBUG_POLL
@ -118,7 +118,7 @@ SOCKET
win32_socket(int domain, int type, int protocol)
{
SOCKET fd = socket(domain, type, protocol);
if(fd == INVALID_SOCKET) {
if (fd == INVALID_SOCKET) {
set_socket_errno(WSAGetLastError());
}
return fd;
@ -133,7 +133,7 @@ win32_connect(SOCKET fd, struct sockaddr *addr, socklen_t addr_len)
{
int rc = connect(fd, addr, addr_len);
assert(rc == 0 || rc == SOCKET_ERROR);
if(rc == SOCKET_ERROR) {
if (rc == SOCKET_ERROR) {
set_connect_errno(WSAGetLastError());
}
return rc;
@ -148,7 +148,7 @@ SOCKET
win32_accept(SOCKET fd, struct sockaddr *addr, socklen_t *addr_len)
{
SOCKET newfd = accept(fd, addr, addr_len);
if(newfd == INVALID_SOCKET) {
if (newfd == INVALID_SOCKET) {
set_socket_errno(WSAGetLastError());
newfd = (SOCKET)-1;
}
@ -165,7 +165,7 @@ win32_shutdown(SOCKET fd, int mode)
{
int rc = shutdown(fd, mode);
assert(rc == 0 || rc == SOCKET_ERROR);
if(rc == SOCKET_ERROR) {
if (rc == SOCKET_ERROR) {
set_socket_errno(WSAGetLastError());
}
return rc;
@ -174,7 +174,7 @@ win32_shutdown(SOCKET fd, int mode)
int win32_close_socket(SOCKET fd)
{
int rc = closesocket(fd);
if(rc == SOCKET_ERROR) {
if (rc == SOCKET_ERROR) {
set_socket_errno(WSAGetLastError());
}
return rc;
@ -183,7 +183,7 @@ int win32_close_socket(SOCKET fd)
ssize_t win32_write_socket(SOCKET fd, void *buf, int n)
{
int rc = send(fd, buf, n, 0);
if(rc == SOCKET_ERROR) {
if (rc == SOCKET_ERROR) {
set_socket_errno(WSAGetLastError());
}
return rc;
@ -192,7 +192,7 @@ ssize_t win32_write_socket(SOCKET fd, void *buf, int n)
ssize_t win32_read_socket(SOCKET fd, void *buf, int n)
{
int rc = recv(fd, buf, n, 0);
if(rc == SOCKET_ERROR) {
if (rc == SOCKET_ERROR) {
set_socket_errno(WSAGetLastError());
}
return rc;

Wyświetl plik

@ -921,9 +921,9 @@ static stlink_t* stlink_open(const int verbose) {
struct stlink_libsg *slsg = malloc(sizeof (struct stlink_libsg));
if (sl == NULL || slsg == NULL) {
WLOG("Couldn't malloc stlink and stlink_sg structures out of memory!\n");
if(sl != NULL)
if (sl != NULL)
free(sl);
if(slsg != NULL)
if (slsg != NULL)
free(slsg);
return NULL;
}

Wyświetl plik

@ -129,7 +129,7 @@ int main(int ac, char** av)
if (o.cmd == FLASH_CMD_WRITE) /* write */
{
size_t size = 0;
if(o.format == FLASH_FORMAT_IHEX) {
if (o.format == FLASH_FORMAT_IHEX) {
err = stlink_parse_ihex(o.filename, stlink_get_erased_pattern(sl), &mem, &size, &o.addr);
if (err == -1) {
printf("Cannot parse %s as Intel-HEX file\n", o.filename);
@ -138,7 +138,7 @@ int main(int ac, char** av)
}
if ((o.addr >= sl->flash_base) &&
(o.addr < sl->flash_base + sl->flash_size)) {
if(o.format == FLASH_FORMAT_IHEX)
if (o.format == FLASH_FORMAT_IHEX)
err = stlink_mwrite_flash(sl, mem, (uint32_t)size, o.addr);
else
err = stlink_fwrite_flash(sl, o.filename, o.addr);
@ -150,7 +150,7 @@ int main(int ac, char** av)
}
else if ((o.addr >= sl->sram_base) &&
(o.addr < sl->sram_base + sl->sram_size)) {
if(o.format == FLASH_FORMAT_IHEX)
if (o.format == FLASH_FORMAT_IHEX)
err = stlink_mwrite_sram(sl, mem, (uint32_t)size, o.addr);
else
err = stlink_fwrite_sram(sl, o.filename, o.addr);
@ -207,19 +207,19 @@ int main(int ac, char** av)
}
else /* read */
{
if(o.area == FLASH_OPTION_BYTES){
if(sl->chip_id == STLINK_CHIPID_STM32_F2){
if (o.area == FLASH_OPTION_BYTES){
if (sl->chip_id == STLINK_CHIPID_STM32_F2){
uint32_t option_byte = 0;
err = stlink_read_option_bytes_f2(sl,&option_byte);
printf("%x\n",option_byte);
}else if(sl->chip_id == STLINK_CHIPID_STM32_F446){
} else if (sl->chip_id == STLINK_CHIPID_STM32_F446){
uint32_t option_byte = 0;
err = stlink_read_option_bytes_f4(sl,&option_byte);
printf("%x\n",option_byte);
}else{
} else {
printf("This format is available for STM32F2 and STM32F4 only\n");
}
}else{
} else {
if ((o.addr >= sl->flash_base) && (o.size == 0) &&
(o.addr < sl->flash_base + sl->flash_size)){
o.size = sl->flash_size;

Wyświetl plik

@ -28,7 +28,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
o->log_level = STND_LOG_LEVEL;
// options
while(ac >= 1) {
while (ac >= 1) {
if (strcmp(av[0], "--version") == 0) {
printf("v%s\n", STLINK_VERSION);
exit(EXIT_SUCCESS);
@ -44,7 +44,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
}
else if (strcmp(av[0], "--serial") == 0 || starts_with(av[0], "--serial=")) {
const char * serial;
if(strcmp(av[0], "--serial") == 0) {
if (strcmp(av[0], "--serial") == 0) {
ac--;
av++;
if (ac < 1) return -1;
@ -56,8 +56,8 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
/** @todo This is not really portable, as strlen really returns size_t we need to obey and not cast it to a signed type. */
int j = (int)strlen(serial);
int length = j / 2; // the length of the destination-array
if(j % 2 != 0) return -1;
for(size_t k = 0; j >= 0 && k < sizeof(o->serial); ++k, j -= 2) {
if (j % 2 != 0) return -1;
for (size_t k = 0; j >= 0 && k < sizeof(o->serial); ++k, j -= 2) {
char buffer[3] = {0};
memcpy(buffer, serial + j, 2);
o->serial[length - k] = (uint8_t)strtol(buffer, NULL, 16);
@ -65,7 +65,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
}
else if (strcmp(av[0], "--area") == 0 || starts_with(av[0], "--area=")) {
const char * area;
if(strcmp(av[0], "--area") == 0) {
if (strcmp(av[0], "--area") == 0) {
ac--;
av++;
if (ac < 1) return -1;
@ -88,7 +88,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
}
else if (strcmp(av[0], "--format") == 0 || starts_with(av[0], "--format=")) {
const char * format;
if(strcmp(av[0], "--format") == 0) {
if (strcmp(av[0], "--format") == 0) {
ac--;
av++;
if (ac < 1) return -1;
@ -136,7 +136,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
}
// command and (optional) device name
while(ac >= 1) {
while (ac >= 1) {
if (strcmp(av[0], "erase") == 0) {
if (o->cmd != FLASH_CMD_NONE) return -1;
o->cmd = FLASH_CMD_ERASE;
@ -167,32 +167,32 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
return -1;
case FLASH_CMD_ERASE: // no more arguments expected
if(ac != 0) return -1;
if (ac != 0) return -1;
break;
case FLASH_CMD_READ: // expect filename, addr and size
if((o->area == FLASH_OPTION_BYTES) &&(ac == 0)) break;
if ((o->area == FLASH_OPTION_BYTES) &&(ac == 0)) break;
if (ac != 3) return invalid_args("read <path> <addr> <size>");
if (ac != 3) return -1;
o->filename = av[0];
o->addr = (uint32_t) strtoul(av[1], &tail, 16);
if(tail[0] != '\0') return bad_arg("addr");
if (tail[0] != '\0') return bad_arg("addr");
o->size = strtoul(av[2], &tail, 16);
if(tail[0] != '\0') return bad_arg("size");
if (tail[0] != '\0') return bad_arg("size");
break;
case FLASH_CMD_WRITE:
if(o->area == FLASH_OPTION_BYTES){
if(ac != 1) return -1;
if (o->area == FLASH_OPTION_BYTES){
if (ac != 1) return -1;
o->val = (uint32_t)strtoul(av[0], &tail, 16);
}
else if(o->format == FLASH_FORMAT_BINARY) { // expect filename and addr
else if (o->format == FLASH_FORMAT_BINARY) { // expect filename and addr
if (ac != 2) return invalid_args("write <path> <addr>");
o->filename = av[0];
o->addr = (uint32_t) strtoul(av[1], &tail, 16);
if(tail[0] != '\0') return bad_arg("addr");
if (tail[0] != '\0') return bad_arg("addr");
}
else if(o->format == FLASH_FORMAT_IHEX) { // expect filename
else if (o->format == FLASH_FORMAT_IHEX) { // expect filename
if (ac != 1) return invalid_args("write <path>");
o->filename = av[0];
}

Wyświetl plik

@ -142,7 +142,7 @@ mem_view_add_as_hex (GtkListStore *store,
gchar *hex_str;
hex_str = g_strdup_printf ("0x%08X", value);
gtk_list_store_set (store, iter, column, hex_str, -1);
gtk_list_store_set(store, iter, column, hex_str, -1);
g_free (hex_str);
}
@ -439,7 +439,7 @@ static void mem_jmp (GtkTreeView *view,
}
}
}
g_value_unset (&value);
g_value_unset(&value);
} while (gtk_tree_model_iter_next (model, &iter));
}
}
@ -751,10 +751,10 @@ int export_to_file(const char*filename, const struct mem_t flash_mem)
{
printf("%s\n", filename);
FILE * f=fopen(filename, "w");
if(f==NULL)
if (f==NULL)
return -1;
for(gsize i=0;i<flash_mem.size;i++)
if(fputc(flash_mem.memory[i], f)==EOF)
for (gsize i=0;i<flash_mem.size;i++)
if (fputc(flash_mem.memory[i], f)==EOF)
return -1;
fclose(f);
return 0;
@ -782,7 +782,7 @@ export_button_cb (GtkWidget *widget, gpointer data)
char *filename;
filename = gtk_file_chooser_get_filename (chooser);
if(export_to_file (filename, gui->flash_mem)!=0)
if (export_to_file (filename, gui->flash_mem)!=0)
stlink_gui_set_info_error_message(gui, "Failed to export flash");
else
stlink_gui_set_info_error_message(gui, "Export successful");
@ -886,7 +886,7 @@ stlink_gui_init_dnd (STlinkGUI *gui)
{ "text/uri-list", 0, TARGET_FILENAME },
};
gtk_drag_dest_set (GTK_WIDGET (gui->window),
gtk_drag_dest_set(GTK_WIDGET (gui->window),
GTK_DEST_DEFAULT_ALL,
target_list,
G_N_ELEMENTS (target_list),

Wyświetl plik

@ -144,7 +144,7 @@ static int fill_command
unsigned char* const cmd = sl->c_buf;
int i = 0;
memset(cmd, 0, sizeof (sl->c_buf));
if(slu->protocoll == 1) {
if (slu->protocoll == 1) {
cmd[i++] = 'U';
cmd[i++] = 'S';
cmd[i++] = 'B';
@ -651,7 +651,7 @@ int _stlink_usb_read_all_regs(stlink_t *sl, struct stlink_reg *regp) {
}
sl->q_len = (int) size;
stlink_print_data(sl);
for(i=0; i<16; i++)
for (i=0; i<16; i++)
regp->r[i]= read_uint32(sl->q_buf, i*4);
regp->xpsr = read_uint32(sl->q_buf, 64);
regp->main_sp = read_uint32(sl->q_buf, 68);
@ -1049,7 +1049,7 @@ stlink_t *stlink_open_usb(enum ugly_loglevel verbose, bool reset, char serial[ST
}
if (reset) {
if( sl->version.stlink_v > 1 ) stlink_jtag_reset(sl, 2);
if ( sl->version.stlink_v > 1)stlink_jtag_reset(sl, 2);
stlink_reset(sl);
usleep(10000);
}

Wyświetl plik

@ -15,12 +15,12 @@ struct Test {
};
static bool cmp_strings(const char * s1, const char * s2) {
if(s1 == NULL || s2 == NULL) return (s1 == s2);
if (s1 == NULL || s2 == NULL) return (s1 == s2);
else return (0 == strcmp(s1, s2));
}
static bool cmp_mem(const uint8_t * s1, const uint8_t * s2, size_t size) {
if(s1 == NULL || s2 == NULL) return (s1 == s2);
if (s1 == NULL || s2 == NULL) return (s1 == s2);
else return (0 == memcmp(s1, s2, size));
}
@ -36,8 +36,8 @@ static bool execute_test(const struct Test * test) {
#endif
strcpy(cmd_line, test->cmd_line);
for(char * tok = strtok(cmd_line, " "); tok; tok = strtok(NULL, " ")) {
if((size_t)ac >= sizeof(av)/sizeof(av[0])) return false;
for (char * tok = strtok(cmd_line, " "); tok; tok = strtok(NULL, " ")) {
if ((size_t)ac >= sizeof(av)/sizeof(av[0])) return false;
av[ac] = tok;
++ac;
@ -50,7 +50,7 @@ static bool execute_test(const struct Test * test) {
// compare results
bool ret = (res == test->res);
if(ret && (res == 0)) {
if (ret && (res == 0)) {
ret &= (opts.cmd == test->opts.cmd);
ret &= cmp_strings(opts.devname, test->opts.devname);
ret &= cmp_mem(opts.serial, test->opts.serial, sizeof(opts.serial));
@ -104,8 +104,8 @@ static struct Test tests[] = {
int main()
{
bool allOk = true;
for(size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) {
if(!execute_test(&tests[i])) allOk = false;
for (size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) {
if (!execute_test(&tests[i])) allOk = false;
}
return (allOk ? 0 : 1);