Skip to content

Commit

Permalink
Reorganised project source directories
Browse files Browse the repository at this point in the history
(Closes #976)
  • Loading branch information
Nightwalker-87 committed Jun 4, 2020
1 parent 8f42f54 commit c7041cc
Show file tree
Hide file tree
Showing 32 changed files with 193 additions and 222 deletions.
62 changes: 29 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/stlink-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/stlink-lib/chipid.h
src/stlink-lib/flash_loader.h
src/stlink-lib/logging.h
src/stlink-lib/md5.h
src/stlink-lib/sg.h
src/stlink-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/stlink-lib/chipid.c
src/stlink-lib/flash_loader.c
src/stlink-lib/logging.c
src/stlink-lib/md5.c
src/stlink-lib/sg.c
src/stlink-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)
Expand All @@ -140,7 +138,7 @@ endif ()
set(STLINK_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Main library install directory")

# Set the environment variable LD_LIBRARY_PATH to point to /usr/local/lib (per default).
execute_process (COMMAND bash -c "export LD_LIBRARY_PATH="${CMAKE_INSTALL_LIBDIR}" ")
execute_process (COMMAND bash -c "export LD_LIBRARY_PATH=${CMAKE_INSTALL_LIBDIR}")


###
Expand Down Expand Up @@ -221,15 +219,17 @@ 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)
# Add getopt to sources
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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions doc/dev/developer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ In order to use pkg-config for development purposes, add the following lines to

## Package configuration (pkg-config) on unix-based systems
if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
add_subdirectory(doc/dev/pkg-config) # Option A: external tool pkg-config
find_package(PkgConfig) # Option B: internal cmake module for pkg-config integration
pkg_check_modules(GTK3 gtk+-3.0)
add_subdirectory(doc/dev/pkg-config) # external tool pkg-config
endif ()

ToDo: Check for compatibility issues between options A and B.
Expand Down
9 changes: 9 additions & 0 deletions inc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions include/CMakeLists.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <sys/stat.h>

#include <stlink.h>
#include "mmap.h"
#include "logging.h"
#include "md5.h"
#include <mmap.h>
#include <logging.h>
#include <md5.h>

#ifndef O_BINARY
#define O_BINARY 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/tools/flash.c → src/st-flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <sys/types.h>

#include <stlink.h>
#include <flash.h>
#include "flash.h"

static stlink_t *connected_stlink = NULL;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/tools/flash_opts.c → src/st-flash/flash_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdio.h>
#include <string.h>

#include <flash.h>
#include "flash.h"

static bool starts_with(const char * str, const char * prefix) {
size_t n = strlen(prefix);
Expand Down
File renamed without changes.
59 changes: 16 additions & 43 deletions src/st-util/semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,87 +9,66 @@
#include <logging.h>
#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) {
read_len += 4 - (read_len % 4);
}

/* 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.
//
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 4 additions & 3 deletions src/stlink-gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# Build GUI
###

if (NOT WIN32)
if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
find_package(PkgConfig)
pkg_check_modules(GTK3 gtk+-3.0)

## GUI-Building requires the presence of a GTK3 toolset
if (NOT GTK3_FOUND)
message(STATUS "GTK3 not found!")
Expand Down Expand Up @@ -35,7 +38,5 @@ if (NOT WIN32)
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_PREFIX}/bin")
target_link_libraries(stlink-gui ${STLINK_LIB_SHARED} ${SSP_LIB} ${GTK3_LDFLAGS})
install(TARGETS stlink-gui DESTINATION ${CMAKE_INSTALL_BINDIR})


endif ()
endif ()
2 changes: 1 addition & 1 deletion src/chipid.c → src/stlink-lib/chipid.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <stlink.h>
#include <chipid.h>
#include "chipid.h"

static const struct stlink_chipid_params devices[] = {
{
Expand Down
File renamed without changes.
Loading

0 comments on commit c7041cc

Please sign in to comment.