Skip to content

Commit

Permalink
nomagic probe compiles without target.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Pötter committed May 3, 2024
1 parent 40a9762 commit 3f12d13
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 211 deletions.
4 changes: 0 additions & 4 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="target/src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="tests"/>
</sourceEntries>
</configuration>
Expand Down Expand Up @@ -513,7 +512,6 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="target/src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="tests"/>
</sourceEntries>
</configuration>
Expand Down Expand Up @@ -773,7 +771,6 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="target/src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="tests"/>
</sourceEntries>
</configuration>
Expand Down Expand Up @@ -1033,7 +1030,6 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="target/src"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="tests"/>
</sourceEntries>
</configuration>
Expand Down
233 changes: 26 additions & 207 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ DIS = $(CP) -S
OBJDUMP = arm-none-eabi-objdump
TST_CC = gcc
TST_LD = cc
GITREF = $(shell git describe --abbrev=40 --dirty --always --tags)

# configuration
# =============
Expand All @@ -44,206 +43,26 @@ GITREF = $(shell git describe --abbrev=40 --dirty --always --tags)

BIN_FOLDER = bin/
SRC_FOLDER = src/
NOMAGIC_FOLDER =

# default target is the RaspberryPi RP2040
ifndef TARGET
TARGET = RP2040
endif


# remove ? SOURCE_DIR = $(dir $(lastword $(MAKEFILE_LIST)))

ifeq ($(TARGET), DETECT)
HAS_MSC = yes
HAS_DEBUG_UART = no
HAS_DEBUG_CDC = yes
HAS_CLI = yes
HAS_GDB_SERVER = no
HAS_DETECT = yes
else
HAS_MSC = yes
HAS_DEBUG_UART = yes
HAS_DEBUG_CDC = no
HAS_CLI = yes
HAS_GDB_SERVER = yes
HAS_DETECT = no
endif


# ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
# ! ! ! ! ALL CONFIGURATION SETTINGS ARE ABOVE THIS LINE ! ! ! !
# ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !


# COMPILER SWITCHES
# =================
# These switches enable or disable functionality
# tinyUSB logging has different levels 0 = no logging,1 = some logging, 2 = more logging, 3= all logging
DDEFS += -DCFG_TUSB_DEBUG=1
# with this (=1)the watchdog is only active if the debugger is not connected
DDEFS += -DDISABLE_WATCHDOG_FOR_DEBUG=0
# use both cores
#DDEFS += -DENABLE_CORE_1=1
# use BOOT ROM (for flash functions,...)
DDEFS += -DBOOT_ROM_ENABLED=1

DDEFS += -DTARGET=$(TARGET)

# enable USB Mass Storage (Thumb Drive)
ifeq ($(HAS_MSC), yes)
DDEFS += -DFEAT_USB_MSC
endif
# enable the command line interface for testing
ifeq ($(HAS_DEBUG_UART), yes)
DDEFS += -DFEAT_DEBUG_UART
endif

ifeq ($(HAS_DEBUG_CDC), yes)
DDEFS += -DFEAT_DEBUG_CDC
endif
# enable the gdb-server
ifeq ($(HAS_GDB_SERVER), yes)
DDEFS += -DFEAT_GDB_SERVER
endif


CFLAGS = -c -ggdb3 -MMD -MP
CFLAGS += -O3
# sometimes helps with debugging:
# CFLAGS += -O0
# CFLAGS += -save-temps=obj

CFLAGS += -std=c17
CFLAGS += -mcpu=cortex-m0plus -mthumb
CFLAGS += -ffreestanding -funsigned-char
# -fno-short-enums
CFLAGS += -Wall -Wextra -pedantic -Wshadow -Wdouble-promotion -Wconversion
# -Wpadded : tinyUSB creates warnings with this enabled. :-(
CFLAGS += -ffunction-sections -fdata-sections

LKR_SCRIPT = $(SRC_FOLDER)hal/RP2040.ld



LFLAGS = -ffreestanding -nostartfiles
# disabled the following due to this issue:
# undefined reference to `__gnu_thumb1_case_si'
# LFLAGS += -nostdlib -nolibc -nodefaultlibs
# LFLAGS += -specs=nosys.specs
# LFLAGS += -fno-builtin -fno-builtin-function
# https://wiki.osdev.org/Libgcc : All code compiled with GCC must be linked with libgcc.
LFLAGS += -lgcc
LFLAGS += -Wl,--gc-sections,-Map=$(BIN_FOLDER)$(PROJECT).map -g
LFLAGS += -fno-common -T$(LKR_SCRIPT)


