Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples stuff: fix examples/rules, extend rules and add f7 examples #193

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
PREFIX ?= arm-none-eabi
#PREFIX ?= arm-elf

TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4 stm32/l0 stm32/l1
TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
TARGETS := stm32/f0 stm32/f1 stm32/f2 stm32/f3 stm32/f4
TARGETS += stm32/l0 stm32/l1 stm32/l4
TARGETS += lpc/lpc13xx lpc/lpc17xx lpc/lpc43xx
TARGETS += tiva/lm3s tiva/lm4f
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
TARGETS += vf6xx
Expand Down
2 changes: 1 addition & 1 deletion examples/lpc/lpc43xx/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


LIBNAME = opencm3_lpc43xx
DEFS += -DLPC43XX
DEFS += -DLPC43XX -DLPC43XX_M4

FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16
ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ MEMORY
{
/* rom is really the shadow region that points to SPI flash or elsewhere */
rom (rx) : ORIGIN = 0x00000000, LENGTH = 1M
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
ram_local1 (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
/* there are some additional RAM regions */
ram_local2 (rw) : ORIGIN = 0x10080000, LENGTH = 72K
}

/* Include the common ld script. */
INCLUDE libopencm3_lpc43xx.ld
INCLUDE lpc43xx/m4/libopencm3_lpc43xx.ld
2 changes: 1 addition & 1 deletion examples/lpc/lpc43xx/hackrf-jellybean/i2c/i2cdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(void)
int i;

gpio_setup();
i2c0_init();
i2c0_init(15);

gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */

Expand Down
5 changes: 3 additions & 2 deletions examples/lpc/lpc43xx/hackrf-jellybean/jellybean-lpc4330.ld
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ MEMORY
{
/* rom is really the shadow region that points to SPI flash or elsewhere */
rom (rx) : ORIGIN = 0x00000000, LENGTH = 1M
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
ram_local1 (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
/* there are some additional RAM regions */
ram_local2 (rw) : ORIGIN = 0x10080000, LENGTH = 72K
}

/* Include the common ld script. */
INCLUDE libopencm3_lpc43xx.ld
INCLUDE lpc43xx/m4/libopencm3_lpc43xx.ld
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ MEMORY
rom_flash (rx) : ORIGIN = 0x80000000, LENGTH = 1M
/* rom is really the shadow region that points to SPI flash or elsewhere */
rom (rx) : ORIGIN = 0x00000000, LENGTH = 1M
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
ram_local1 (rwx) : ORIGIN = 0x10000000, LENGTH = 128K
/* there are some additional RAM regions for data */
ram_data (rw) : ORIGIN = 0x10080000, LENGTH = 72K
ram_local2 (rw) : ORIGIN = 0x10080000, LENGTH = 72K
}

/* Include the common ld script. */
INCLUDE libopencm3_lpc43xx_rom_to_ram.ld
INCLUDE lpc43xx/m4/libopencm3_lpc43xx_rom_to_ram.ld
2 changes: 1 addition & 1 deletion examples/lpc/lpc43xx/hackrf-jellybean/ssp/sspdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(void)

while (1) {

ssp_write(SSP1_NUM, (uint16_t)ssp_val);
ssp_transfer(SSP1_NUM, (uint16_t)ssp_val);

gpio_set(GPIO2, GPIOPIN1); /* LED on */

Expand Down
6 changes: 3 additions & 3 deletions examples/lpc/lpc43xx/hackrf-jellybean/systick/systickdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ static void systick_setup(void)
g_ulSysTickCount = 0;

/* Disable IRQ globally */
asm volatile ("cpsid i");
__asm__ __volatile__ ("cpsid i");

/* Set processor Clock as Source Clock */
systick_set_clocksource(STK_CTRL_CLKSOURCE);
systick_set_clocksource(STK_CSR_CLKSOURCE);

/* Get SysTick calibration value to obtain by default 1 tick = 10ms */
systick_reload_val = systick_get_calib();
Expand All @@ -97,7 +97,7 @@ static void systick_setup(void)
nvic_set_priority(NVIC_SYSTICK_IRQ, 0xFF);

/* Enable IRQ globally */
asm volatile ("cpsie i");
__asm__ __volatile__ ("cpsie i");
}

static void scs_dwt_cycle_counter_enabled(void)
Expand Down
30 changes: 23 additions & 7 deletions examples/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ifeq ($(strip $(DEVICE)),)
DEFS += -I$(OPENCM3_DIR)/include
LDFLAGS += -L$(OPENCM3_DIR)/lib
LDLIBS += -l$(LIBNAME)
LIBDEPS += $(OPENCM3_DIR)/lib/lib$(LIBNAME).a
LDSCRIPT ?= $(BINARY).ld
else
# New style, assume device is provided, and we're generating the rest.
Expand Down Expand Up @@ -167,11 +168,26 @@ else
include $(OPENCM3_DIR)/mk/genlink-rules.mk
endif

# Find libopencm3 library folder
# this tries to match LIBNAME to manufacturer or manufacturer/series folder in lib/
# eg. LIBNAME=lm3s LIBFOLDER=lib/lm3s or LIBNAME=stm32f7 LIBFOLDER=lib/stm32/f7
DIR=$(notdir $(subst /.,,$(wildcard $1/*/.)))
LIBFOLDER=lib/$(strip \
$(foreach M,$(filter-out usb ethernet dispatch,$(call DIR,$(OPENCM3_DIR)/lib)), \
$(if $(subst opencm3_$M,,$(LIBNAME)),\
$(foreach S,$(call DIR,$(OPENCM3_DIR)/lib/$(M)), \
$(if $(subst opencm3_$M$S,,$(LIBNAME)),,$M/$S)), \
$M)))
# exceptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely not interested in this one. I've had enough rpoblems with people trying to pick and choose things, and reportings bugs when all they really needed to do was just run "make" once in the top and everythign would have been fine. This relies far too much on knowledge of the build system and file structure within the library, which should be treated as a simple .a dependency. It's a submodule for exactly that reason, just build it once, move on.

ifeq ($(LIBFOLDER),lib/lpc43xx)
LIBFOLDER=lib/lpc43xx/m4
endif

# Build libopencm3-lib if it does exists
$(OPENCM3_DIR)/lib/lib$(LIBNAME).a:
ifeq (,$(wildcard $@))
$(warning $(LIBNAME).a not found, attempting to rebuild in $(OPENCM3_DIR))
$(MAKE) -C $(OPENCM3_DIR)
endif
$(MAKE) -C $(OPENCM3_DIR) $(LIBFOLDER)
$(OPENCM3_DIR)/include/%.h: $(OPENCM3_DIR)/lib/lib$(LIBNAME).a;

# Define a helper macro for debugging make errors online
# you can type "make print-OPENCM3_DIR" and it will show you
Expand Down Expand Up @@ -199,19 +215,19 @@ print-%:
@#printf " OBJDUMP $(*).list\n"
$(Q)$(OBJDUMP) -S $(*).elf > $(*).list

%.elf %.map: $(OBJS) $(LDSCRIPT) $(OPENCM3_DIR)/lib/lib$(LIBNAME).a
%.elf %.map: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
@#printf " LD $(*).elf\n"
$(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(*).elf

%.o: %.c
%.o: %.c $(LIBDEPS)
@#printf " CC $(*).c\n"
$(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).c

%.o: %.cxx
%.o: %.cxx $(LIBDEPS)
@#printf " CXX $(*).cxx\n"
$(Q)$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cxx

%.o: %.cpp
%.o: %.cpp $(LIBDEPS)
@#printf " CXX $(*).cpp\n"
$(Q)$(CXX) $(TGT_CXXFLAGS) $(CXXFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $(*).o -c $(*).cpp

Expand Down
44 changes: 44 additions & 0 deletions examples/stm32/l4/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
##
## This file is part of the libopencm3 project.
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library 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 Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##

# You should use linker script generation! Specify device!
ifeq ($(DEVICE),)
LIBNAME = opencm3_stm32l4
DEFS += -DSTM32L4

FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv5-sp-d16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where di you get that it's v5?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right though, I have this as an unchecked in file locally, never committed when the "basics" example was added.

ARCH_FLAGS = -mthumb -mcpu=cortex-m4 $(FP_FLAGS)
endif

################################################################################
# OpenOCD specific variables

OOCD ?= openocd
OOCD_INTERFACE ?= stlink-v2-1
OOCD_TARGET ?= stm32l4x

################################################################################
# Black Magic Probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?=

################################################################################
# texane/stlink specific variables
#STLINK_PORT ?= :4242


include ../../../../rules.mk