nuttx/drivers/segger/Make.defs
Marco Casaroli f3721d83d0 drivers/segger: Let the SEGGER sources take part in dependency checking.
Every other driver subdirectory adds bare file names to CSRCS and points
VPATH and DEPPATH at itself, so drivers/lcd/st7365p.c is built as
drivers/st7365p.o.  segger/Make.defs instead put the path in CSRCS, so its
objects were built as drivers/segger/serial_rtt.o and friends.

The generated rules in drivers/Make.dep name their target with the basename
of the source -- mkdeps calls basename() and prefixes --obj-path -- so they
read "serial_rtt.o: segger/serial_rtt.c ... nuttx/config.h".  No such file
was ever built.  The dependency rule and the compile rule named different
targets, and nothing under drivers/segger was ever recompiled when a header
or the configuration changed.

The result is a stale object silently linked against fresh ones.  Enabling
CONFIG_TTY_SIGINT, for instance, adds a pid_t to struct uart_dev_s, which
moves every field after it.  serial.c is rebuilt and reads dev->ops from its
new offset; serial_rtt.o is not, and its statically initialised device still
has ops four bytes lower.  uart_open() then branches through whatever
follows it, and the board hard faults in uart_attach() before the console
has emitted a byte -- a symptom with no visible connection to its cause.

Use the same convention as the other subdirectories.

Tested on a Pimoroni Pico Plus 2 W with the RTT console
(pimoroni-pico-plus-2-w:nsh with CONFIG_SERIAL_RTT_CONSOLE).  On master,
touching nuttx/serial/serial.h or enabling CONFIG_TTY_SIGINT does not
recompile segger/serial_rtt.c, and the incrementally built image prints
nothing on RTT.  With this change, serial_rtt.c is recompiled in both
cases, and the same incremental build boots to NSH over RTT.

drivers/mtd/Make.defs has the same shape for its downloaded dhara and nvblk
sources and is left alone: it adds both nvblk.c and mtd/nvblk/src/nvblk.c,
whose basenames collide, so it needs more than a change of convention.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-10-08 15:54:35 -03:00

101 lines
2.8 KiB
Text

############################################################################
# drivers/segger/Make.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
TARGET_ZIP =
SGDIR = segger
ifeq ($(CONFIG_SEGGER_RTT),y)
CSRCS += segger.c
CSRCS += SEGGER_RTT.c
CFLAGS += -Wno-shadow -Wno-pointer-to-int-cast
ifneq ($(CONFIG_SEGGER_RTT_SECTION),"")
CFLAGS += ${DEFINE_PREFIX}SEGGER_RTT_SECTION=CONFIG_SEGGER_RTT_SECTION
endif
ifneq ($(CONFIG_SEGGER_RTT_BUFFER_SECTION),"")
CFLAGS += ${DEFINE_PREFIX}SEGGER_RTT_BUFFER_SECTION=CONFIG_SEGGER_RTT_BUFFER_SECTION
endif
CFLAGS += ${INCDIR_PREFIX}segger$(DELIM)config
ifeq ($(CONFIG_ARCH_ARMV7M),y)
AFLAGS += ${INCDIR_PREFIX}segger$(DELIM)config
ASRCS += SEGGER_RTT_ASM_ARMv7M.S
endif
endif
ifeq ($(CONFIG_STREAM_RTT),y)
CSRCS += stream_rtt.c
endif
ifeq ($(CONFIG_SYSLOG_RTT),y)
CSRCS += syslog_rtt.c
endif
ifeq ($(CONFIG_NOTE_RTT),y)
CSRCS += note_rtt.c
endif
ifeq ($(CONFIG_SERIAL_RTT),y)
CSRCS += serial_rtt.c
endif
ifeq ($(CONFIG_SEGGER_SYSVIEW),y)
CSRCS += note_sysview.c
CSRCS += SEGGER_SYSVIEW.c
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)sched
endif
DEPPATH += --dep-path segger
VPATH += :segger
# Common settings for RTT and SYSTEMVIEW
ifneq ($(CONFIG_SEGGER_RTT)$(CONFIG_SEGGER_SYSVIEW),)
CFLAGS += ${INCDIR_PREFIX}segger$(DELIM)SystemView$(DELIM)SEGGER
DEPPATH += --dep-path segger/SystemView/SEGGER
VPATH += :segger/SystemView/SEGGER
SYSVIEW_VERSION ?= $(CONFIG_SEGGER_SYSVIEW_TARGET_SOURCE)
SYSVIEW_ZIP = SystemView_Src_V$(SYSVIEW_VERSION).zip
# Download and unpack tarball if no git repo found
ifeq ($(wildcard $(SGDIR)/SystemView/.git),)
TARGET_ZIP = $(SGDIR)/$(SYSVIEW_ZIP)
$(SGDIR)/$(SYSVIEW_ZIP):
$(call DOWNLOAD,https://github.com/NuttX/nuttx/releases/download/systemview,$(SYSVIEW_ZIP),$(TARGET_ZIP))
$(Q) unzip -o $(TARGET_ZIP) -d $(SGDIR)/SystemView
endif
endif
context:: $(TARGET_ZIP)
distclean::
ifeq ($(wildcard $(SGDIR)/SystemView/.git),)
$(call DELDIR, $(SGDIR)/SystemView)
endif
$(call DELFILE, $(TARGET_ZIP))