# Files to compile
# ================

# file handling
ifeq ($(HAS_MSC), yes)
SRC += $(SRC_FOLDER)file/fake_mbr.c
SRC += $(SRC_FOLDER)file/fake_boot_sector.c
SRC += $(SRC_FOLDER)file/fake_fat.c
SRC += $(SRC_FOLDER)file/fake_root_folder.c
SRC += $(SRC_FOLDER)file/fake_text_files.c
SRC += $(SRC_FOLDER)file/fake_favicon.c
SRC += $(SRC_FOLDER)file/fake_fs.c
SRC += $(SRC_FOLDER)file/file_storage.c
SRC += $(SRC_FOLDER)file/file_system.c
endif

# gdb server
ifeq ($(HAS_GDB_SERVER), yes)
SRC += $(SRC_FOLDER)gdbserver/cmd_qsupported.c
SRC += $(SRC_FOLDER)gdbserver/cmd_qxfer.c
SRC += $(SRC_FOLDER)gdbserver/commands.c
SRC += $(SRC_FOLDER)gdbserver/gdbserver.c
SRC += $(SRC_FOLDER)gdbserver/util.c
endif

# Hardware abstraction layer
ifeq ($(HAS_DEBUG_UART), yes)
SRC += $(SRC_FOLDER)hal/debug_uart.c
endif
SRC += $(SRC_FOLDER)hal/startup.c
SRC += $(SRC_FOLDER)hal/hw_divider.c
SRC += $(SRC_FOLDER)hal/watchdog.c
SRC += $(SRC_FOLDER)hal/boot_rom.c
SRC += $(SRC_FOLDER)hal/flash.c
SRC += $(SRC_FOLDER)hal/qspi.c
SRC += $(SRC_FOLDER)hal/time_base.c

# command line interface (debug - UART0 / USB-CDC)
ifeq ($(HAS_CLI), yes)
SRC += $(SRC_FOLDER)cli/cli.c
SRC += $(SRC_FOLDER)cli/cli_memory.c
SRC += $(SRC_FOLDER)cli/cli_swd.c
SRC += $(SRC_FOLDER)cli/cli_sys.c
SRC += $(SRC_FOLDER)cli/cli_usb.c
endif

# functions usually available from standard libraries
SRC += $(SRC_FOLDER)lib/ctype.c
SRC += $(SRC_FOLDER)lib/atoi.c
SRC += $(SRC_FOLDER)lib/memcpy.c
SRC += $(SRC_FOLDER)lib/memmove.c
SRC += $(SRC_FOLDER)lib/memset.c
SRC += $(SRC_FOLDER)lib/printf.c
SRC += $(SRC_FOLDER)lib/strchr.c
SRC += $(SRC_FOLDER)lib/strlen.c
SRC += $(SRC_FOLDER)lib/strncmp.c

# SWD
SRC += $(SRC_FOLDER)swd/swd_engine.c
SRC += $(SRC_FOLDER)swd/swd_protocol.c
SRC += $(SRC_FOLDER)swd/swd_packets.c
SRC += $(SRC_FOLDER)swd/swd_packet_bits.c
SRC += $(SRC_FOLDER)swd/swd_gpio.c

# USB driver
SRC += $(SRC_FOLDER)tinyusb/usb.c
SRC += $(SRC_FOLDER)tinyusb/usb_descriptors.c

# USB stack (tinyusb
SRC += $(SRC_FOLDER)tinyusb/src/tusb.c
SRC += $(SRC_FOLDER)tinyusb/src/device/usbd.c
SRC += $(SRC_FOLDER)tinyusb/src/device/usbd_control.c
SRC += $(SRC_FOLDER)tinyusb/src/common/tusb_fifo.c

# USB serial interface (CDC)
SRC += $(SRC_FOLDER)tinyusb/usb_cdc.c
SRC += $(SRC_FOLDER)tinyusb/src/class/cdc/cdc_device.c

