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
Open
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 stm32/f7
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
32 changes: 24 additions & 8 deletions examples/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ifeq ($(strip $(OPENCM3_DIR)),)
LIBPATHS := ./libopencm3 ../../../../libopencm3 ../../../../../libopencm3

OPENCM3_DIR := $(wildcard $(LIBPATHS:=/locm3.sublime-project))
OPENCM3_DIR := $(firstword $(dir $(OPENCM3_DIR)))
OPENCM3_DIR := $(patsubst %/,%,$(firstword $(dir $(OPENCM3_DIR))))

ifeq ($(strip $(OPENCM3_DIR)),)
$(warning Cannot find libopencm3 library in the standard search paths.)
Expand All @@ -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) $(if $(CFLAGS),CFLAGS="$(CFLAGS)")
Copy link
Member

Choose a reason for hiding this comment

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

what sort of usecase is this meant to support?

Copy link
Author

Choose a reason for hiding this comment

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

i guess it makes no sense having this in the examples

$(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/f7/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_stm32f7
DEFS += -DSTM32F7

FP_FLAGS ?= -mfloat-abi=hard -mfpu=fpv5-sp-d16
ARCH_FLAGS = -mthumb -mcpu=cortex-m7 $(FP_FLAGS)
endif

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

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

################################################################################
# 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
9 changes: 9 additions & 0 deletions examples/stm32/f7/stm32f769i-discovery/blinkled/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
OBJS = clock.o

BINARY = application

CFLAGS = -O3

DEVICE = stm32f769nih6

include ../../Makefile.include
6 changes: 6 additions & 0 deletions examples/stm32/f7/stm32f769i-discovery/blinkled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# README

Demo of gpio and exti.

This simple program uses the LEDs LD1-3 to show a grey-counter.
By pressing the blue button, all the LEDs light up. On release, the counter restarts from 0.
119 changes: 119 additions & 0 deletions examples/stm32/f7/stm32f769i-discovery/blinkled/application.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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/>.
*/

#include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/exti.h>
#include "clock.h"


/**
* Function definitions
*/
static void pin_setup(void);
static void update_led_counter(void);

/**
* Setup functions
*/
#define LED_LD1 GPIOJ,GPIO13
#define LED_LD2 GPIOJ,GPIO5
#define LED_LD3 GPIOA,GPIO12
#define BUTTON_BLUE GPIOA,GPIO0
#define BUTTON_BLUE_PRESSED() gpio_get(BUTTON_BLUE)
void pin_setup()
{
/* pin-clocks */
rcc_periph_clock_enable(RCC_GPIOA);
rcc_periph_clock_enable(RCC_GPIOJ);

/* pins */
/* outputs (LEDs 1-3) */
gpio_mode_setup(GPIOJ, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5 | GPIO13);
gpio_set_output_options(GPIOJ, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, GPIO5 | GPIO13);
gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
gpio_set_output_options(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_25MHZ, GPIO12);
/* inputs (blue button) */
gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO0);

/* setup blue/user button */
exti_select_source(EXTI0, GPIOA);
exti_set_trigger(EXTI0, EXTI_TRIGGER_BOTH);
exti_enable_request(EXTI0);
nvic_enable_irq(NVIC_EXTI0_IRQ);
}

/**
* Interrupts
*/

/* Blue button interrupt (EXTI makes not too much sense here :)) */
static bool blue_button_state_changed = false;
void exti0_isr()
{
exti_reset_request(EXTI0);
blue_button_state_changed = true;
update_led_counter();
}

/**
* Functions
*/
void update_led_counter()
{
/* little grey code blinker */
static const uint32_t gcl[] = {0,1,3,2,6,7,5,4};
static const uint32_t *gc = gcl;
static const uint32_t *gcle = gcl+sizeof(gcl)/sizeof(gcl[0])-1;
if (blue_button_state_changed) {
blue_button_state_changed = false;
gc = gcl;
}
if (BUTTON_BLUE_PRESSED()) {
gpio_set(LED_LD1);
gpio_set(LED_LD2);
gpio_set(LED_LD3);
} else {
if (*gc&0b001) gpio_set(LED_LD1);
else gpio_clear(LED_LD1);
if (*gc&0b010) gpio_set(LED_LD2);
else gpio_clear(LED_LD2);
if (*gc&0b100) gpio_set(LED_LD3);
else gpio_clear(LED_LD3);
if (gc==gcle) gc = gcl;
else gc++;
}
}

/**
* Main loop
*/
int main(void)
{
/* init timers. */
clock_setup();
/* setup pins */
pin_setup();

while (1) {
msleep(1000);
update_led_counter();
}
}


Loading