Merge branch 'master' into efm32
Conflicts: Makefile
This commit is contained in:
124
examples/lpc17xx/Makefile.include
Normal file
124
examples/lpc17xx/Makefile.include
Normal file
@@ -0,0 +1,124 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
PREFIX ?= arm-none-eabi
|
||||
#PREFIX ?= arm-elf
|
||||
CC = $(PREFIX)-gcc
|
||||
LD = $(PREFIX)-gcc
|
||||
OBJCOPY = $(PREFIX)-objcopy
|
||||
OBJDUMP = $(PREFIX)-objdump
|
||||
# Uncomment this line if you want to use the installed (not local) library.
|
||||
# TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX)
|
||||
TOOLCHAIN_DIR = ../../../..
|
||||
CFLAGS += -O0 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \
|
||||
-mcpu=cortex-m3 -mthumb -MD
|
||||
LDSCRIPT ?= $(BINARY).ld
|
||||
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib/lpc17xx \
|
||||
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections
|
||||
OBJS += $(BINARY).o
|
||||
|
||||
OOCD ?= openocd
|
||||
OOCD_INTERFACE ?= flossjtag
|
||||
OOCD_BOARD ?= olimex_stm32_h103
|
||||
# FIXME
|
||||
|
||||
# Be silent per default, but 'make V=1' will show all compiler calls.
|
||||
ifneq ($(V),1)
|
||||
Q := @
|
||||
NULL := 2>/dev/null
|
||||
else
|
||||
LDFLAGS += -Wl,--print-gc-sections
|
||||
endif
|
||||
|
||||
.SUFFIXES: .elf .bin .hex .srec .list .images
|
||||
.SECONDEXPANSION:
|
||||
.SECONDARY:
|
||||
|
||||
all: images
|
||||
|
||||
images: $(BINARY).images
|
||||
flash: $(BINARY).flash
|
||||
|
||||
%.images: %.bin %.hex %.srec %.list
|
||||
@#echo "*** $* images generated ***"
|
||||
|
||||
%.bin: %.elf
|
||||
@#printf " OBJCOPY $(*).bin\n"
|
||||
$(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin
|
||||
|
||||
%.hex: %.elf
|
||||
@#printf " OBJCOPY $(*).hex\n"
|
||||
$(Q)$(OBJCOPY) -Oihex $(*).elf $(*).hex
|
||||
|
||||
%.srec: %.elf
|
||||
@#printf " OBJCOPY $(*).srec\n"
|
||||
$(Q)$(OBJCOPY) -Osrec $(*).elf $(*).srec
|
||||
|
||||
%.list: %.elf
|
||||
@#printf " OBJDUMP $(*).list\n"
|
||||
$(Q)$(OBJDUMP) -S $(*).elf > $(*).list
|
||||
|
||||
%.elf: $(OBJS) $(LDSCRIPT) $(TOOLCHAIN_DIR)/lib/lpc17xx/libopencm3_lpc17xx.a
|
||||
@#printf " LD $(subst $(shell pwd)/,,$(@))\n"
|
||||
$(Q)$(LD) $(LDFLAGS) -o $(*).elf $(OBJS) -lopencm3_lpc17xx
|
||||
|
||||
%.o: %.c Makefile
|
||||
@#printf " CC $(subst $(shell pwd)/,,$(@))\n"
|
||||
$(Q)$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
clean:
|
||||
$(Q)rm -f *.o
|
||||
$(Q)rm -f *.d
|
||||
$(Q)rm -f *.elf
|
||||
$(Q)rm -f *.bin
|
||||
$(Q)rm -f *.hex
|
||||
$(Q)rm -f *.srec
|
||||
$(Q)rm -f *.list
|
||||
|
||||
# FIXME: Replace STM32 stuff with proper LPC13XX OpenOCD support later.
|
||||
ifeq ($(OOCD_SERIAL),)
|
||||
%.flash: %.hex
|
||||
@printf " FLASH $<\n"
|
||||
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
|
||||
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
|
||||
-f board/$(OOCD_BOARD).cfg \
|
||||
-c "init" -c "reset init" \
|
||||
-c "stm32x mass_erase 0" \
|
||||
-c "flash write_image $(*).hex" \
|
||||
-c "reset" \
|
||||
-c "shutdown" $(NULL)
|
||||
else
|
||||
%.flash: %.hex
|
||||
@printf " FLASH $<\n"
|
||||
@# IMPORTANT: Don't use "resume", only "reset" will work correctly!
|
||||
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
|
||||
-f board/$(OOCD_BOARD).cfg \
|
||||
-c "ft2232_serial $(OOCD_SERIAL)" \
|
||||
-c "init" -c "reset init" \
|
||||
-c "stm32x mass_erase 0" \
|
||||
-c "flash write_image $(*).hex" \
|
||||
-c "reset" \
|
||||
-c "shutdown" $(NULL)
|
||||
endif
|
||||
|
||||
.PHONY: images clean
|
||||
|
||||
-include $(OBJS:.o=.d)
|
||||
|
||||
32
examples/lpc17xx/blueboard-lpc1768-h/blueboard-lpc1768-h.ld
Normal file
32
examples/lpc17xx/blueboard-lpc1768-h/blueboard-lpc1768-h.ld
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Blueboard-LPC1768-H (LPC1768, 512K flash, 64K SRAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00000000, LENGTH = 512K
|
||||
ram (rwx) : ORIGIN = 0x10000000, LENGTH = 32K
|
||||
ram1 (rwx) : ORIGIN = 0x2007C000, LENGTH = 16K
|
||||
ram2 (rwx) : ORIGIN = 0x20080000, LENGTH = 16K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_lpc17xx.ld
|
||||
24
examples/lpc17xx/blueboard-lpc1768-h/miniblink/Makefile
Normal file
24
examples/lpc17xx/blueboard-lpc1768-h/miniblink/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = miniblink
|
||||
|
||||
LDSCRIPT = ../blueboard-lpc1768-h.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
9
examples/lpc17xx/blueboard-lpc1768-h/miniblink/README
Normal file
9
examples/lpc17xx/blueboard-lpc1768-h/miniblink/README
Normal file
@@ -0,0 +1,9 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is the smallest-possible example program using libopencm3.
|
||||
|
||||
It's intended for the NXP LPC1768-based NGX Blueboard-LPC1768-H eval board (see
|
||||
http://shop.ngxtechnologies.com/product_info.php?cPath=21&products_id=65). It should blink
|
||||
a LED on the board.
|
||||
52
examples/lpc17xx/blueboard-lpc1768-h/miniblink/miniblink.c
Normal file
52
examples/lpc17xx/blueboard-lpc1768-h/miniblink/miniblink.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* 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/lpc17xx/gpio.h>
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
GPIO1_DIR |= (1 << 29); /* Configure P1_29 as output. */
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
gpio_setup();
|
||||
|
||||
/* Blink LED0 (P3_0) on the board. */
|
||||
while (1) {
|
||||
/* Manually: */
|
||||
//GPIO1_SET = (1 << 29); /* LED on */
|
||||
//for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
//GPIO1_CLR = (1 << 29); /* LED off */
|
||||
//for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
|
||||
gpio_set(GPIO1, GPIOPIN29); /* LED on */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_clear(GPIO1, GPIOPIN29); /* LED off */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/stm32/f1/lisa-m-2/usart/Makefile
Normal file
25
examples/stm32/f1/lisa-m-2/usart/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart
|
||||
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
12
examples/stm32/f1/lisa-m-2/usart/README
Normal file
12
examples/stm32/f1/lisa-m-2/usart/README
Normal file
@@ -0,0 +1,12 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program sends some characters on USART2 on Lisa/M 2.0 board
|
||||
(see http://paparazzi.enac.fr/wiki/LisaM for details).
|
||||
|
||||
The terminal settings for the receiving device/PC are 38400 8n1.
|
||||
|
||||
The sending is done in a blocking way in the code, see the usart_irq example
|
||||
for a more elaborate USART example.
|
||||
|
||||
86
examples/stm32/f1/lisa-m-2/usart/usart.c
Normal file
86
examples/stm32/f1/lisa-m-2/usart/usart.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA, GPIOB, GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR,
|
||||
RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |
|
||||
RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port B (for GPIO_USART3_TX) and USART3. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR,
|
||||
RCC_APB1ENR_USART2EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO pin GPIO_USART2_TX. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART2, 38400);
|
||||
usart_set_databits(USART2, 8);
|
||||
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
||||
usart_set_mode(USART2, USART_MODE_TX);
|
||||
usart_set_parity(USART2, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART2);
|
||||
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO8 (in GPIO port A) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j = 0, c = 0;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/* Blink the LED (PA8) on the board with every transmitted byte. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO8); /* LED on/off */
|
||||
usart_send_blocking(USART2, c + '0'); /* USART2: Send byte. */
|
||||
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
||||
if ((j++ % 80) == 0) { /* Newline after line full. */
|
||||
usart_send_blocking(USART2, '\r');
|
||||
usart_send_blocking(USART2, '\n');
|
||||
}
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/stm32/f1/lisa-m-2/usart_dma/Makefile
Normal file
25
examples/stm32/f1/lisa-m-2/usart_dma/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart_dma
|
||||
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
199
examples/stm32/f1/lisa-m-2/usart_dma/usart_dma.c
Normal file
199
examples/stm32/f1/lisa-m-2/usart_dma/usart_dma.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/f1/dma.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA, GPIOB, GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR,
|
||||
RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |
|
||||
RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port B (for GPIO_USART3_TX) and USART3. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR,
|
||||
RCC_APB1ENR_USART2EN);
|
||||
|
||||
/* Enable DMA1 clock */
|
||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_DMA1EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO pin GPIO_USART2_TX and GPIO_USART2_RX. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART2, 38400);
|
||||
usart_set_databits(USART2, 8);
|
||||
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
||||
usart_set_mode(USART2, USART_MODE_TX_RX);
|
||||
usart_set_parity(USART2, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART2);
|
||||
|
||||
nvic_set_priority(NVIC_DMA1_CHANNEL7_IRQ, 0);
|
||||
nvic_enable_irq(NVIC_DMA1_CHANNEL7_IRQ);
|
||||
|
||||
nvic_set_priority(NVIC_DMA1_CHANNEL6_IRQ, 0);
|
||||
nvic_enable_irq(NVIC_DMA1_CHANNEL6_IRQ);
|
||||
|
||||
}
|
||||
|
||||
void dma_write(char *data, int size)
|
||||
{
|
||||
/*
|
||||
* Using channel 7 for USART2_TX
|
||||
*/
|
||||
|
||||
/* Reset DMA channel*/
|
||||
dma_channel_reset(DMA1, DMA_CHANNEL7);
|
||||
|
||||
dma_set_peripheral_address(DMA1, DMA_CHANNEL7, (u32)&USART2_DR);
|
||||
dma_set_memory_address(DMA1, DMA_CHANNEL7, (u32)data);
|
||||
dma_set_number_of_data(DMA1, DMA_CHANNEL7, size);
|
||||
dma_set_read_from_memory(DMA1, DMA_CHANNEL7);
|
||||
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL7);
|
||||
dma_set_peripheral_size(DMA1, DMA_CHANNEL7, DMA_CCR_PSIZE_8BIT);
|
||||
dma_set_memory_size(DMA1, DMA_CHANNEL7, DMA_CCR_MSIZE_8BIT);
|
||||
dma_set_priority(DMA1, DMA_CHANNEL7, DMA_CCR_PL_VERY_HIGH);
|
||||
|
||||
dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL7);
|
||||
|
||||
dma_enable_channel(DMA1, DMA_CHANNEL7);
|
||||
|
||||
usart_enable_tx_dma(USART2);
|
||||
}
|
||||
|
||||
volatile int transfered = 0;
|
||||
|
||||
void dma1_channel7_isr(void)
|
||||
{
|
||||
if ((DMA1_ISR &DMA_ISR_TCIF7) != 0) {
|
||||
DMA1_IFCR |= DMA_IFCR_CTCIF7;
|
||||
|
||||
transfered = 1;
|
||||
}
|
||||
|
||||
dma_disable_transfer_complete_interrupt(DMA1, DMA_CHANNEL7);
|
||||
|
||||
usart_disable_tx_dma(USART2);
|
||||
|
||||
dma_disable_channel(DMA1, DMA_CHANNEL7);
|
||||
}
|
||||
|
||||
void dma_read(char *data, int size)
|
||||
{
|
||||
/*
|
||||
* Using channel 6 for USART2_RX
|
||||
*/
|
||||
|
||||
/* Reset DMA channel*/
|
||||
dma_channel_reset(DMA1, DMA_CHANNEL6);
|
||||
|
||||
dma_set_peripheral_address(DMA1, DMA_CHANNEL6, (u32)&USART2_DR);
|
||||
dma_set_memory_address(DMA1, DMA_CHANNEL6, (u32)data);
|
||||
dma_set_number_of_data(DMA1, DMA_CHANNEL6, size);
|
||||
dma_set_read_from_peripheral(DMA1, DMA_CHANNEL6);
|
||||
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL6);
|
||||
dma_set_peripheral_size(DMA1, DMA_CHANNEL6, DMA_CCR_PSIZE_8BIT);
|
||||
dma_set_memory_size(DMA1, DMA_CHANNEL6, DMA_CCR_MSIZE_8BIT);
|
||||
dma_set_priority(DMA1, DMA_CHANNEL6, DMA_CCR_PL_HIGH);
|
||||
|
||||
dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL6);
|
||||
|
||||
dma_enable_channel(DMA1, DMA_CHANNEL6);
|
||||
|
||||
usart_enable_rx_dma(USART2);
|
||||
}
|
||||
|
||||
volatile int received = 0;
|
||||
|
||||
void dma1_channel6_isr(void)
|
||||
{
|
||||
if ((DMA1_ISR &DMA_ISR_TCIF6) != 0) {
|
||||
DMA1_IFCR |= DMA_IFCR_CTCIF6;
|
||||
|
||||
received = 1;
|
||||
}
|
||||
|
||||
dma_disable_transfer_complete_interrupt(DMA1, DMA_CHANNEL6);
|
||||
|
||||
usart_disable_rx_dma(USART2);
|
||||
|
||||
dma_disable_channel(DMA1, DMA_CHANNEL6);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO8 (in GPIO port A) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char tx[10] = "abcdefg\r\n";
|
||||
int tx_len = 10;
|
||||
char rx[7] = "bcdefg";
|
||||
int rx_len = 6;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
transfered = 0;
|
||||
dma_write(tx, tx_len);
|
||||
received = 0;
|
||||
dma_read(rx, rx_len);
|
||||
|
||||
/* Blink the LED (PA8) on the board with every transmitted byte. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO8); /* LED on/off */
|
||||
while ( transfered != 1) {
|
||||
if (received == 1) {
|
||||
tx[1] = rx[0];
|
||||
tx[2] = rx[1];
|
||||
tx[3] = rx[2];
|
||||
tx[4] = rx[3];
|
||||
tx[5] = rx[4];
|
||||
tx[6] = rx[5];
|
||||
received = 0;
|
||||
dma_read(rx, rx_len);
|
||||
}
|
||||
}
|
||||
tx[0]++;
|
||||
if (tx[0] > 'z') tx[0] = 'a';
|
||||
transfered = 0;
|
||||
dma_write(tx, tx_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/stm32/f1/lisa-m-2/usart_irq/Makefile
Normal file
25
examples/stm32/f1/lisa-m-2/usart_irq/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart_irq
|
||||
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
126
examples/stm32/f1/lisa-m-2/usart_irq/usart_irq.c
Normal file
126
examples/stm32/f1/lisa-m-2/usart_irq/usart_irq.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
|
||||
RCC_APB2ENR_AFIOEN);
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Enable the USART2 interrupt. */
|
||||
nvic_enable_irq(NVIC_USART2_IRQ);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART2_TX on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIO_BANK_USART2_TX, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART2_RX on GPIO port A for receive. */
|
||||
gpio_set_mode(GPIO_BANK_USART2_RX, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART2, 230400);
|
||||
usart_set_databits(USART2, 8);
|
||||
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
||||
usart_set_parity(USART2, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
||||
usart_set_mode(USART2, USART_MODE_TX_RX);
|
||||
|
||||
/* Enable USART2 Receive interrupt. */
|
||||
USART_CR1(USART2) |= USART_CR1_RXNEIE;
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART2);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
gpio_set(GPIOA, GPIO8);
|
||||
|
||||
/* Setup GPIO8 (in GPIO port A) for LED use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
|
||||
gpio_set(GPIOC, GPIO15);
|
||||
|
||||
/* Setup GPIO15 (in GPIO port C) for LED use. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
}
|
||||
|
||||
void usart2_isr(void)
|
||||
{
|
||||
static u8 data = 'A';
|
||||
|
||||
/* Check if we were called because of RXNE. */
|
||||
if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) &&
|
||||
((USART_SR(USART2) & USART_SR_RXNE) != 0)) {
|
||||
|
||||
/* Indicate that we got data. */
|
||||
gpio_toggle(GPIOA, GPIO8);
|
||||
|
||||
/* Retrieve the data from the peripheral. */
|
||||
data = usart_recv(USART2);
|
||||
|
||||
/* Enable transmit interrupt so it sends back the data. */
|
||||
USART_CR1(USART2) |= USART_CR1_TXEIE;
|
||||
}
|
||||
|
||||
/* Check if we were called because of TXE. */
|
||||
if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) &&
|
||||
((USART_SR(USART2) & USART_SR_TXE) != 0)) {
|
||||
|
||||
/* Indicate that we are sending out data. */
|
||||
gpio_toggle(GPIOC, GPIO15);
|
||||
|
||||
/* Put data into the transmit register. */
|
||||
usart_send(USART2, data);
|
||||
|
||||
/* Disable the TXE interrupt as we don't need it anymore. */
|
||||
USART_CR1(USART2) &= ~USART_CR1_TXEIE;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/* Wait forever and do nothing. */
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/stm32/f1/lisa-m-2/usart_irq_printf/Makefile
Normal file
25
examples/stm32/f1/lisa-m-2/usart_irq_printf/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart_irq_printf
|
||||
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
269
examples/stm32/f1/lisa-m-2/usart_irq_printf/usart_irq_printf.c
Normal file
269
examples/stm32/f1/lisa-m-2/usart_irq_printf/usart_irq_printf.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>,
|
||||
* Copyright (C) 2011 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/******************************************************************************
|
||||
* Simple ringbuffer implementation from open-bldc's libgovernor that
|
||||
* you can find at:
|
||||
* https://github.com/open-bldc/open-bldc/tree/master/source/libgovernor
|
||||
*****************************************************************************/
|
||||
|
||||
typedef s32 ring_size_t;
|
||||
|
||||
struct ring {
|
||||
u8 *data;
|
||||
ring_size_t size;
|
||||
u32 begin;
|
||||
u32 end;
|
||||
};
|
||||
|
||||
#define RING_SIZE(RING) ((RING)->size - 1)
|
||||
#define RING_DATA(RING) (RING)->data
|
||||
#define RING_EMPTY(RING) ((RING)->begin == (RING)->end)
|
||||
|
||||
void ring_init(struct ring *ring, u8 *buf, ring_size_t size)
|
||||
{
|
||||
ring->data = buf;
|
||||
ring->size = size;
|
||||
ring->begin = 0;
|
||||
ring->end = 0;
|
||||
}
|
||||
|
||||
s32 ring_write_ch(struct ring *ring, u8 ch)
|
||||
{
|
||||
if (((ring->end + 1) % ring->size) != ring->begin) {
|
||||
ring->data[ring->end++] = ch;
|
||||
ring->end %= ring->size;
|
||||
return (u32)ch;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
s32 ring_write(struct ring *ring, u8 *data, ring_size_t size)
|
||||
{
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (ring_write_ch(ring, data[i]) < 0)
|
||||
return -i;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
s32 ring_read_ch(struct ring *ring, u8 *ch)
|
||||
{
|
||||
s32 ret = -1;
|
||||
|
||||
if (ring->begin != ring->end) {
|
||||
ret = ring->data[ring->begin++];
|
||||
ring->begin %= ring->size;
|
||||
if (ch)
|
||||
*ch = ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 ring_read(struct ring *ring, u8 *data, ring_size_t size)
|
||||
{
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (ring_read_ch(ring, data + i) < 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -i;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* The example implementation
|
||||
*****************************************************************************/
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
struct ring output_ring;
|
||||
u8 output_ring_buffer[BUFFER_SIZE];
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
|
||||
RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Initialize output ring buffer. */
|
||||
ring_init(&output_ring, output_ring_buffer, BUFFER_SIZE);
|
||||
|
||||
/* Enable the USART2 interrupt. */
|
||||
nvic_enable_irq(NVIC_USART2_IRQ);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART2_TX on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART2_RX on GPIO port A for receive. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, GPIO_USART2_RX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART2, 230400);
|
||||
usart_set_databits(USART2, 8);
|
||||
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
||||
usart_set_parity(USART2, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
||||
usart_set_mode(USART2, USART_MODE_TX_RX);
|
||||
|
||||
/* Enable USART2 Receive interrupt. */
|
||||
USART_CR1(USART2) |= USART_CR1_RXNEIE;
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART2);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
gpio_set(GPIOA, GPIO8);
|
||||
|
||||
/* Setup GPIO8 (in GPIO port A) for LED use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
}
|
||||
|
||||
void usart2_isr(void)
|
||||
{
|
||||
/* Check if we were called because of RXNE. */
|
||||
if (((USART_CR1(USART2) & USART_CR1_RXNEIE) != 0) &&
|
||||
((USART_SR(USART2) & USART_SR_RXNE) != 0)) {
|
||||
|
||||
/* Indicate that we got data. */
|
||||
gpio_toggle(GPIOA, GPIO8);
|
||||
|
||||
/* Retrieve the data from the peripheral. */
|
||||
ring_write_ch(&output_ring, usart_recv(USART2));
|
||||
|
||||
/* Enable transmit interrupt so it sends back the data. */
|
||||
USART_CR1(USART2) |= USART_CR1_TXEIE;
|
||||
}
|
||||
|
||||
/* Check if we were called because of TXE. */
|
||||
if (((USART_CR1(USART2) & USART_CR1_TXEIE) != 0) &&
|
||||
((USART_SR(USART2) & USART_SR_TXE) != 0)) {
|
||||
|
||||
s32 data;
|
||||
|
||||
data = ring_read_ch(&output_ring, NULL);
|
||||
|
||||
if (data == -1) {
|
||||
/* Disable the TXE interrupt, it's no longer needed. */
|
||||
USART_CR1(USART2) &= ~USART_CR1_TXEIE;
|
||||
} else {
|
||||
/* Put data into the transmit register. */
|
||||
usart_send(USART2, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (file == 1) {
|
||||
ret = ring_write(&output_ring, (u8 *)ptr, len);
|
||||
|
||||
if (ret < 0)
|
||||
ret = -ret;
|
||||
|
||||
USART_CR1(USART2) |= USART_CR1_TXEIE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void systick_setup(void)
|
||||
{
|
||||
/* 72MHz / 8 => 9000000 counts per second. */
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
|
||||
/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
|
||||
systick_set_reload(9000);
|
||||
|
||||
systick_interrupt_enable();
|
||||
|
||||
/* Start counting. */
|
||||
systick_counter_enable();
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static int counter = 0;
|
||||
static float fcounter = 0.0;
|
||||
static double dcounter = 0.0;
|
||||
static u32 temp32 = 0;
|
||||
|
||||
temp32++;
|
||||
|
||||
/*
|
||||
* We call this handler every 1ms so we are sending hello world
|
||||
* every 10ms / 100Hz.
|
||||
*/
|
||||
if (temp32 == 10) {
|
||||
printf("Hello World! %i %f %f\r\n", counter, fcounter,
|
||||
dcounter);
|
||||
counter++;
|
||||
fcounter += 0.01;
|
||||
dcounter += 0.01;
|
||||
|
||||
temp32 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
systick_setup();
|
||||
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
examples/stm32/f1/lisa-m-2/usart_printf/Makefile
Normal file
25
examples/stm32/f1/lisa-m-2/usart_printf/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart_printf
|
||||
|
||||
LDSCRIPT = ../lisa-m.ld
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
106
examples/stm32/f1/lisa-m-2/usart_printf/usart_printf.c
Normal file
106
examples/stm32/f1/lisa-m-2/usart_printf/usart_printf.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>,
|
||||
* Copyright (C) 2011-2012 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* 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/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART2_TX) and USART2. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN |
|
||||
RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USART2EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO pin GPIO_USART2_RE_TX on GPIO port B for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART2, 230400);
|
||||
usart_set_databits(USART2, 8);
|
||||
usart_set_stopbits(USART2, USART_STOPBITS_1);
|
||||
usart_set_parity(USART2, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
|
||||
usart_set_mode(USART2, USART_MODE_TX);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART2);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
gpio_set(GPIOA, GPIO8);
|
||||
|
||||
/* Setup GPIO8 (in GPIO port A) for LED use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
}
|
||||
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (file == 1) {
|
||||
for (i = 0; i < len; i++)
|
||||
usart_send_blocking(USART2, ptr[i]);
|
||||
return i;
|
||||
}
|
||||
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int counter = 0;
|
||||
float fcounter = 0.0;
|
||||
double dcounter = 0.0;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/*
|
||||
* Write Hello World, an integer, float and double all over
|
||||
* again while incrementing the numbers.
|
||||
*/
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO8);
|
||||
printf("Hello World! %i %f %f\r\n", counter, fcounter,
|
||||
dcounter);
|
||||
counter++;
|
||||
fcounter += 0.01;
|
||||
dcounter += 0.01;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
u32 baseaddr = prog.addr + ((prog.blocknum - 2) *
|
||||
dfu_function.wTransferSize);
|
||||
for (i = 0; i < prog.len; i += 2)
|
||||
flash_library_half_word(baseaddr + i,
|
||||
flash_program_half_word(baseaddr + i,
|
||||
*(u16 *)(prog.buf + i));
|
||||
}
|
||||
flash_lock();
|
||||
|
||||
@@ -4,16 +4,16 @@
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser Lesser General Public License as published by
|
||||
* 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 Lesser General Public License for more details.
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser Lesser General Public License
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user