# USB thumb drive (MSC)
ifeq ($(HAS_MSC), yes)
SRC += $(SRC_FOLDER)tinyusb/usb_msc.c
SRC += $(SRC_FOLDER)tinyusb/src/class/msc/msc_device.c
endif

# user feedback
SRC += $(SRC_FOLDER)led.c

# main
SRC += $(SRC_FOLDER)main.c

# files specific to the chip that will be debugged:
ifeq ($(TARGET), EXTERN)
# target loader
SRC += $(SRC_FOLDER)file/target_loader.c
else
include target/target.mk
endif
HAS_MSC = yes
HAS_DEBUG_UART = yes
HAS_DEBUG_CDC = no
HAS_CLI = yes
HAS_GDB_SERVER = yes
HAS_DETECT = no


include nomagic_probe.mk

# files specific to the chip that will be debugged:
SRC += no_target/no.c

INCDIRS +=src/probe_api/
INCDIRS +=no_target/

OBJS = $(addprefix $(BIN_FOLDER),$(SRC:.c=.o))

INCDIRS +=$(SRC_FOLDER)
INCDIRS +=$(SRC_FOLDER)cfg/
INCDIRS +=$(SRC_FOLDER)lib/
INCDIRS +=$(SRC_FOLDER)tinyusb/src/
INCDIR = $(patsubst %,-I%, $(INCDIRS))

# unit test configuration
# =======================
Expand Down Expand Up @@ -331,13 +150,13 @@ $(BIN_FOLDER)$(PROJECT).elf: $(OBJS) $(LIBS)
@echo "==========="
$(DIS) $< $@ > $@

$(BIN_FOLDER)version.h:
@echo ""
@echo "create version.h"
@echo "================"
@echo -n "#define VERSION \"" > $(BIN_FOLDER)version.h
@cat version.txt >> $(BIN_FOLDER)version.h
@echo " $(GITREF)\"" >> $(BIN_FOLDER)version.h
#$(BIN_FOLDER)version.h:
# @echo ""
# @echo "create version.h"
# @echo "================"
# @echo -n "#define VERSION \"" > $(BIN_FOLDER)version.h
# @cat version.txt >> $(BIN_FOLDER)version.h
# @echo " $(GITREF)\"" >> $(BIN_FOLDER)version.h

flash: $(BIN_FOLDER)$(PROJECT).elf
@echo ""
Expand All @@ -357,11 +176,11 @@ all: $(BIN_FOLDER)$(PROJECT).uf2
@echo "===="
$(SIZE) --format=GNU $(BIN_FOLDER)$(PROJECT).elf

$(BIN_FOLDER)$(SRC_FOLDER)cli/cli.o: $(SRC_FOLDER)cli/cli.c $(BIN_FOLDER)version.h
@echo ""
@echo "=== compiling $@"
@$(MKDIR_P) $(@D)
$(CC) $(CFLAGS) $(DDEFS) $(INCDIR) $< -o $@
#$(BIN_FOLDER)$(SRC_FOLDER)cli/cli.o: $(SRC_FOLDER)cli/cli.c $(BIN_FOLDER)version.h
# @echo ""
# @echo "=== compiling $@"
# @$(MKDIR_P) $(@D)
# $(CC) $(CFLAGS) $(DDEFS) $(INCDIR) $< -o $@

$(BIN_FOLDER)%o: %c
@echo ""
Expand Down
24 changes: 24 additions & 0 deletions no_target/cfg/target_cli_commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>
*
*/

#ifndef SOURCE_CFG_TARGET_CLI_COMMANDS_H_
#define SOURCE_CFG_TARGET_CLI_COMMANDS_H_

#include "target_actions.h"

#define TARGET_CLI_COMMANDS


#endif /* SOURCE_CFG_TARGET_CLI_COMMANDS_H_ */
23 changes: 23 additions & 0 deletions no_target/cfg/target_walk_walks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>
*
*/

#ifndef SOURCE_CFG_TARGET_WALK_WALKS_H_
#define SOURCE_CFG_TARGET_WALK_WALKS_H_

// no special Walks for this target, yet!
#define TARGET_ENUM_WALKS
#define TARGET_LOOKUP_HANDLERS

#endif /* SOURCE_CFG_TARGET_WALK_WALKS_H_ */
Loading

0 comments on commit 3f12d13

Please sign in to comment.