Rename F1 examples folder.
This commit is contained in:
committed by
Stephen Caudle
parent
ce7dd46aef
commit
cff706e3ca
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = fancyblink
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
/* Set STM32 to 72 MHz. */
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO12 (in GPIO port C) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO4);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_FULL_SWJ_NO_JNTRST;
|
||||
|
||||
/* preconfigure the led's */
|
||||
gpio_set(GPIOB, GPIO4); /* switch off led */
|
||||
gpio_clear(GPIOC, GPIO13); /* switch on led */
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
|
||||
/* Blink the LED (PC12) on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO13); /* LED on/off */
|
||||
gpio_toggle(GPIOB, GPIO4); /* LED on/off */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usbdfu
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB Device Firmware Upgrade (DFU) bootloader
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
#define APP_ADDRESS 0x08002000
|
||||
|
||||
/* Commands sent with wBlockNum == 0 as per ST implementation. */
|
||||
#define CMD_SETADDR 0x21
|
||||
#define CMD_ERASE 0x41
|
||||
|
||||
/* We need a special large control buffer for this device: */
|
||||
u8 usbd_control_buffer[1024];
|
||||
|
||||
static enum dfu_state usbdfu_state = STATE_DFU_IDLE;
|
||||
|
||||
static struct {
|
||||
u8 buf[sizeof(usbd_control_buffer)];
|
||||
u16 len;
|
||||
u32 addr;
|
||||
u16 blocknum;
|
||||
} prog;
|
||||
|
||||
const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x0483,
|
||||
.idProduct = 0xDF11,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
const struct usb_dfu_descriptor dfu_function = {
|
||||
.bLength = sizeof(struct usb_dfu_descriptor),
|
||||
.bDescriptorType = DFU_FUNCTIONAL,
|
||||
.bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH,
|
||||
.wDetachTimeout = 255,
|
||||
.wTransferSize = 1024,
|
||||
.bcdDFUVersion = 0x011A,
|
||||
};
|
||||
|
||||
const struct usb_interface_descriptor iface = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 0,
|
||||
.bInterfaceClass = 0xFE, /* Device Firmware Upgrade */
|
||||
.bInterfaceSubClass = 1,
|
||||
.bInterfaceProtocol = 2,
|
||||
|
||||
/* The ST Microelectronics DfuSe application needs this string.
|
||||
* The format isn't documented... */
|
||||
.iInterface = 4,
|
||||
|
||||
.extra = &dfu_function,
|
||||
.extralen = sizeof(dfu_function),
|
||||
};
|
||||
|
||||
const struct usb_interface ifaces[] = {{
|
||||
.num_altsetting = 1,
|
||||
.altsetting = &iface,
|
||||
}};
|
||||
|
||||
const struct usb_config_descriptor config = {
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0xC0,
|
||||
.bMaxPower = 0x32,
|
||||
|
||||
.interface = ifaces,
|
||||
};
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"DFU Demo",
|
||||
"DEMO",
|
||||
/* This string is used by ST Microelectronics' DfuSe utility */
|
||||
"@Internal Flash /0x08000000/8*001Ka,56*001Kg"
|
||||
};
|
||||
|
||||
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
{
|
||||
switch(usbdfu_state) {
|
||||
case STATE_DFU_DNLOAD_SYNC:
|
||||
usbdfu_state = STATE_DFU_DNBUSY;
|
||||
*bwPollTimeout = 100;
|
||||
return DFU_STATUS_OK;
|
||||
|
||||
case STATE_DFU_MANIFEST_SYNC:
|
||||
/* Device will reset when read is complete */
|
||||
usbdfu_state = STATE_DFU_MANIFEST;
|
||||
return DFU_STATUS_OK;
|
||||
|
||||
default:
|
||||
return DFU_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
|
||||
switch(usbdfu_state) {
|
||||
case STATE_DFU_DNBUSY:
|
||||
|
||||
flash_unlock();
|
||||
if(prog.blocknum == 0) {
|
||||
switch(prog.buf[0]) {
|
||||
case CMD_ERASE:
|
||||
flash_erase_page(*(u32*)(prog.buf+1));
|
||||
case CMD_SETADDR:
|
||||
prog.addr = *(u32*)(prog.buf+1);
|
||||
}
|
||||
} else {
|
||||
u32 baseaddr = prog.addr +
|
||||
((prog.blocknum - 2) *
|
||||
dfu_function.wTransferSize);
|
||||
for(i = 0; i < prog.len; i += 2)
|
||||
flash_program_half_word(baseaddr + i,
|
||||
*(u16*)(prog.buf+i));
|
||||
}
|
||||
flash_lock();
|
||||
|
||||
/* We jump straight to dfuDNLOAD-IDLE,
|
||||
* skipping dfuDNLOAD-SYNC
|
||||
*/
|
||||
usbdfu_state = STATE_DFU_DNLOAD_IDLE;
|
||||
return;
|
||||
|
||||
case STATE_DFU_MANIFEST:
|
||||
/* USB device must detach, we just reset... */
|
||||
scb_reset_system();
|
||||
return; /* Will never return */
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
|
||||
if((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
switch(req->bRequest) {
|
||||
case DFU_DNLOAD:
|
||||
if((len == NULL) || (*len == 0)) {
|
||||
usbdfu_state = STATE_DFU_MANIFEST_SYNC;
|
||||
return 1;
|
||||
} else {
|
||||
/* Copy download data for use on GET_STATUS */
|
||||
prog.blocknum = req->wValue;
|
||||
prog.len = *len;
|
||||
memcpy(prog.buf, *buf, *len);
|
||||
usbdfu_state = STATE_DFU_DNLOAD_SYNC;
|
||||
return 1;
|
||||
}
|
||||
case DFU_CLRSTATUS:
|
||||
/* Clear error and return to dfuIDLE */
|
||||
if(usbdfu_state == STATE_DFU_ERROR)
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
case DFU_ABORT:
|
||||
/* Abort returns to dfuIDLE state */
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
case DFU_UPLOAD:
|
||||
/* Upload not supported for now */
|
||||
return 0;
|
||||
case DFU_GETSTATUS: {
|
||||
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||
|
||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
||||
(*buf)[1] = bwPollTimeout & 0xFF;
|
||||
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
||||
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
||||
(*buf)[4] = usbdfu_state;
|
||||
(*buf)[5] = 0; /* iString not used here */
|
||||
*len = 6;
|
||||
|
||||
*complete = usbdfu_getstatus_complete;
|
||||
|
||||
return 1;
|
||||
}
|
||||
case DFU_GETSTATE:
|
||||
/* Return state with no state transision */
|
||||
*buf[0] = usbdfu_state;
|
||||
*len = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
if(!gpio_get(GPIOA, GPIO10)) {
|
||||
/* Boot the application if it's valid */
|
||||
if((*(volatile u32*)APP_ADDRESS & 0x2FFE0000) == 0x20000000) {
|
||||
/* Set vector table base address */
|
||||
SCB_VTOR = APP_ADDRESS & 0xFFFF;
|
||||
/* Initialise master stack pointer */
|
||||
asm volatile ("msr msp, %0"::"g"
|
||||
(*(volatile u32*)APP_ADDRESS));
|
||||
/* Jump to application */
|
||||
(*(void(**)())(APP_ADDRESS + 4))();
|
||||
}
|
||||
}
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 8K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usbhid
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB Human Interface Device (HID)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -1,289 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
* Copyright (C) 2011 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/stm32/otg_fs.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/hid.h>
|
||||
|
||||
/* Define this to include the DFU APP interface. */
|
||||
#define INCLUDE_DFU_INTERFACE
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
#include <libopencm3/stm32/scb.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
#endif
|
||||
|
||||
const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x0483,
|
||||
.idProduct = 0x5710,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
/* I have no idea what this means. I haven't read the HID spec. */
|
||||
static const u8 hid_report_descriptor[] = {
|
||||
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
|
||||
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
|
||||
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
|
||||
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,
|
||||
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38,
|
||||
0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03,
|
||||
0x81, 0x06, 0xC0, 0x09, 0x3c, 0x05, 0xff, 0x09,
|
||||
0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95,
|
||||
0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1,
|
||||
0x01, 0xc0
|
||||
};
|
||||
|
||||
static const struct {
|
||||
struct usb_hid_descriptor hid_descriptor;
|
||||
struct {
|
||||
u8 bReportDescriptorType;
|
||||
u16 wDescriptorLength;
|
||||
} __attribute__((packed)) hid_report;
|
||||
} __attribute__((packed)) hid_function = {
|
||||
.hid_descriptor = {
|
||||
.bLength = sizeof(hid_function),
|
||||
.bDescriptorType = USB_DT_HID,
|
||||
.bcdHID = 0x0100,
|
||||
.bCountryCode = 0,
|
||||
.bNumDescriptors = 1,
|
||||
},
|
||||
.hid_report = {
|
||||
.bReportDescriptorType = USB_DT_REPORT,
|
||||
.wDescriptorLength = sizeof(hid_report_descriptor),
|
||||
}
|
||||
};
|
||||
|
||||
const struct usb_endpoint_descriptor hid_endpoint = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = 0x81,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 4,
|
||||
.bInterval = 0x20,
|
||||
};
|
||||
|
||||
const struct usb_interface_descriptor hid_iface = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 1,
|
||||
.bInterfaceClass = USB_CLASS_HID,
|
||||
.bInterfaceSubClass = 1, /* boot */
|
||||
.bInterfaceProtocol = 2, /* mouse */
|
||||
.iInterface = 0,
|
||||
|
||||
.endpoint = &hid_endpoint,
|
||||
|
||||
.extra = &hid_function,
|
||||
.extralen = sizeof(hid_function),
|
||||
};
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
const struct usb_dfu_descriptor dfu_function = {
|
||||
.bLength = sizeof(struct usb_dfu_descriptor),
|
||||
.bDescriptorType = DFU_FUNCTIONAL,
|
||||
.bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH,
|
||||
.wDetachTimeout = 255,
|
||||
.wTransferSize = 1024,
|
||||
.bcdDFUVersion = 0x011A,
|
||||
};
|
||||
|
||||
const struct usb_interface_descriptor dfu_iface = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 1,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 0,
|
||||
.bInterfaceClass = 0xFE,
|
||||
.bInterfaceSubClass = 1,
|
||||
.bInterfaceProtocol = 1,
|
||||
.iInterface = 0,
|
||||
|
||||
.extra = &dfu_function,
|
||||
.extralen = sizeof(dfu_function),
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct usb_interface ifaces[] = {{
|
||||
.num_altsetting = 1,
|
||||
.altsetting = &hid_iface,
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
}, {
|
||||
.num_altsetting = 1,
|
||||
.altsetting = &dfu_iface,
|
||||
#endif
|
||||
}};
|
||||
|
||||
const struct usb_config_descriptor config = {
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
.bNumInterfaces = 2,
|
||||
#else
|
||||
.bNumInterfaces = 1,
|
||||
#endif
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0xC0,
|
||||
.bMaxPower = 0x32,
|
||||
|
||||
.interface = ifaces,
|
||||
};
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"HID Demo",
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
|
||||
if((req->bmRequestType != 0x81) ||
|
||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||
(req->wValue != 0x2200))
|
||||
return 0;
|
||||
|
||||
/* Handle the HID report descriptor */
|
||||
*buf = (u8*)hid_report_descriptor;
|
||||
*len = sizeof(hid_report_descriptor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
{
|
||||
(void)req;
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
|
||||
gpio_set(GPIOA, GPIO10);
|
||||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
|
||||
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
*complete = dfu_detach_complete;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hid_set_config(u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
hid_control_request);
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
dfu_control_request);
|
||||
#endif
|
||||
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
systick_set_reload(100000);
|
||||
systick_interrupt_enable();
|
||||
systick_counter_enable();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int usb_connect_blink = 0;
|
||||
rcc_clock_setup_in_hse_12mhz_out_72mhz();
|
||||
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* USB_DETECT as input */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, GPIO8);
|
||||
|
||||
/* green LED off, as output */
|
||||
gpio_set(GPIOC, GPIO2);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO2);
|
||||
|
||||
|
||||
usbd_init(&stm32f107_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(hid_set_config);
|
||||
|
||||
/* delay some seconds to show that pull-up switch works */
|
||||
{int i; for (i=0;i<0x800000;i++) asm("nop");}
|
||||
|
||||
/* wait for USB Vbus */
|
||||
while(gpio_get(GPIOA, GPIO8) == 0) asm("nop");
|
||||
|
||||
/* green LED on, connect USB */
|
||||
gpio_clear(GPIOC, GPIO2);
|
||||
//OTG_FS_GCCFG &= ~OTG_FS_GCCFG_VBUSBSEN;
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static int x = 0;
|
||||
static int dir = 1;
|
||||
u8 buf[4] = {0, 0, 0, 0};
|
||||
|
||||
buf[1] = dir;
|
||||
x += dir;
|
||||
if(x > 30) dir = -dir;
|
||||
if(x < -30) dir = -dir;
|
||||
|
||||
usbd_ep_write_packet(0x81, buf, 4);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = fancyblink
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is a blink example program using libopencm3.
|
||||
|
||||
It's intended for the ST STM32-based MB525 eval board (see
|
||||
http://www.st.com/stonline/products/literature/um/13472.htm for details).
|
||||
It should blink the LED on the board.
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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 program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO6 (in GPIO port C) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6 | GPIO7 | GPIO8 | GPIO9);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
|
||||
/* Blink the LED (PC12) on the board. */
|
||||
gpio_set(GPIOC, GPIO6);
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO6); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO9); /* LED on/off */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO9); /* LED on/off */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOC, GPIO6); /* LED on/off */
|
||||
gpio_toggle(GPIOC, GPIO7); /* LED on/off */
|
||||
for (i = 0; i < 4000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = pwmleds
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is a PWM based LED fading example using libopencm3.
|
||||
|
||||
It's intended for the ST STM32-based MB525 eval board (see
|
||||
http://www.st.com/stonline/products/literature/um/13472.htm for details).
|
||||
It should blink the LED on the board.
|
||||
|
||||
@@ -1,496 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
|
||||
// #define COMPARE
|
||||
// #define MOVING_FADE
|
||||
#define KITT
|
||||
|
||||
#ifdef COMPARE
|
||||
#define GAMMA_LINEAR
|
||||
#define GAMMA_1_3
|
||||
#define GAMMA_2_5
|
||||
#define GAMMA_3_0
|
||||
#endif
|
||||
|
||||
#ifdef MOVING_FADE
|
||||
#define GAMMA_2_2
|
||||
#define GAMMA_TABLE gamma_table_2_2
|
||||
#endif
|
||||
|
||||
#ifdef KITT
|
||||
#define GAMMA_2_5
|
||||
#define GAMMA_TABLE gamma_table_2_5
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Gamma correction table
|
||||
*
|
||||
* The nonlinear tables are calculating with the function:
|
||||
* Iout = Iin ** gamma
|
||||
*/
|
||||
#ifdef GAMMA_LINEAR
|
||||
static const u16 gamma_table_linear[] = {
|
||||
1, 4, 9, 17, 26, 37, 51, 67,
|
||||
84, 104, 126, 149, 175, 203, 233, 265,
|
||||
299, 334, 372, 412, 454, 499, 545, 593,
|
||||
643, 695, 749, 805, 864, 924, 986, 1050,
|
||||
1116, 1185, 1255, 1327, 1402, 1478, 1556, 1637,
|
||||
1719, 1803, 1890, 1978, 2068, 2161, 2255, 2352,
|
||||
2450, 2550, 2653, 2757, 2864, 2972, 3082, 3195,
|
||||
3309, 3426, 3544, 3664, 3787, 3911, 4038, 4166,
|
||||
4296, 4429, 4563, 4700, 4838, 4978, 5121, 5265,
|
||||
5411, 5560, 5710, 5862, 6017, 6173, 6331, 6492,
|
||||
6654, 6818, 6985, 7153, 7323, 7495, 7670, 7846,
|
||||
8024, 8204, 8387, 8571, 8757, 8945, 9135, 9327,
|
||||
9521, 9718, 9916, 10116, 10318, 10522, 10728, 10936,
|
||||
11146, 11358, 11572, 11788, 12006, 12226, 12448, 12672,
|
||||
12897, 13125, 13355, 13587, 13821, 14057, 14294, 14534,
|
||||
14776, 15020, 15265, 15513, 15763, 16014, 16268, 16524,
|
||||
16781, 17041, 17302, 17566, 17831, 18099, 18368, 18640,
|
||||
18913, 19189, 19466, 19745, 20027, 20310, 20595, 20883,
|
||||
21172, 21463, 21756, 22051, 22349, 22648, 22949, 23252,
|
||||
23557, 23864, 24173, 24484, 24797, 25112, 25429, 25748,
|
||||
26069, 26391, 26716, 27043, 27372, 27702, 28035, 28370,
|
||||
28707, 29045, 29386, 29728, 30073, 30419, 30768, 31118,
|
||||
31471, 31825, 32182, 32540, 32900, 33263, 33627, 33993,
|
||||
34361, 34731, 35104, 35478, 35854, 36232, 36612, 36994,
|
||||
37378, 37764, 38152, 38542, 38933, 39327, 39723, 40121,
|
||||
40521, 40922, 41326, 41732, 42139, 42549, 42960, 43374,
|
||||
43789, 44207, 44626, 45048, 45471, 45896, 46324, 46753,
|
||||
47184, 47617, 48052, 48490, 48929, 49370, 49813, 50258,
|
||||
50705, 51154, 51604, 52057, 52512, 52969, 53428, 53888,
|
||||
54351, 54816, 55282, 55751, 56222, 56694, 57169, 57645,
|
||||
58123, 58604, 59086, 59570, 60057, 60545, 61035, 61527,
|
||||
62021, 62517, 63016, 63516, 64018, 64521, 65027, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_1_3
|
||||
static const u16 gamma_table_1_3[] = {
|
||||
/* Gamma 1.3 */
|
||||
0, 49, 120, 203, 296, 395, 501, 612,
|
||||
728, 848, 973, 1101, 1233, 1368, 1506, 1648,
|
||||
1792, 1939, 2088, 2241, 2395, 2552, 2711, 2872,
|
||||
3036, 3201, 3369, 3538, 3709, 3882, 4057, 4234,
|
||||
4412, 4592, 4774, 4957, 5142, 5329, 5517, 5706,
|
||||
5897, 6090, 6283, 6479, 6675, 6873, 7072, 7273,
|
||||
7475, 7678, 7882, 8088, 8294, 8502, 8711, 8922,
|
||||
9133, 9346, 9559, 9774, 9990, 10207, 10425, 10644,
|
||||
10864, 11086, 11308, 11531, 11755, 11981, 12207, 12434,
|
||||
12662, 12891, 13121, 13352, 13584, 13817, 14051, 14285,
|
||||
14521, 14757, 14994, 15233, 15472, 15712, 15952, 16194,
|
||||
16436, 16679, 16923, 17168, 17414, 17660, 17908, 18156,
|
||||
18405, 18654, 18905, 19156, 19408, 19660, 19914, 20168,
|
||||
20423, 20679, 20935, 21192, 21450, 21708, 21968, 22228,
|
||||
22488, 22750, 23012, 23275, 23538, 23802, 24067, 24332,
|
||||
24599, 24865, 25133, 25401, 25670, 25939, 26209, 26480,
|
||||
26751, 27023, 27296, 27569, 27843, 28118, 28393, 28669,
|
||||
28945, 29222, 29500, 29778, 30057, 30336, 30616, 30897,
|
||||
31178, 31460, 31742, 32025, 32308, 32592, 32877, 33162,
|
||||
33448, 33734, 34021, 34309, 34597, 34885, 35175, 35464,
|
||||
35754, 36045, 36337, 36628, 36921, 37214, 37507, 37801,
|
||||
38096, 38391, 38686, 38982, 39279, 39576, 39874, 40172,
|
||||
40471, 40770, 41070, 41370, 41670, 41972, 42273, 42576,
|
||||
42878, 43181, 43485, 43789, 44094, 44399, 44705, 45011,
|
||||
45317, 45625, 45932, 46240, 46549, 46858, 47167, 47477,
|
||||
47787, 48098, 48409, 48721, 49034, 49346, 49659, 49973,
|
||||
50287, 50602, 50917, 51232, 51548, 51864, 52181, 52498,
|
||||
52816, 53134, 53452, 53771, 54091, 54411, 54731, 55052,
|
||||
55373, 55694, 56016, 56339, 56662, 56985, 57309, 57633,
|
||||
57957, 58282, 58608, 58933, 59260, 59586, 59913, 60241,
|
||||
60569, 60897, 61226, 61555, 61884, 62214, 62545, 62875,
|
||||
63206, 63538, 63870, 64202, 64535, 64868, 65201, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_2_2
|
||||
static const u16 gamma_table_2_2[] = {
|
||||
0, 0, 2, 4, 7, 11, 17, 24,
|
||||
32, 42, 53, 65, 79, 94, 111, 129,
|
||||
148, 169, 192, 216, 242, 270, 299, 330,
|
||||
362, 396, 432, 469, 508, 549, 591, 635,
|
||||
681, 729, 779, 830, 883, 938, 995, 1053,
|
||||
1113, 1175, 1239, 1305, 1373, 1443, 1514, 1587,
|
||||
1663, 1740, 1819, 1900, 1983, 2068, 2155, 2243,
|
||||
2334, 2427, 2521, 2618, 2717, 2817, 2920, 3024,
|
||||
3131, 3240, 3350, 3463, 3578, 3694, 3813, 3934,
|
||||
4057, 4182, 4309, 4438, 4570, 4703, 4838, 4976,
|
||||
5115, 5257, 5401, 5547, 5695, 5845, 5998, 6152,
|
||||
6309, 6468, 6629, 6792, 6957, 7124, 7294, 7466,
|
||||
7640, 7816, 7994, 8175, 8358, 8543, 8730, 8919,
|
||||
9111, 9305, 9501, 9699, 9900, 10102, 10307, 10515,
|
||||
10724, 10936, 11150, 11366, 11585, 11806, 12029, 12254,
|
||||
12482, 12712, 12944, 13179, 13416, 13655, 13896, 14140,
|
||||
14386, 14635, 14885, 15138, 15394, 15652, 15912, 16174,
|
||||
16439, 16706, 16975, 17247, 17521, 17798, 18077, 18358,
|
||||
18642, 18928, 19216, 19507, 19800, 20095, 20393, 20694,
|
||||
20996, 21301, 21609, 21919, 22231, 22546, 22863, 23182,
|
||||
23504, 23829, 24156, 24485, 24817, 25151, 25487, 25826,
|
||||
26168, 26512, 26858, 27207, 27558, 27912, 28268, 28627,
|
||||
28988, 29351, 29717, 30086, 30457, 30830, 31206, 31585,
|
||||
31966, 32349, 32735, 33124, 33514, 33908, 34304, 34702,
|
||||
35103, 35507, 35913, 36321, 36732, 37146, 37562, 37981,
|
||||
38402, 38825, 39252, 39680, 40112, 40546, 40982, 41421,
|
||||
41862, 42306, 42753, 43202, 43654, 44108, 44565, 45025,
|
||||
45487, 45951, 46418, 46888, 47360, 47835, 48313, 48793,
|
||||
49275, 49761, 50249, 50739, 51232, 51728, 52226, 52727,
|
||||
53230, 53736, 54245, 54756, 55270, 55787, 56306, 56828,
|
||||
57352, 57879, 58409, 58941, 59476, 60014, 60554, 61097,
|
||||
61642, 62190, 62741, 63295, 63851, 64410, 64971, 65535
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_2_5
|
||||
static const u16 gamma_table_2_5[] = {
|
||||
/* gamma = 2.5 */
|
||||
0, 0, 0, 1, 2, 4, 6, 8,
|
||||
11, 15, 20, 25, 31, 38, 46, 55,
|
||||
65, 75, 87, 99, 113, 128, 143, 160,
|
||||
178, 197, 218, 239, 262, 286, 311, 338,
|
||||
366, 395, 425, 457, 491, 526, 562, 599,
|
||||
639, 679, 722, 765, 811, 857, 906, 956,
|
||||
1007, 1061, 1116, 1172, 1231, 1291, 1352, 1416,
|
||||
1481, 1548, 1617, 1688, 1760, 1834, 1910, 1988,
|
||||
2068, 2150, 2233, 2319, 2407, 2496, 2587, 2681,
|
||||
2776, 2874, 2973, 3075, 3178, 3284, 3391, 3501,
|
||||
3613, 3727, 3843, 3961, 4082, 4204, 4329, 4456,
|
||||
4585, 4716, 4850, 4986, 5124, 5264, 5407, 5552,
|
||||
5699, 5849, 6001, 6155, 6311, 6470, 6632, 6795,
|
||||
6962, 7130, 7301, 7475, 7650, 7829, 8009, 8193,
|
||||
8379, 8567, 8758, 8951, 9147, 9345, 9546, 9750,
|
||||
9956, 10165, 10376, 10590, 10806, 11025, 11247, 11472,
|
||||
11699, 11929, 12161, 12397, 12634, 12875, 13119, 13365,
|
||||
13614, 13865, 14120, 14377, 14637, 14899, 15165, 15433,
|
||||
15705, 15979, 16256, 16535, 16818, 17104, 17392, 17683,
|
||||
17978, 18275, 18575, 18878, 19184, 19493, 19805, 20119,
|
||||
20437, 20758, 21082, 21409, 21739, 22072, 22407, 22746,
|
||||
23089, 23434, 23782, 24133, 24487, 24845, 25206, 25569,
|
||||
25936, 26306, 26679, 27055, 27435, 27818, 28203, 28592,
|
||||
28985, 29380, 29779, 30181, 30586, 30994, 31406, 31820,
|
||||
32239, 32660, 33085, 33513, 33944, 34379, 34817, 35258,
|
||||
35702, 36150, 36602, 37056, 37514, 37976, 38441, 38909,
|
||||
39380, 39856, 40334, 40816, 41301, 41790, 42282, 42778,
|
||||
43277, 43780, 44286, 44795, 45308, 45825, 46345, 46869,
|
||||
47396, 47927, 48461, 48999, 49540, 50085, 50634, 51186,
|
||||
51742, 52301, 52864, 53431, 54001, 54575, 55153, 55734,
|
||||
56318, 56907, 57499, 58095, 58695, 59298, 59905, 60515,
|
||||
61130, 61748, 62370, 62995, 63624, 64258, 64894, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_3_0
|
||||
static const u16 gamma_table_3_0[] = {
|
||||
/* gamma = 3.0 */
|
||||
0, 0, 0, 0, 0, 0, 1, 1,
|
||||
2, 3, 4, 5, 7, 9, 11, 13,
|
||||
16, 19, 23, 27, 32, 37, 42, 48,
|
||||
55, 62, 69, 78, 87, 96, 107, 118,
|
||||
130, 142, 155, 169, 184, 200, 217, 234,
|
||||
253, 272, 293, 314, 337, 360, 385, 410,
|
||||
437, 465, 494, 524, 556, 588, 622, 658,
|
||||
694, 732, 771, 812, 854, 897, 942, 988,
|
||||
1036, 1085, 1136, 1189, 1243, 1298, 1356, 1415,
|
||||
1475, 1538, 1602, 1667, 1735, 1804, 1876, 1949,
|
||||
2024, 2100, 2179, 2260, 2343, 2427, 2514, 2603,
|
||||
2693, 2786, 2881, 2978, 3078, 3179, 3283, 3389,
|
||||
3497, 3607, 3720, 3835, 3952, 4072, 4194, 4319,
|
||||
4446, 4575, 4707, 4842, 4979, 5118, 5261, 5405,
|
||||
5553, 5703, 5856, 6011, 6169, 6330, 6494, 6660,
|
||||
6830, 7002, 7177, 7355, 7536, 7719, 7906, 8096,
|
||||
8289, 8484, 8683, 8885, 9090, 9298, 9510, 9724,
|
||||
9942, 10163, 10387, 10614, 10845, 11079, 11317, 11557,
|
||||
11802, 12049, 12300, 12555, 12813, 13074, 13339, 13608,
|
||||
13880, 14156, 14435, 14718, 15005, 15295, 15589, 15887,
|
||||
16189, 16494, 16803, 17117, 17433, 17754, 18079, 18408,
|
||||
18740, 19077, 19418, 19762, 20111, 20464, 20821, 21182,
|
||||
21547, 21917, 22290, 22668, 23050, 23436, 23827, 24222,
|
||||
24621, 25025, 25433, 25845, 26262, 26683, 27109, 27539,
|
||||
27974, 28413, 28857, 29306, 29759, 30217, 30680, 31147,
|
||||
31619, 32095, 32577, 33063, 33554, 34050, 34551, 35056,
|
||||
35567, 36082, 36602, 37128, 37658, 38194, 38734, 39280,
|
||||
39830, 40386, 40947, 41513, 42084, 42661, 43243, 43830,
|
||||
44422, 45019, 45622, 46231, 46844, 47463, 48088, 48718,
|
||||
49353, 49994, 50641, 51293, 51950, 52614, 53282, 53957,
|
||||
54637, 55323, 56014, 56712, 57415, 58123, 58838, 59558,
|
||||
60285, 61017, 61755, 62499, 63249, 64005, 64767, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable TIM1 clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_TIM1EN);
|
||||
|
||||
/* Enable GPIOC, Alternate Function clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR,
|
||||
RCC_APB2ENR_IOPAEN | RCC_APB2ENR_AFIOEN);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/*
|
||||
* Set GPIO6 (in GPIO port C) to
|
||||
* 'output alternate function push-pull'.
|
||||
*/
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
||||
GPIO_TIM1_CH1 |
|
||||
GPIO_TIM1_CH2 |
|
||||
GPIO_TIM1_CH3 |
|
||||
GPIO_TIM1_CH4);
|
||||
|
||||
/* Remap TIM1:
|
||||
* CH1 -> PC6
|
||||
* CH2 -> PC7
|
||||
* CH3 -> PC8
|
||||
* CH4 -> PC9
|
||||
*/
|
||||
//AFIO_MAPR |= AFIO_MAPR_TIM3_REMAP_FULL_REMAP;
|
||||
}
|
||||
void tim_setup(void)
|
||||
{
|
||||
#if 0
|
||||
TIM1_CR1 = TIM_CR1_CMS_CENTER_1 | TIM_CR1_ARPE;
|
||||
TIM1_CCMR1 = TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC1PE | TIM_CCMR1_OC2M_PWM1 | TIM_CCMR1_OC2PE;
|
||||
TIM1_CCMR2 = TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE;
|
||||
|
||||
TIM1_CCER &= ~TIM_CCER_CC1P;
|
||||
#endif
|
||||
#if 1
|
||||
TIM1_SMCR &= ~TIM_SMCR_SMS_MASK;
|
||||
TIM1_CR1 &= ~TIM_CR1_CEN;
|
||||
|
||||
/* Clock division and mode */
|
||||
TIM1_CR1 = TIM_CR1_CKD_CK_INT | TIM_CR1_CMS_EDGE;
|
||||
/* Period */
|
||||
TIM1_ARR = 65535;
|
||||
/* Prescaler */
|
||||
TIM1_PSC = 2;
|
||||
TIM1_EGR = TIM_EGR_UG;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 1 mode and preload */
|
||||
TIM1_CCMR1 |= TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC1PE;
|
||||
|
||||
/* Polarity and state */
|
||||
// TIM1_CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;
|
||||
TIM1_CCER |= TIM_CCER_CC1E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM1_CCR1 = 1000;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 2 mode and preload */
|
||||
TIM1_CCMR1 |= TIM_CCMR1_OC2M_PWM1 | TIM_CCMR1_OC2PE;
|
||||
|
||||
/* Polarity and state */
|
||||
// TIM1_CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;
|
||||
TIM1_CCER |= TIM_CCER_CC2E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM1_CCR2 = 1000;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 3 mode and preload */
|
||||
TIM1_CCMR2 |= TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE;
|
||||
|
||||
/* Polarity and state */
|
||||
// TIM1_CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;
|
||||
TIM1_CCER |= TIM_CCER_CC3E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM1_CCR3 = 1000;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 4 mode and preload */
|
||||
TIM1_CCMR2 |= TIM_CCMR2_OC4M_PWM1 | TIM_CCMR2_OC4PE;
|
||||
|
||||
/* Polarity and state */
|
||||
// TIM1_CCER = TIM_CCER_CC1P | TIM_CCER_CC1E;
|
||||
TIM1_CCER |= TIM_CCER_CC4E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM1_CCR4 = 1000;
|
||||
|
||||
/* ---- */
|
||||
/* ARR reload enable */
|
||||
TIM1_CR1 |= TIM_CR1_ARPE;
|
||||
|
||||
TIM1_BDTR |= TIM_BDTR_MOE;
|
||||
|
||||
/* Counter enable */
|
||||
TIM1_CR1 |= TIM_CR1_CEN;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j0, j1, j2, j3, d0, d1, d2, d3, j, k, kd;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
tim_setup();
|
||||
|
||||
#ifdef COMPARE
|
||||
j0 = 0;
|
||||
d0 = 1;
|
||||
j1 = 0;
|
||||
d1 = 1;
|
||||
j2 = 0;
|
||||
d2 = 1;
|
||||
j3 = 0;
|
||||
d3 = 1;
|
||||
while (1) {
|
||||
TIM1_CCR1 = gamma_table_linear[j0];
|
||||
j0 += d0;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 0)
|
||||
d0 = 1;
|
||||
TIM1_CCR2 = gamma_table_1_3[j1];
|
||||
j1 += d1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 0)
|
||||
d1 = 1;
|
||||
TIM1_CCR3 = gamma_table_2_5[j2];
|
||||
j2 += d2;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 0)
|
||||
d2 = 1;
|
||||
TIM1_CCR4= gamma_table_3_0[j3];
|
||||
j3 += d3;
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 0)
|
||||
d3 = 1;
|
||||
for (i = 0; i < 50000; i++);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOVING_FADE
|
||||
j0 = 0;
|
||||
d0 = 1;
|
||||
j1 = 128;
|
||||
d1 = 1;
|
||||
j2 = 255;
|
||||
d2 = -1;
|
||||
j3 = 128;
|
||||
d3 = -1;
|
||||
while (1) {
|
||||
TIM1_CCR1 = GAMMA_TABLE[j0];
|
||||
j0 += d0;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 0)
|
||||
d0 = 1;
|
||||
TIM1_CCR2 = GAMMA_TABLE[j1];
|
||||
j1 += d1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 0)
|
||||
d1 = 1;
|
||||
TIM1_CCR3 = GAMMA_TABLE[j2];
|
||||
j2 += d2;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 0)
|
||||
d2 = 1;
|
||||
TIM1_CCR4 = GAMMA_TABLE[j3];
|
||||
j3 += d3;
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 0)
|
||||
d3 = 1;
|
||||
for (i = 0; i < 10000; i++);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KITT
|
||||
j0 = 255;
|
||||
d0 = -1;
|
||||
j1 = 20;
|
||||
d1 = -1;
|
||||
j2 = 20;
|
||||
d2 = -1;
|
||||
j3 = 20;
|
||||
d3 = -1;
|
||||
j = 0;
|
||||
k = 0;
|
||||
kd = 1;
|
||||
while (1) {
|
||||
TIM1_CCR1 = GAMMA_TABLE[j0];
|
||||
j0 += d0;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 19)
|
||||
j0 = 20;
|
||||
TIM1_CCR2 = GAMMA_TABLE[j1];
|
||||
j1 += d1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 19)
|
||||
j1 = 20;
|
||||
TIM1_CCR3 = GAMMA_TABLE[j2];
|
||||
j2 += d2;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 19)
|
||||
j2 = 20;
|
||||
TIM1_CCR4 = GAMMA_TABLE[j3];
|
||||
j3 += d3;
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 19)
|
||||
j3 = 20;
|
||||
for (i = 0; i < 5000; i++);
|
||||
j++;
|
||||
if (j == 100) {
|
||||
j = 0;
|
||||
switch (k += kd) {
|
||||
case 0:
|
||||
j0 = 255;
|
||||
break;
|
||||
case 1:
|
||||
j1 = 255;
|
||||
break;
|
||||
case 2:
|
||||
j2 = 255;
|
||||
break;
|
||||
case 3:
|
||||
j3 = 255;
|
||||
break;
|
||||
}
|
||||
if (k == 3)
|
||||
kd =- 1;
|
||||
if (k == 0)
|
||||
kd = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = can
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/stm32/can.h>
|
||||
|
||||
struct can_tx_msg {
|
||||
u32 std_id;
|
||||
u32 ext_id;
|
||||
u8 ide;
|
||||
u8 rtr;
|
||||
u8 dlc;
|
||||
u8 data[8];
|
||||
};
|
||||
|
||||
struct can_rx_msg {
|
||||
u32 std_id;
|
||||
u32 ext_id;
|
||||
u8 ide;
|
||||
u8 rtr;
|
||||
u8 dlc;
|
||||
u8 data[8];
|
||||
u8 fmi;
|
||||
};
|
||||
|
||||
struct can_tx_msg can_tx_msg;
|
||||
struct can_rx_msg can_rx_msg;
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOA clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
gpio_set(GPIOA, GPIO6); /* LED0 off */
|
||||
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||
gpio_set(GPIOB, GPIO0); /* LED2 off */
|
||||
gpio_set(GPIOB, GPIO1); /* LED3 off */
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port A) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO0);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
|
||||
}
|
||||
|
||||
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 can_setup(void)
|
||||
{
|
||||
/* Enable peripheral clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_CANEN);
|
||||
|
||||
/* Configure CAN pin: RX (input pull-up). */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_CAN_RX);
|
||||
gpio_set(GPIOA, GPIO_CAN_RX);
|
||||
|
||||
/* Configure CAN pin: TX. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_CAN_TX);
|
||||
|
||||
/* NVIC setup. */
|
||||
nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ);
|
||||
nvic_set_priority(NVIC_USB_LP_CAN_RX0_IRQ, 1);
|
||||
|
||||
/* Reset CAN. */
|
||||
can_reset(CAN1);
|
||||
|
||||
/* CAN cell init. */
|
||||
if (can_init(CAN1,
|
||||
false, /* TTCM: Time triggered comm mode? */
|
||||
true, /* ABOM: Automatic bus-off management? */
|
||||
false, /* AWUM: Automatic wakeup mode? */
|
||||
false, /* NART: No automatic retransmission? */
|
||||
false, /* RFLM: Receive FIFO locked mode? */
|
||||
false, /* TXFP: Transmit FIFO priority? */
|
||||
CAN_BTR_SJW_1TQ,
|
||||
CAN_BTR_TS1_3TQ,
|
||||
CAN_BTR_TS2_4TQ,
|
||||
12)) /* BRP+1: Baud rate prescaler */
|
||||
{
|
||||
gpio_set(GPIOA, GPIO6); /* LED0 off */
|
||||
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||
gpio_set(GPIOB, GPIO0); /* LED2 off */
|
||||
gpio_clear(GPIOB, GPIO1); /* LED3 on */
|
||||
|
||||
/* Die because we failed to initialize. */
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
/* CAN filter 0 init. */
|
||||
can_filter_id_mask_32bit_init(CAN1,
|
||||
0, /* Filter ID */
|
||||
0, /* CAN ID */
|
||||
0, /* CAN ID mask */
|
||||
0, /* FIFO assignment (here: FIFO0) */
|
||||
true); /* Enable the filter. */
|
||||
|
||||
/* Enable CAN RX interrupt. */
|
||||
can_enable_irq(CAN1, CAN_IER_FMPIE0);
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static int temp32 = 0;
|
||||
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||
|
||||
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
||||
if (++temp32 != 1000)
|
||||
return;
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
/* Transmit CAN frame. */
|
||||
data[0]++;
|
||||
if (can_transmit(CAN1,
|
||||
0, /* (EX/ST)ID: CAN ID */
|
||||
false, /* IDE: CAN ID extended? */
|
||||
false, /* RTR: Request transmit? */
|
||||
8, /* DLC: Data length */
|
||||
data) == -1)
|
||||
{
|
||||
gpio_set(GPIOA, GPIO6); /* LED0 off */
|
||||
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||
gpio_clear(GPIOB, GPIO0); /* LED2 on */
|
||||
gpio_set(GPIOB, GPIO1); /* LED3 off */
|
||||
}
|
||||
}
|
||||
|
||||
void usb_lp_can_rx0_isr(void)
|
||||
{
|
||||
u32 id, fmi;
|
||||
bool ext, rtr;
|
||||
u8 length, data[8];
|
||||
|
||||
can_receive(CAN1, 0, false, &id, &ext, &rtr, &fmi, &length, data);
|
||||
|
||||
if (data[0] & 1)
|
||||
gpio_clear(GPIOA, GPIO6);
|
||||
else
|
||||
gpio_set(GPIOA, GPIO6);
|
||||
|
||||
if (data[0] & 2)
|
||||
gpio_clear(GPIOA, GPIO7);
|
||||
else
|
||||
gpio_set(GPIOA, GPIO7);
|
||||
|
||||
if (data[0] & 4)
|
||||
gpio_clear(GPIOB, GPIO0);
|
||||
else
|
||||
gpio_set(GPIOB, GPIO0);
|
||||
|
||||
if (data[0] & 8)
|
||||
gpio_clear(GPIOB, GPIO1);
|
||||
else
|
||||
gpio_set(GPIOB, GPIO1);
|
||||
|
||||
can_fifo_release(CAN1, 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
can_setup();
|
||||
systick_setup();
|
||||
|
||||
while (1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = led
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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 program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
/* Set STM32 to 72 MHz. */
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO6 and 7 (in GPIO port A) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6 | GPIO7);
|
||||
|
||||
/* Set GPIO0 and 1 (in GPIO port B) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO0 | GPIO1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
|
||||
/* Blink the LEDs on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO6); /* LED on/off */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOA, GPIO7); /* LED on/off */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOB, GPIO0); /* LED on/off */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
gpio_toggle(GPIOB, GPIO1); /* LED on/off */
|
||||
for (i = 0; i < 8000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Open-BLDC (STM32F103CBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = pwmleds
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,485 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
|
||||
// #define COMPARE
|
||||
// #define MOVING_FADE
|
||||
#define KITT
|
||||
|
||||
#ifdef COMPARE
|
||||
#define GAMMA_LINEAR
|
||||
#define GAMMA_1_3
|
||||
#define GAMMA_2_5
|
||||
#define GAMMA_3_0
|
||||
#endif
|
||||
|
||||
#ifdef MOVING_FADE
|
||||
#define GAMMA_2_2
|
||||
#define GAMMA_TABLE gamma_table_2_2
|
||||
#endif
|
||||
|
||||
#ifdef KITT
|
||||
#define GAMMA_2_5
|
||||
#define GAMMA_TABLE gamma_table_2_5
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Gamma correction table
|
||||
*
|
||||
* The nonlinear tables are calculating with the function:
|
||||
* Iout = Iin ** gamma
|
||||
*/
|
||||
#ifdef GAMMA_LINEAR
|
||||
static const u16 gamma_table_linear[] = {
|
||||
1, 4, 9, 17, 26, 37, 51, 67,
|
||||
84, 104, 126, 149, 175, 203, 233, 265,
|
||||
299, 334, 372, 412, 454, 499, 545, 593,
|
||||
643, 695, 749, 805, 864, 924, 986, 1050,
|
||||
1116, 1185, 1255, 1327, 1402, 1478, 1556, 1637,
|
||||
1719, 1803, 1890, 1978, 2068, 2161, 2255, 2352,
|
||||
2450, 2550, 2653, 2757, 2864, 2972, 3082, 3195,
|
||||
3309, 3426, 3544, 3664, 3787, 3911, 4038, 4166,
|
||||
4296, 4429, 4563, 4700, 4838, 4978, 5121, 5265,
|
||||
5411, 5560, 5710, 5862, 6017, 6173, 6331, 6492,
|
||||
6654, 6818, 6985, 7153, 7323, 7495, 7670, 7846,
|
||||
8024, 8204, 8387, 8571, 8757, 8945, 9135, 9327,
|
||||
9521, 9718, 9916, 10116, 10318, 10522, 10728, 10936,
|
||||
11146, 11358, 11572, 11788, 12006, 12226, 12448, 12672,
|
||||
12897, 13125, 13355, 13587, 13821, 14057, 14294, 14534,
|
||||
14776, 15020, 15265, 15513, 15763, 16014, 16268, 16524,
|
||||
16781, 17041, 17302, 17566, 17831, 18099, 18368, 18640,
|
||||
18913, 19189, 19466, 19745, 20027, 20310, 20595, 20883,
|
||||
21172, 21463, 21756, 22051, 22349, 22648, 22949, 23252,
|
||||
23557, 23864, 24173, 24484, 24797, 25112, 25429, 25748,
|
||||
26069, 26391, 26716, 27043, 27372, 27702, 28035, 28370,
|
||||
28707, 29045, 29386, 29728, 30073, 30419, 30768, 31118,
|
||||
31471, 31825, 32182, 32540, 32900, 33263, 33627, 33993,
|
||||
34361, 34731, 35104, 35478, 35854, 36232, 36612, 36994,
|
||||
37378, 37764, 38152, 38542, 38933, 39327, 39723, 40121,
|
||||
40521, 40922, 41326, 41732, 42139, 42549, 42960, 43374,
|
||||
43789, 44207, 44626, 45048, 45471, 45896, 46324, 46753,
|
||||
47184, 47617, 48052, 48490, 48929, 49370, 49813, 50258,
|
||||
50705, 51154, 51604, 52057, 52512, 52969, 53428, 53888,
|
||||
54351, 54816, 55282, 55751, 56222, 56694, 57169, 57645,
|
||||
58123, 58604, 59086, 59570, 60057, 60545, 61035, 61527,
|
||||
62021, 62517, 63016, 63516, 64018, 64521, 65027, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_1_3
|
||||
static const u16 gamma_table_1_3[] = {
|
||||
/* Gamma 1.3 */
|
||||
0, 49, 120, 203, 296, 395, 501, 612,
|
||||
728, 848, 973, 1101, 1233, 1368, 1506, 1648,
|
||||
1792, 1939, 2088, 2241, 2395, 2552, 2711, 2872,
|
||||
3036, 3201, 3369, 3538, 3709, 3882, 4057, 4234,
|
||||
4412, 4592, 4774, 4957, 5142, 5329, 5517, 5706,
|
||||
5897, 6090, 6283, 6479, 6675, 6873, 7072, 7273,
|
||||
7475, 7678, 7882, 8088, 8294, 8502, 8711, 8922,
|
||||
9133, 9346, 9559, 9774, 9990, 10207, 10425, 10644,
|
||||
10864, 11086, 11308, 11531, 11755, 11981, 12207, 12434,
|
||||
12662, 12891, 13121, 13352, 13584, 13817, 14051, 14285,
|
||||
14521, 14757, 14994, 15233, 15472, 15712, 15952, 16194,
|
||||
16436, 16679, 16923, 17168, 17414, 17660, 17908, 18156,
|
||||
18405, 18654, 18905, 19156, 19408, 19660, 19914, 20168,
|
||||
20423, 20679, 20935, 21192, 21450, 21708, 21968, 22228,
|
||||
22488, 22750, 23012, 23275, 23538, 23802, 24067, 24332,
|
||||
24599, 24865, 25133, 25401, 25670, 25939, 26209, 26480,
|
||||
26751, 27023, 27296, 27569, 27843, 28118, 28393, 28669,
|
||||
28945, 29222, 29500, 29778, 30057, 30336, 30616, 30897,
|
||||
31178, 31460, 31742, 32025, 32308, 32592, 32877, 33162,
|
||||
33448, 33734, 34021, 34309, 34597, 34885, 35175, 35464,
|
||||
35754, 36045, 36337, 36628, 36921, 37214, 37507, 37801,
|
||||
38096, 38391, 38686, 38982, 39279, 39576, 39874, 40172,
|
||||
40471, 40770, 41070, 41370, 41670, 41972, 42273, 42576,
|
||||
42878, 43181, 43485, 43789, 44094, 44399, 44705, 45011,
|
||||
45317, 45625, 45932, 46240, 46549, 46858, 47167, 47477,
|
||||
47787, 48098, 48409, 48721, 49034, 49346, 49659, 49973,
|
||||
50287, 50602, 50917, 51232, 51548, 51864, 52181, 52498,
|
||||
52816, 53134, 53452, 53771, 54091, 54411, 54731, 55052,
|
||||
55373, 55694, 56016, 56339, 56662, 56985, 57309, 57633,
|
||||
57957, 58282, 58608, 58933, 59260, 59586, 59913, 60241,
|
||||
60569, 60897, 61226, 61555, 61884, 62214, 62545, 62875,
|
||||
63206, 63538, 63870, 64202, 64535, 64868, 65201, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_2_2
|
||||
static const u16 gamma_table_2_2[] = {
|
||||
0, 0, 2, 4, 7, 11, 17, 24,
|
||||
32, 42, 53, 65, 79, 94, 111, 129,
|
||||
148, 169, 192, 216, 242, 270, 299, 330,
|
||||
362, 396, 432, 469, 508, 549, 591, 635,
|
||||
681, 729, 779, 830, 883, 938, 995, 1053,
|
||||
1113, 1175, 1239, 1305, 1373, 1443, 1514, 1587,
|
||||
1663, 1740, 1819, 1900, 1983, 2068, 2155, 2243,
|
||||
2334, 2427, 2521, 2618, 2717, 2817, 2920, 3024,
|
||||
3131, 3240, 3350, 3463, 3578, 3694, 3813, 3934,
|
||||
4057, 4182, 4309, 4438, 4570, 4703, 4838, 4976,
|
||||
5115, 5257, 5401, 5547, 5695, 5845, 5998, 6152,
|
||||
6309, 6468, 6629, 6792, 6957, 7124, 7294, 7466,
|
||||
7640, 7816, 7994, 8175, 8358, 8543, 8730, 8919,
|
||||
9111, 9305, 9501, 9699, 9900, 10102, 10307, 10515,
|
||||
10724, 10936, 11150, 11366, 11585, 11806, 12029, 12254,
|
||||
12482, 12712, 12944, 13179, 13416, 13655, 13896, 14140,
|
||||
14386, 14635, 14885, 15138, 15394, 15652, 15912, 16174,
|
||||
16439, 16706, 16975, 17247, 17521, 17798, 18077, 18358,
|
||||
18642, 18928, 19216, 19507, 19800, 20095, 20393, 20694,
|
||||
20996, 21301, 21609, 21919, 22231, 22546, 22863, 23182,
|
||||
23504, 23829, 24156, 24485, 24817, 25151, 25487, 25826,
|
||||
26168, 26512, 26858, 27207, 27558, 27912, 28268, 28627,
|
||||
28988, 29351, 29717, 30086, 30457, 30830, 31206, 31585,
|
||||
31966, 32349, 32735, 33124, 33514, 33908, 34304, 34702,
|
||||
35103, 35507, 35913, 36321, 36732, 37146, 37562, 37981,
|
||||
38402, 38825, 39252, 39680, 40112, 40546, 40982, 41421,
|
||||
41862, 42306, 42753, 43202, 43654, 44108, 44565, 45025,
|
||||
45487, 45951, 46418, 46888, 47360, 47835, 48313, 48793,
|
||||
49275, 49761, 50249, 50739, 51232, 51728, 52226, 52727,
|
||||
53230, 53736, 54245, 54756, 55270, 55787, 56306, 56828,
|
||||
57352, 57879, 58409, 58941, 59476, 60014, 60554, 61097,
|
||||
61642, 62190, 62741, 63295, 63851, 64410, 64971, 65535
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_2_5
|
||||
static const u16 gamma_table_2_5[] = {
|
||||
/* gamma = 2.5 */
|
||||
0, 0, 0, 1, 2, 4, 6, 8,
|
||||
11, 15, 20, 25, 31, 38, 46, 55,
|
||||
65, 75, 87, 99, 113, 128, 143, 160,
|
||||
178, 197, 218, 239, 262, 286, 311, 338,
|
||||
366, 395, 425, 457, 491, 526, 562, 599,
|
||||
639, 679, 722, 765, 811, 857, 906, 956,
|
||||
1007, 1061, 1116, 1172, 1231, 1291, 1352, 1416,
|
||||
1481, 1548, 1617, 1688, 1760, 1834, 1910, 1988,
|
||||
2068, 2150, 2233, 2319, 2407, 2496, 2587, 2681,
|
||||
2776, 2874, 2973, 3075, 3178, 3284, 3391, 3501,
|
||||
3613, 3727, 3843, 3961, 4082, 4204, 4329, 4456,
|
||||
4585, 4716, 4850, 4986, 5124, 5264, 5407, 5552,
|
||||
5699, 5849, 6001, 6155, 6311, 6470, 6632, 6795,
|
||||
6962, 7130, 7301, 7475, 7650, 7829, 8009, 8193,
|
||||
8379, 8567, 8758, 8951, 9147, 9345, 9546, 9750,
|
||||
9956, 10165, 10376, 10590, 10806, 11025, 11247, 11472,
|
||||
11699, 11929, 12161, 12397, 12634, 12875, 13119, 13365,
|
||||
13614, 13865, 14120, 14377, 14637, 14899, 15165, 15433,
|
||||
15705, 15979, 16256, 16535, 16818, 17104, 17392, 17683,
|
||||
17978, 18275, 18575, 18878, 19184, 19493, 19805, 20119,
|
||||
20437, 20758, 21082, 21409, 21739, 22072, 22407, 22746,
|
||||
23089, 23434, 23782, 24133, 24487, 24845, 25206, 25569,
|
||||
25936, 26306, 26679, 27055, 27435, 27818, 28203, 28592,
|
||||
28985, 29380, 29779, 30181, 30586, 30994, 31406, 31820,
|
||||
32239, 32660, 33085, 33513, 33944, 34379, 34817, 35258,
|
||||
35702, 36150, 36602, 37056, 37514, 37976, 38441, 38909,
|
||||
39380, 39856, 40334, 40816, 41301, 41790, 42282, 42778,
|
||||
43277, 43780, 44286, 44795, 45308, 45825, 46345, 46869,
|
||||
47396, 47927, 48461, 48999, 49540, 50085, 50634, 51186,
|
||||
51742, 52301, 52864, 53431, 54001, 54575, 55153, 55734,
|
||||
56318, 56907, 57499, 58095, 58695, 59298, 59905, 60515,
|
||||
61130, 61748, 62370, 62995, 63624, 64258, 64894, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef GAMMA_3_0
|
||||
static const u16 gamma_table_3_0[] = {
|
||||
/* gamma = 3.0 */
|
||||
0, 0, 0, 0, 0, 0, 1, 1,
|
||||
2, 3, 4, 5, 7, 9, 11, 13,
|
||||
16, 19, 23, 27, 32, 37, 42, 48,
|
||||
55, 62, 69, 78, 87, 96, 107, 118,
|
||||
130, 142, 155, 169, 184, 200, 217, 234,
|
||||
253, 272, 293, 314, 337, 360, 385, 410,
|
||||
437, 465, 494, 524, 556, 588, 622, 658,
|
||||
694, 732, 771, 812, 854, 897, 942, 988,
|
||||
1036, 1085, 1136, 1189, 1243, 1298, 1356, 1415,
|
||||
1475, 1538, 1602, 1667, 1735, 1804, 1876, 1949,
|
||||
2024, 2100, 2179, 2260, 2343, 2427, 2514, 2603,
|
||||
2693, 2786, 2881, 2978, 3078, 3179, 3283, 3389,
|
||||
3497, 3607, 3720, 3835, 3952, 4072, 4194, 4319,
|
||||
4446, 4575, 4707, 4842, 4979, 5118, 5261, 5405,
|
||||
5553, 5703, 5856, 6011, 6169, 6330, 6494, 6660,
|
||||
6830, 7002, 7177, 7355, 7536, 7719, 7906, 8096,
|
||||
8289, 8484, 8683, 8885, 9090, 9298, 9510, 9724,
|
||||
9942, 10163, 10387, 10614, 10845, 11079, 11317, 11557,
|
||||
11802, 12049, 12300, 12555, 12813, 13074, 13339, 13608,
|
||||
13880, 14156, 14435, 14718, 15005, 15295, 15589, 15887,
|
||||
16189, 16494, 16803, 17117, 17433, 17754, 18079, 18408,
|
||||
18740, 19077, 19418, 19762, 20111, 20464, 20821, 21182,
|
||||
21547, 21917, 22290, 22668, 23050, 23436, 23827, 24222,
|
||||
24621, 25025, 25433, 25845, 26262, 26683, 27109, 27539,
|
||||
27974, 28413, 28857, 29306, 29759, 30217, 30680, 31147,
|
||||
31619, 32095, 32577, 33063, 33554, 34050, 34551, 35056,
|
||||
35567, 36082, 36602, 37128, 37658, 38194, 38734, 39280,
|
||||
39830, 40386, 40947, 41513, 42084, 42661, 43243, 43830,
|
||||
44422, 45019, 45622, 46231, 46844, 47463, 48088, 48718,
|
||||
49353, 49994, 50641, 51293, 51950, 52614, 53282, 53957,
|
||||
54637, 55323, 56014, 56712, 57415, 58123, 58838, 59558,
|
||||
60285, 61017, 61755, 62499, 63249, 64005, 64767, 65535,
|
||||
};
|
||||
#endif
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable TIM3 clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN);
|
||||
|
||||
/* Enable GPIOC, Alternate Function clocks. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR,
|
||||
RCC_APB2ENR_IOPAEN |
|
||||
RCC_APB2ENR_IOPBEN |
|
||||
RCC_APB2ENR_AFIOEN);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/*
|
||||
* Set GPIO6 and 7 (in GPIO port A) to
|
||||
* 'output alternate function push-pull'.
|
||||
*/
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
||||
GPIO_TIM3_CH1 |
|
||||
GPIO_TIM3_CH2);
|
||||
|
||||
/*
|
||||
* Set GPIO0 and 1 (in GPIO port B) to
|
||||
* 'output alternate function push-pull'.
|
||||
*/
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
|
||||
GPIO_TIM3_CH3 |
|
||||
GPIO_TIM3_CH4);
|
||||
|
||||
}
|
||||
void tim_setup(void)
|
||||
{
|
||||
/* Clock division and mode */
|
||||
TIM3_CR1 = TIM_CR1_CKD_CK_INT | TIM_CR1_CMS_EDGE;
|
||||
/* Period */
|
||||
TIM3_ARR = 65535;
|
||||
/* Prescaler */
|
||||
TIM3_PSC = 0;
|
||||
TIM3_EGR = TIM_EGR_UG;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 1 mode and preload */
|
||||
TIM3_CCMR1 |= TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC1PE;
|
||||
|
||||
/* Polarity and state */
|
||||
TIM3_CCER |= TIM_CCER_CC1P | TIM_CCER_CC1E;
|
||||
//TIM3_CCER |= TIM_CCER_CC1E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM3_CCR1 = 0;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 2 mode and preload */
|
||||
TIM3_CCMR1 |= TIM_CCMR1_OC2M_PWM1 | TIM_CCMR1_OC2PE;
|
||||
|
||||
/* Polarity and state */
|
||||
TIM3_CCER |= TIM_CCER_CC2P | TIM_CCER_CC2E;
|
||||
//TIM3_CCER |= TIM_CCER_CC2E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM3_CCR2 = 0;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 3 mode and preload */
|
||||
TIM3_CCMR2 |= TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE;
|
||||
|
||||
/* Polarity and state */
|
||||
TIM3_CCER |= TIM_CCER_CC3P | TIM_CCER_CC3E;
|
||||
//TIM3_CCER |= TIM_CCER_CC3E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM3_CCR3 = 0;
|
||||
|
||||
/* ---- */
|
||||
/* Output compare 4 mode and preload */
|
||||
TIM3_CCMR2 |= TIM_CCMR2_OC4M_PWM1 | TIM_CCMR2_OC4PE;
|
||||
|
||||
/* Polarity and state */
|
||||
TIM3_CCER |= TIM_CCER_CC4P | TIM_CCER_CC4E;
|
||||
//TIM3_CCER |= TIM_CCER_CC4E;
|
||||
|
||||
/* Capture compare value */
|
||||
TIM3_CCR4 = 0;
|
||||
|
||||
/* ---- */
|
||||
/* ARR reload enable */
|
||||
TIM3_CR1 |= TIM_CR1_ARPE;
|
||||
|
||||
/* Counter enable */
|
||||
TIM3_CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j0, j1, j2, j3, d0, d1, d2, d3, j, k, kd;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
tim_setup();
|
||||
|
||||
#ifdef COMPARE
|
||||
j0 = 0;
|
||||
d0 = 1;
|
||||
j1 = 0;
|
||||
d1 = 1;
|
||||
j2 = 0;
|
||||
d2 = 1;
|
||||
j3 = 0;
|
||||
d3 = 1;
|
||||
while (1) {
|
||||
TIM3_CCR1 = gamma_table_linear[j0];
|
||||
j0 += d0;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 0)
|
||||
d0 = 1;
|
||||
TIM3_CCR2 = gamma_table_1_3[j1];
|
||||
j1 += d1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 0)
|
||||
d1 = 1;
|
||||
TIM3_CCR3 = gamma_table_2_5[j2];
|
||||
j2 += d2;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 0)
|
||||
d2 = 1;
|
||||
TIM3_CCR4= gamma_table_3_0[j3];
|
||||
j3 += d3;
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 0)
|
||||
d3 = 1;
|
||||
for (i = 0; i < 50000; i++);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MOVING_FADE
|
||||
j0 = 0;
|
||||
d0 = 1;
|
||||
j1 = 128;
|
||||
d1 = 1;
|
||||
j2 = 255;
|
||||
d2 = -1;
|
||||
j3 = 128;
|
||||
d3 = -1;
|
||||
while (1) {
|
||||
TIM3_CCR1 = GAMMA_TABLE[j0];
|
||||
j0 += d0;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 0)
|
||||
d0 = 1;
|
||||
TIM3_CCR2 = GAMMA_TABLE[j1];
|
||||
j1 += d1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 0)
|
||||
d1 = 1;
|
||||
TIM3_CCR3 = GAMMA_TABLE[j2];
|
||||
j2 += d2;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 0)
|
||||
d2 = 1;
|
||||
TIM3_CCR4 = GAMMA_TABLE[j3];
|
||||
j3 += d3;
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 0)
|
||||
d3 = 1;
|
||||
for (i = 0; i < 10000; i++);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KITT
|
||||
j0 = 255;
|
||||
d0 = -1;
|
||||
j1 = 20;
|
||||
d1 = -1;
|
||||
j2 = 20;
|
||||
d2 = -1;
|
||||
j3 = 20;
|
||||
d3 = -1;
|
||||
j = 0;
|
||||
k = 0;
|
||||
kd = 1;
|
||||
while (1) {
|
||||
TIM3_CCR1 = GAMMA_TABLE[j0];
|
||||
j0 += d0;
|
||||
if (j0 == 255)
|
||||
d0 =- 1;
|
||||
if (j0 == 19)
|
||||
j0 = 20;
|
||||
TIM3_CCR2 = GAMMA_TABLE[j1];
|
||||
j1 += d1;
|
||||
if (j1 == 255)
|
||||
d1 =- 1;
|
||||
if (j1 == 19)
|
||||
j1 = 20;
|
||||
TIM3_CCR3 = GAMMA_TABLE[j2];
|
||||
j2 += d2;
|
||||
if (j2 == 255)
|
||||
d2 =- 1;
|
||||
if (j2 == 19)
|
||||
j2 = 20;
|
||||
TIM3_CCR4 = GAMMA_TABLE[j3];
|
||||
j3 += d3;
|
||||
if (j3 == 255)
|
||||
d3 =- 1;
|
||||
if (j3 == 19)
|
||||
j3 = 20;
|
||||
for (i = 0; i < 15000; i++)
|
||||
__asm__("nop");
|
||||
j++;
|
||||
if (j == 100) {
|
||||
j = 0;
|
||||
switch (k += kd) {
|
||||
case 0:
|
||||
j0 = 255;
|
||||
break;
|
||||
case 1:
|
||||
j1 = 255;
|
||||
break;
|
||||
case 2:
|
||||
j2 = 255;
|
||||
break;
|
||||
case 3:
|
||||
j3 = 255;
|
||||
break;
|
||||
}
|
||||
if (k == 3)
|
||||
kd =- 1;
|
||||
if (k == 0)
|
||||
kd = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = systick
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
|
||||
u32 temp32;
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOA clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
gpio_set(GPIOA, GPIO6); /* LED0 off */
|
||||
gpio_set(GPIOA, GPIO7); /* LED1 off */
|
||||
gpio_set(GPIOB, GPIO0); /* LED2 off */
|
||||
gpio_set(GPIOB, GPIO1); /* LED3 off */
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port A) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO0);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
temp32++;
|
||||
|
||||
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
||||
if (temp32 == 1000) {
|
||||
gpio_toggle(GPIOA, GPIO6); /* LED2 on/off */
|
||||
temp32 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
|
||||
gpio_clear(GPIOA, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOA, GPIO6); /* LED2 off */
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
/* 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();
|
||||
|
||||
while (1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103CBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable clocks for GPIO port B (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO6 (in GPIO port A) to 'output push-pull' for LED use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_USART1_REMAP;
|
||||
|
||||
/* Setup GPIO pin GPIO_USART3_TX/GPIO10 on GPIO port B for transmit. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART1, 230400);
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO12 (in GPIO port C) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j = 0, c = 0;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/* Blink the LED (PC12) on the board with every transmitted byte. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOA, GPIO6); /* LED on/off */
|
||||
usart_send_blocking(USART1, c + '0'); /* Send a byte. */
|
||||
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
||||
if ((j++ % 80) == 0) { /* Newline after line full. */
|
||||
usart_send_blocking(USART1, '\r');
|
||||
usart_send_blocking(USART1, '\n');
|
||||
}
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Open-BLDC (STM32F103CBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart_irq
|
||||
|
||||
OOCD_BOARD = open-bldc
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOA clock (for LED GPIOs). */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Enable clocks for GPIO port B (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Enable the USART1 interrupt. */
|
||||
nvic_enable_irq(NVIC_USART1_IRQ);
|
||||
|
||||
/* enable USART1 pin software remapping */
|
||||
AFIO_MAPR |= AFIO_MAPR_USART1_REMAP;
|
||||
|
||||
/* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_RE_TX);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port B for receive. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RE_RX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART1, 230400);
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
usart_set_mode(USART1, USART_MODE_TX_RX);
|
||||
|
||||
/* Enable USART1 Receive interrupt. */
|
||||
USART_CR1(USART1) |= USART_CR1_RXNEIE;
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
gpio_set(GPIOA, GPIO6 | GPIO7);
|
||||
|
||||
/* Setup GPIO6 and 7 (in GPIO port A) for led use. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6 | GPIO7);
|
||||
}
|
||||
|
||||
void usart1_isr(void)
|
||||
{
|
||||
static u8 data = 'A';
|
||||
|
||||
/* Check if we were called because of RXNE. */
|
||||
if (((USART_CR1(USART1) & USART_CR1_RXNEIE) != 0) &&
|
||||
((USART_SR(USART1) & USART_SR_RXNE) != 0)) {
|
||||
/* Indicate that we got data. */
|
||||
gpio_toggle(GPIOA, GPIO6);
|
||||
|
||||
/* Retrieve the data from the peripheral. */
|
||||
data = usart_recv(USART1);
|
||||
|
||||
/* Enable transmit interrupt so it sends back the data. */
|
||||
USART_CR1(USART1) |= USART_CR1_TXEIE;
|
||||
}
|
||||
|
||||
/* Check if we were called because of TXE. */
|
||||
if (((USART_CR1(USART1) & USART_CR1_TXEIE) != 0) &&
|
||||
((USART_SR(USART1) & USART_SR_TXE) != 0)) {
|
||||
/* Indicate that we are sending out data. */
|
||||
gpio_toggle(GPIOA, GPIO7);
|
||||
|
||||
/* Put data into the transmit register. */
|
||||
usart_send(USART1, data);
|
||||
|
||||
/* Disable the TXE interrupt as we don't need it anymore. */
|
||||
USART_CR1(USART1) &= ~USART_CR1_TXEIE;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/* Wait forever and do nothing. */
|
||||
while (1)
|
||||
__asm__("nop");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Open-BLDC (STM32F103CBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = adc
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program sends some characters on USART1.
|
||||
Afterwards it read out the internal temperature sensor of the STM32 and
|
||||
sends the value read out from the ADC to the USART1.
|
||||
|
||||
The terminal settings for the receiving device/PC are 115200 8n1.
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/adc.h>
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART1, 115200);
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX_RX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
}
|
||||
|
||||
void adc_setup(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
|
||||
|
||||
/* Make shure it doesn't run during config. */
|
||||
adc_off(ADC1);
|
||||
|
||||
/* We configure everything for one single conversion. */
|
||||
adc_disable_scan_mode(ADC1);
|
||||
adc_set_single_conversion_mode(ADC1);
|
||||
adc_enable_discontinous_mode_regular(ADC1);
|
||||
adc_disable_external_trigger_regular(ADC1);
|
||||
adc_set_right_aligned(ADC1);
|
||||
/* We want to read the temperature sensor, so we have to enable it. */
|
||||
adc_enable_temperature_sensor(ADC1);
|
||||
adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
|
||||
|
||||
adc_on(ADC1);
|
||||
|
||||
/* Wait for ADC starting up. */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
|
||||
adc_reset_calibration(ADC1);
|
||||
adc_calibration(ADC1);
|
||||
}
|
||||
|
||||
void my_usart_print_int(u32 usart, int value)
|
||||
{
|
||||
s8 i;
|
||||
u8 nr_digits = 0;
|
||||
char buffer[25];
|
||||
|
||||
if (value < 0) {
|
||||
usart_send(usart, '-');
|
||||
value = value * -1;
|
||||
}
|
||||
|
||||
while (value > 0) {
|
||||
buffer[nr_digits++] = "0123456789"[value % 10];
|
||||
value /= 10;
|
||||
}
|
||||
|
||||
for (i = nr_digits; i >= 0; i--)
|
||||
usart_send(usart, buffer[i]);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
u8 channel_array[16];
|
||||
u16 temperature;
|
||||
|
||||
rcc_clock_setup_in_hse_16mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
adc_setup();
|
||||
|
||||
gpio_clear(GPIOB, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOB, GPIO6); /* LED2 off */
|
||||
|
||||
/* Send a message on USART1. */
|
||||
usart_send(USART1, 's');
|
||||
usart_send(USART1, 't');
|
||||
usart_send(USART1, 'm');
|
||||
usart_send(USART1, '\r');
|
||||
usart_send(USART1, '\n');
|
||||
|
||||
/* Select the channel we want to convert. 16=temperature_sensor. */
|
||||
channel_array[0] = 16;
|
||||
adc_set_regular_sequence(ADC1, 1, channel_array);
|
||||
|
||||
/*
|
||||
* If the ADC_CR2_ON bit is already set -> setting it another time
|
||||
* starts the conversion.
|
||||
*/
|
||||
adc_on(ADC1);
|
||||
|
||||
/* Wait for end of conversion. */
|
||||
while (!(ADC_SR(ADC1) & ADC_SR_EOC));
|
||||
|
||||
temperature = ADC_DR(ADC1);
|
||||
|
||||
/*
|
||||
* That's actually not the real temperature - you have to compute it
|
||||
* as described in the datasheet.
|
||||
*/
|
||||
my_usart_print_int(USART1, temperature);
|
||||
|
||||
gpio_clear(GPIOB, GPIO6); /* LED2 on */
|
||||
|
||||
while(1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = dma
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This program demonstrates a little DMA MEM2MEM transfer. A string is send out
|
||||
to USART1 and afterwards copied by DMA to another memory location. To check
|
||||
if the transfer was successful we send the destination string also out to
|
||||
USART1.
|
||||
|
||||
The terminal settings for the receiving device/PC are 115200 8n1.
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/dma.h>
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART1, 115200);
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX_RX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
}
|
||||
|
||||
void my_usart_print_string(u32 usart, char * s)
|
||||
{
|
||||
while (*s != 0) {
|
||||
usart_send(usart, *s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Exactly 20 bytes including '0' at the end.
|
||||
We want to transfer 32bit * 5 so it should fit */
|
||||
char s1[20] = "Hello STM MEM2MEM\r\n";
|
||||
char s2[20];
|
||||
|
||||
rcc_clock_setup_in_hse_16mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
gpio_clear(GPIOB, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOB, GPIO6); /* LED2 off */
|
||||
|
||||
my_usart_print_string(USART1, "s1 ");
|
||||
my_usart_print_string(USART1, s1);
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_DMA1EN);
|
||||
|
||||
/* MEM2MEM mode for channel 1. */
|
||||
dma_enable_mem2mem_mode(DMA1, DMA_CHANNEL1);
|
||||
|
||||
/* Highest priority. */
|
||||
dma_set_priority(DMA1, DMA_CHANNEL1, DMA_CCR1_PL_VERY_HIGH);
|
||||
|
||||
/* 32Bit wide transfer for source and destination. */
|
||||
dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR1_MSIZE_32BIT);
|
||||
dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR1_PSIZE_32BIT);
|
||||
|
||||
/* After each 32Bit we have to increase the addres because we use RAM. */
|
||||
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1);
|
||||
dma_enable_peripheral_increment_mode(DMA1, DMA_CHANNEL1);
|
||||
|
||||
/* We define the source as peripheral. */
|
||||
dma_set_read_from_peripheral(DMA1, DMA_CHANNEL1);
|
||||
|
||||
/* We want to transfer string s1. */
|
||||
dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (u32) &s1);
|
||||
|
||||
/* Destination should be string s2. */
|
||||
dma_set_memory_address(DMA1, DMA_CHANNEL1, (u32) &s2);
|
||||
|
||||
/* Set number of DATA to transfer.
|
||||
Remember that this means not necessary bytes but MSIZE or PSIZE
|
||||
depending from your source device. */
|
||||
dma_set_number_of_data(DMA1, DMA_CHANNEL1, 5);
|
||||
|
||||
/* Start DMA transfer. */
|
||||
dma_enable_channel(DMA1, DMA_CHANNEL1);
|
||||
|
||||
/* TODO: write a function to get the interrupt flags. */
|
||||
while(!(DMA_ISR(DMA1) & 0x0000001))
|
||||
{
|
||||
}
|
||||
|
||||
dma_disable_channel(DMA1, DMA_CHANNEL1);
|
||||
|
||||
/* String s1 should now already be transferred to s2. */
|
||||
my_usart_print_string(USART1, "s2 ");
|
||||
my_usart_print_string(USART1, s2);
|
||||
|
||||
gpio_clear(GPIOB, GPIO6); /* LED2 on */
|
||||
while(1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = main
|
||||
|
||||
OBJS = dogm128.o
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program writes some text on an DOGM128 LCD display connected
|
||||
to SPI2.
|
||||
|
||||
@@ -1,291 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "./dogm128.h"
|
||||
|
||||
u8 dogm128_ram[1024];
|
||||
u8 dogm128_cursor_x;
|
||||
u8 dogm128_cursor_y;
|
||||
|
||||
void dogm128_send_command(u8 command)
|
||||
{
|
||||
u32 counter;
|
||||
|
||||
gpio_clear(DOGM128_A0_PORT, DOGM128_A0_PIN); /* A0 low for commands */
|
||||
spi_send(DOGM128_SPI, command);
|
||||
|
||||
for (counter = 0; counter<=500; counter++) /* wait */
|
||||
{}
|
||||
}
|
||||
|
||||
void dogm128_send_data(u8 data)
|
||||
{
|
||||
u32 counter;
|
||||
|
||||
gpio_set(DOGM128_A0_PORT, DOGM128_A0_PIN); /* A0 high for data */
|
||||
spi_send(DOGM128_SPI, data);
|
||||
|
||||
for (counter = 0; counter<=500; counter++) /* wait */
|
||||
{}
|
||||
}
|
||||
|
||||
void dogm128_init()
|
||||
{
|
||||
u32 counter;
|
||||
|
||||
/* reset the display */
|
||||
gpio_clear(DOGM128_RESET_PORT, DOGM128_RESET_PIN); /* reset low for dogm128 */
|
||||
for (counter = 0; counter<=60000; counter++) /* wait */
|
||||
{}
|
||||
gpio_set(DOGM128_RESET_PORT, DOGM128_RESET_PIN); /* reset high for dogm128 */
|
||||
|
||||
for (counter = 0; counter<=60000; counter++) /* wait */
|
||||
{}
|
||||
|
||||
gpio_clear(DOGM128_A0_PORT, DOGM128_A0_PIN); /* A0 low for init */
|
||||
|
||||
/* tell the display that we want to start */
|
||||
spi_set_nss_low(DOGM128_SPI);
|
||||
|
||||
/* init sequence */
|
||||
dogm128_send_command(DOGM128_DISPLAY_START_ADDRESS_BASE + 0);
|
||||
dogm128_send_command(DOGM128_ADC_REVERSE);
|
||||
dogm128_send_command(DOGM128_COM_OUTPUT_SCAN_NORMAL);
|
||||
dogm128_send_command(DOGM128_DISPLAY_NORMAL);
|
||||
dogm128_send_command(DOGM128_BIAS_19);
|
||||
dogm128_send_command(DOGM128_POWER_CONTROL_BASE + 0x07);
|
||||
dogm128_send_command(DOGM128_BOOSTER_RATIO_SET);
|
||||
dogm128_send_command(0x00); /* Booster x4 */
|
||||
dogm128_send_command(DOGM128_V0_OUTPUT_RESISTOR_BASE + 0x07);
|
||||
dogm128_send_command(DOGM128_ELECTRONIC_VOLUME_MODE_SET);
|
||||
dogm128_send_command(0x16); /* Contrast */
|
||||
dogm128_send_command(DOGM128_STATIC_INDICATOR_OFF);
|
||||
dogm128_send_command(0x00); /* Flashing OFF */
|
||||
dogm128_send_command(DOGM128_DISPLAY_ON);
|
||||
|
||||
/* end transfer */
|
||||
spi_set_nss_high(DOGM128_SPI);
|
||||
}
|
||||
|
||||
void dogm128_print_char(u8 data)
|
||||
{
|
||||
u8 i;
|
||||
u8 page;
|
||||
u8 shift;
|
||||
u8 xcoord;
|
||||
u8 ycoord;
|
||||
|
||||
xcoord = dogm128_cursor_x;
|
||||
ycoord = dogm128_cursor_y;
|
||||
|
||||
page = (63 - ycoord) / 8; /* the display consists of 8 lines a 8 dots each. */
|
||||
shift = (7 -((63 - ycoord) % 8)); /* vertical shift */
|
||||
|
||||
/* font is 8x5 so iterate each column of the character */
|
||||
for (i = 0; i <= 5; i++) {
|
||||
/* right border reached? */
|
||||
if ((xcoord + i) > 127)
|
||||
return;
|
||||
dogm128_cursor_x++;
|
||||
|
||||
/* 0xAA = end of character - no dots in this line */
|
||||
if (dogm128_font[data - 0x20][i] == 0xAA) {
|
||||
dogm128_ram[(page * 128) + xcoord + i] &= ~(0xFF >> shift); /* clear area */
|
||||
if ((shift > 0) && (page > 0))
|
||||
dogm128_ram[((page - 1) * 128) + xcoord + i] &= ~(0xFF << (8 - shift)); /* clear area */
|
||||
return;
|
||||
}
|
||||
|
||||
/* lower part */
|
||||
dogm128_ram[(page * 128) + xcoord + i] &= ~(0xFF >> shift); /* clear area */
|
||||
dogm128_ram[(page * 128) + xcoord + i] = (dogm128_font[data - 0x20][i] >> shift);
|
||||
/* higher part if needed */
|
||||
if ((shift > 0) && (page > 0)) {
|
||||
dogm128_ram[((page - 1) * 128) + xcoord + i] &= ~(0xFF << (8 - shift)); /* clear area */
|
||||
dogm128_ram[((page - 1) * 128) + xcoord + i] = (dogm128_font[data - 0x20][i] << (8 - shift));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dogm128_set_cursor(u8 xcoord, u8 ycoord)
|
||||
{
|
||||
dogm128_cursor_x = xcoord;
|
||||
dogm128_cursor_y = ycoord;
|
||||
}
|
||||
|
||||
void dogm128_print_string(char * s)
|
||||
{
|
||||
while (*s != 0) {
|
||||
dogm128_print_char(*s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
void dogm128_set_dot(u8 xcoord, u8 ycoord)
|
||||
{
|
||||
dogm128_ram[(((63 - ycoord) / 8) * 128) + xcoord] |= (1 << ((63 - ycoord) % 8));
|
||||
}
|
||||
|
||||
void dogm128_clear_dot(u8 xcoord, u8 ycoord)
|
||||
{
|
||||
dogm128_ram[(((63 - ycoord) / 8) * 128) + xcoord] &= ~(1 << ((63 - ycoord) % 8));
|
||||
}
|
||||
|
||||
void dogm128_update_display()
|
||||
{
|
||||
u8 page;
|
||||
u8 column;
|
||||
|
||||
/* tell the display that we want to start */
|
||||
spi_set_nss_low(DOGM128_SPI);
|
||||
|
||||
for (page = 0; page <= 7; page++) {
|
||||
dogm128_send_command(0xB0 + page); /* set page */
|
||||
dogm128_send_command(0x10); /* set column upper address to 0 */
|
||||
dogm128_send_command(0x00); /* set column lower address to 0 */
|
||||
|
||||
for (column = 0; column <= 127; column++) {
|
||||
dogm128_send_data(dogm128_ram[(page * 128) + column]);
|
||||
}
|
||||
}
|
||||
|
||||
spi_set_nss_high(DOGM128_SPI);
|
||||
}
|
||||
|
||||
void dogm128_clear()
|
||||
{
|
||||
u16 i;
|
||||
|
||||
for (i = 0; i<=1023; i++) {
|
||||
dogm128_ram[i] = 0;
|
||||
}
|
||||
dogm128_update_display();
|
||||
}
|
||||
|
||||
/* This is a non-monospace font definition (upside down for better handling).
|
||||
* 0xAA is the end of the character so its not space efficient in your memory, but on your display.
|
||||
* We are starting with " " as the first printable character at 0x20, so we have to substract 0x20 later.
|
||||
* Its the only defined to 127/0x7F so if you have german umlauts or other special characters from above
|
||||
* you have to expand this definition a little bit. */
|
||||
|
||||
const u8 dogm128_font[96][6] = {
|
||||
|
||||
/* 20 SPACE */ {0x00, 0x00, 0x00, 0xAA, 0xAA, 0xAA},
|
||||
/* 21 ! */ {0x5E, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 22 " */ {0x66, 0x00, 0x66, 0xAA, 0xAA, 0xAA},
|
||||
/* 23 # */ {0x28, 0x7C, 0x28, 0x7C, 0x28, 0xAA},
|
||||
/* 24 $ */ {0x24, 0x2A, 0x7F, 0x2A, 0x10, 0xAA},
|
||||
/* 25 % */ {0x62, 0x18, 0x46, 0xAA, 0xAA, 0xAA},
|
||||
/* 26 & */ {0x30, 0x4C, 0x5A, 0x24, 0x50, 0xAA},
|
||||
/* 27 ' */ {0x06, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 28 ( */ {0x3E, 0x41, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 29 ) */ {0x41, 0x3E, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 2A * */ {0x28, 0x10, 0x7C, 0x10, 0x28, 0xAA},
|
||||
/* 2B + */ {0x10, 0x38, 0x10, 0xAA, 0xAA, 0xAA},
|
||||
/* 2C , */ {0xC0, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 2D - */ {0x10, 0x10, 0x10, 0xAA, 0xAA, 0xAA},
|
||||
/* 2E . */ {0x40, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 2F / */ {0x60, 0x18, 0x06, 0xAA, 0xAA, 0xAA},
|
||||
|
||||
/* 30 0 */ {0x3C, 0x42, 0x42, 0x3C, 0xAA, 0xAA},
|
||||
/* 31 1 */ {0x44, 0x7E, 0x40, 0xAA, 0xAA, 0xAA},
|
||||
/* 32 2 */ {0x44, 0x62, 0x52, 0x4C, 0xAA, 0xAA},
|
||||
/* 33 3 */ {0x4A, 0x4A, 0x34, 0xAA, 0xAA, 0xAA},
|
||||
/* 34 4 */ {0x1E, 0x10, 0x78, 0x10, 0xAA, 0xAA},
|
||||
/* 35 5 */ {0x4E, 0x4A, 0x32, 0xAA, 0xAA, 0xAA},
|
||||
/* 36 6 */ {0x3C, 0x4A, 0x4A, 0x30, 0xAA, 0xAA},
|
||||
/* 37 7 */ {0x62, 0x12, 0x0E, 0xAA, 0xAA, 0xAA},
|
||||
/* 38 8 */ {0x34, 0x4A, 0x4A, 0x34, 0xAA, 0xAA},
|
||||
/* 39 9 */ {0x0C, 0x52, 0x52, 0x3C, 0xAA, 0xAA},
|
||||
/* 3A : */ {0x28, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 3B ; */ {0xC8, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 3C < */ {0x10, 0x28, 0x44, 0xAA, 0xAA, 0xAA},
|
||||
/* 3D = */ {0x28, 0x28, 0x28, 0xAA, 0xAA, 0xAA},
|
||||
/* 3E > */ {0x44, 0x28, 0x10, 0xAA, 0xAA, 0xAA},
|
||||
/* 3F ? */ {0x02, 0x52, 0x0C, 0xAA, 0xAA, 0xAA},
|
||||
|
||||
/* 40 @ */ {0x3C, 0x42, 0x12, 0x2A, 0x3C, 0xAA},
|
||||
/* 41 A */ {0x7C, 0x12, 0x12, 0x7C, 0xAA, 0xAA},
|
||||
/* 42 B */ {0x7E, 0x4A, 0x4A, 0x34, 0xAA, 0xAA},
|
||||
/* 43 C */ {0x3C, 0x42, 0x42, 0x24, 0xAA, 0xAA},
|
||||
/* 44 D */ {0x7E, 0x42, 0x42, 0x3C, 0xAA, 0xAA},
|
||||
/* 45 E */ {0x7E, 0x4A, 0x4A, 0xAA, 0xAA, 0xAA},
|
||||
/* 46 F */ {0x7E, 0x0A, 0x0A, 0xAA, 0xAA, 0xAA},
|
||||
/* 47 G */ {0x3C, 0x42, 0x52, 0x34, 0xAA, 0xAA},
|
||||
/* 48 H */ {0x7E, 0x08, 0x08, 0x7E, 0xAA, 0xAA},
|
||||
/* 49 I */ {0x42, 0x7E, 0x42, 0xAA, 0xAA, 0xAA},
|
||||
/* 4A J */ {0x42, 0x42, 0x3E, 0xAA, 0xAA, 0xAA},
|
||||
/* 4B K */ {0x7E, 0x08, 0x14, 0x62, 0xAA, 0xAA},
|
||||
/* 4C L */ {0x7E, 0x40, 0x40, 0xAA, 0xAA, 0xAA},
|
||||
/* 4D M */ {0x7E, 0x04, 0x08, 0x04, 0x7E, 0xAA},
|
||||
/* 4E N */ {0x7E, 0x04, 0x18, 0x20, 0x7E, 0xAA},
|
||||
/* 4F O */ {0x3C, 0x42, 0x42, 0x3C, 0xAA, 0xAA},
|
||||
|
||||
/* 50 P */ {0x7E, 0x12, 0x12, 0x0C, 0xAA, 0xAA},
|
||||
/* 51 Q */ {0x3C, 0x42, 0x42, 0xBC, 0xAA, 0xAA},
|
||||
/* 52 R */ {0x7E, 0x12, 0x12, 0x6C, 0xAA, 0xAA},
|
||||
/* 53 S */ {0x44, 0x4A, 0x4A, 0x30, 0xAA, 0xAA},
|
||||
/* 54 T */ {0x02, 0x7E, 0x02, 0xAA, 0xAA, 0xAA},
|
||||
/* 55 U */ {0x3E, 0x40, 0x40, 0x3E, 0xAA, 0xAA},
|
||||
/* 56 V */ {0x06, 0x18, 0x60, 0x18, 0x06, 0xAA},
|
||||
/* 57 W */ {0x3E, 0x40, 0x3E, 0x40, 0x3E, 0xAA},
|
||||
/* 58 X */ {0x42, 0x24, 0x18, 0x24, 0x42, 0xAA},
|
||||
/* 59 Y */ {0x9E, 0xA0, 0xA0, 0x7E, 0xAA, 0xAA},
|
||||
/* 5A Z */ {0x62, 0x52, 0x4A, 0x46, 0xAA, 0xAA},
|
||||
/* 5B [ */ {0x7E, 0x42, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 5C \ */ {0x06, 0x18, 0x60, 0xAA, 0xAA, 0xAA},
|
||||
/* 5D ] */ {0x42, 0x7E, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 5E ^ */ {0x04, 0x02, 0x04, 0xAA, 0xAA, 0xAA},
|
||||
/* 5F _ */ {0x40, 0x40, 0x40, 0xAA, 0xAA, 0xAA},
|
||||
|
||||
/* 60 ` */ {0x02, 0x04, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 61 a */ {0x20, 0x54, 0x54, 0x78, 0xAA, 0xAA},
|
||||
/* 62 b */ {0x7E, 0x44, 0x44, 0x38, 0xAA, 0xAA},
|
||||
/* 63 c */ {0x38, 0x44, 0x44, 0x28, 0xAA, 0xAA},
|
||||
/* 64 d */ {0x38, 0x44, 0x44, 0x7E, 0xAA, 0xAA},
|
||||
/* 65 e */ {0x38, 0x54, 0x54, 0x58, 0xAA, 0xAA},
|
||||
/* 66 f */ {0x7C, 0x0A, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 67 g */ {0x98, 0xA4, 0xA4, 0x7C, 0xAA, 0xAA},
|
||||
/* 68 h */ {0x7E, 0x04, 0x04, 0x78, 0xAA, 0xAA},
|
||||
/* 69 i */ {0x7A, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 6A j */ {0x40, 0x3A, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 6B k */ {0x7E, 0x10, 0x28, 0x44, 0xAA, 0xAA},
|
||||
/* 6C l */ {0x7E, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 6D m */ {0x7C, 0x04, 0x78, 0x04, 0x78, 0xAA},
|
||||
/* 6E n */ {0x7C, 0x04, 0x04, 0x78, 0xAA, 0xAA},
|
||||
/* 6F o */ {0x38, 0x44, 0x44, 0x38, 0xAA, 0xAA},
|
||||
|
||||
/* 70 p */ {0xFC, 0x24, 0x24, 0x18, 0xAA, 0xAA},
|
||||
/* 71 q */ {0x18, 0x24, 0x24, 0xFC, 0xAA, 0xAA},
|
||||
/* 72 r */ {0x78, 0x04, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 73 s */ {0x48, 0x54, 0x54, 0x20, 0xAA, 0xAA},
|
||||
/* 74 t */ {0x04, 0x3E, 0x44, 0xAA, 0xAA, 0xAA},
|
||||
/* 75 u */ {0x3C, 0x40, 0x40, 0x3C, 0xAA, 0xAA},
|
||||
/* 76 v */ {0x0C, 0x30, 0x40, 0x30, 0x0C, 0xAA},
|
||||
/* 77 w */ {0x3C, 0x40, 0x3C, 0x40, 0x3C, 0xAA},
|
||||
/* 78 x */ {0x44, 0x28, 0x10, 0x28, 0x44, 0xAA},
|
||||
/* 79 y */ {0x1C, 0xA0, 0xA0, 0x7C, 0xAA, 0xAA},
|
||||
/* 7A z */ {0x64, 0x54, 0x4C, 0xAA, 0xAA, 0xAA},
|
||||
/* 7B { */ {0x08, 0x36, 0x41, 0xAA, 0xAA, 0xAA},
|
||||
/* 7C | */ {0x7E, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA},
|
||||
/* 7D } */ {0x41, 0x36, 0x08, 0xAA, 0xAA, 0xAA},
|
||||
/* 7E ~ */ {0x20, 0x10, 0x20, 0x10, 0xAA, 0xAA},
|
||||
/* 7F DEL */ {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}
|
||||
};
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 DOGM128_H
|
||||
#define DOGM128_H
|
||||
|
||||
#include <libopencm3/cm3/common.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
|
||||
/* PB10 GPIO - ~RESET
|
||||
* PB12 SPI2_NSS - ~CS1
|
||||
* PB13 SPI2_SCK - SCL
|
||||
* PB14 SPI2_MISO - A0
|
||||
* PB15 SPI2_MOSI - SI */
|
||||
|
||||
#define DOGM128_SPI SPI2
|
||||
#define DOGM128_RESET_PIN GPIO10
|
||||
#define DOGM128_RESET_PORT GPIOB
|
||||
#define DOGM128_A0_PIN GPIO14
|
||||
#define DOGM128_A0_PORT GPIOB
|
||||
|
||||
/* DOGM128 display commands */
|
||||
#define DOGM128_PAGE_BASE 0xB0
|
||||
#define DOGM128_PAGE0 0xB0
|
||||
#define DOGM128_PAGE1 0xB1
|
||||
#define DOGM128_PAGE2 0xB2
|
||||
#define DOGM128_PAGE3 0xB3
|
||||
#define DOGM128_PAGE4 0xB4
|
||||
#define DOGM128_PAGE5 0xB5
|
||||
#define DOGM128_PAGE6 0xB6
|
||||
#define DOGM128_PAGE7 0xB7
|
||||
#define DOGM128_DISPLAY_ON 0xAF
|
||||
#define DOGM128_DISPLAY_OFF 0xAE
|
||||
#define DOGM128_DISPLAY_START_ADDRESS_BASE 0x40
|
||||
#define DOGM128_ADC_NORMAL 0xA0
|
||||
#define DOGM128_ADC_REVERSE 0xA1
|
||||
#define DOGM128_DISPLAY_NORMAL 0xA6
|
||||
#define DOGM128_DISPLAY_REVERSE 0xA7
|
||||
#define DOGM128_ALL_POINTS_ON 0xA5
|
||||
#define DOGM128_ALL_POINTS_OFF 0xA4
|
||||
#define DOGM128_BIAS_19 0xA2
|
||||
#define DOGM128_BIAS_17 0xA3
|
||||
#define DOGM128_INTERNAL_RESET 0xE2
|
||||
#define DOGM128_COM_OUTPUT_SCAN_NORMAL 0xC0
|
||||
#define DOGM128_COM_OUTPUT_SCAN_REVERSE 0xC8
|
||||
#define DOGM128_POWER_CONTROL_BASE 0x28
|
||||
#define DOGM128_V0_OUTPUT_RESISTOR_BASE 0x20
|
||||
#define DOGM128_ELECTRONIC_VOLUME_MODE_SET 0x81
|
||||
#define DOGM128_STATIC_INDICATOR_OFF 0xAC
|
||||
#define DOGM128_STATIC_INDICATOR_ON 0xAD
|
||||
#define DOGM128_BOOSTER_RATIO_SET 0xF8
|
||||
|
||||
extern const u8 dogm128_font[96][6];
|
||||
extern u8 dogm128_ram[1024];
|
||||
extern u8 dogm128_cursor_x;
|
||||
extern u8 dogm128_cursor_y;
|
||||
|
||||
void dogm128_send_command(u8 command);
|
||||
void dogm128_set_cursor(u8 xcoord, u8 ycoord);
|
||||
void dogm128_print_char(u8 data);
|
||||
void dogm128_print_string(char * s);
|
||||
void dogm128_set_dot(u8 xcoord, u8 ycoord);
|
||||
void dogm128_clear_dot(u8 xcoord, u8 ycoord);
|
||||
void dogm128_send_data(u8 data);
|
||||
void dogm128_init();
|
||||
void dogm128_update_display();
|
||||
void dogm128_clear();
|
||||
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
#include "./dogm128.h"
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
|
||||
/* A0 of DOGM128 */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO14);
|
||||
/*reset of DOGM128 */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
|
||||
|
||||
/* DOGM128/SPI2 clock and MOSI and NSS(CS1) */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO12);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO13);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO15);
|
||||
}
|
||||
|
||||
void spi_setup()
|
||||
{
|
||||
/* the DOGM128 display is connected to SPI2, so initialise it correctly */
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_SPI2EN);
|
||||
|
||||
spi_set_unidirectional_mode(DOGM128_SPI); /* we want to send only */
|
||||
spi_disable_crc(DOGM128_SPI); /* no CRC for this slave */
|
||||
spi_set_dff_8bit(DOGM128_SPI); /* 8-bit dataword-length */
|
||||
spi_set_full_duplex_mode(DOGM128_SPI); /* not receive-only */
|
||||
spi_enable_software_slave_management(DOGM128_SPI); /* we want to handle the CS signal in software */
|
||||
spi_set_nss_high(DOGM128_SPI);
|
||||
spi_set_baudrate_prescaler(DOGM128_SPI, SPI_CR1_BR_FPCLK_DIV_256); /* PCLOCK/256 as clock */
|
||||
spi_set_master_mode(DOGM128_SPI); /* we want to control everything and generate the clock -> master */
|
||||
spi_set_clock_polarity_1(DOGM128_SPI); /* sck idle state high */
|
||||
spi_set_clock_phase_1(DOGM128_SPI); /* bit is taken on the second (rising edge) of sck */
|
||||
spi_enable_ss_output(DOGM128_SPI);
|
||||
spi_enable(DOGM128_SPI);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_16mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
spi_setup();
|
||||
|
||||
gpio_clear(GPIOB, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOB, GPIO6); /* LED2 off */
|
||||
|
||||
dogm128_init();
|
||||
dogm128_clear();
|
||||
|
||||
dogm128_set_cursor(0, 56);
|
||||
dogm128_print_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
dogm128_set_cursor(0, 48);
|
||||
dogm128_print_string("abcdefghijklmnopqrstuvwxyz");
|
||||
dogm128_set_cursor(0, 40);
|
||||
dogm128_print_string(" !#$%&'()*+,-./0123456789");
|
||||
dogm128_set_cursor(0, 32);
|
||||
dogm128_print_string(":;<=>?@[\\]^_`{|}~");
|
||||
|
||||
dogm128_set_dot(10, 10);
|
||||
dogm128_set_dot(20, 10);
|
||||
dogm128_set_dot(30, 10);
|
||||
dogm128_set_dot(40, 10);
|
||||
dogm128_set_dot(50, 10);
|
||||
|
||||
dogm128_update_display();
|
||||
|
||||
gpio_set(GPIOB, GPIO7); /* LED1 off */
|
||||
while(1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = i2c_stts75_sensor
|
||||
|
||||
OBJS = stts75.o
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program sends some characters on USART1.
|
||||
Afterwards it connects to an STTS75 sensor (ST LM75 compatible)
|
||||
at adress A0/1/2=0 and sets reverse polarity, 26 degree Tos and Thyst.
|
||||
|
||||
It reads out the temperature and submits the temperature over USART1 in
|
||||
binary format (ASCII 0/1).
|
||||
|
||||
The terminal settings for the receiving device/PC are 115200 8n1.
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/i2c.h>
|
||||
#include "stts75.h"
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART1, 115200);
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX_RX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
}
|
||||
|
||||
void i2c_setup(void)
|
||||
{
|
||||
/* Enable clocks for I2C2 and AFIO. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_I2C2EN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
/* Set alternate functions for the SCL and SDA pins of I2C2. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,
|
||||
GPIO_I2C2_SCL | GPIO_I2C2_SDA);
|
||||
|
||||
/* Disable the I2C before changing any configuration. */
|
||||
i2c_peripheral_disable(I2C2);
|
||||
|
||||
/* APB1 is running at 36MHz. */
|
||||
i2c_set_clock_frequency(I2C2, I2C_CR2_FREQ_36MHZ);
|
||||
|
||||
/* 400KHz - I2C Fast Mode */
|
||||
i2c_set_fast_mode(I2C2);
|
||||
|
||||
/*
|
||||
* fclock for I2C is 36MHz APB2 -> cycle time 28ns, low time at 400KHz
|
||||
* incl trise -> Thigh= 1600ns; CCR= tlow/tcycle= 0x1C,9;
|
||||
* datasheet suggests 0x1e.
|
||||
*/
|
||||
i2c_set_ccr(I2C2, 0x1e);
|
||||
|
||||
/*
|
||||
* fclock for I2C is 36MHz -> cycle time 28ns, rise time for
|
||||
* 400KHz => 300ns and 100KHz => 1000ns; 300ns/28ns = 10;
|
||||
* incremented by 1 -> 11.
|
||||
*/
|
||||
i2c_set_trise(I2C2, 0x0b);
|
||||
|
||||
/*
|
||||
* This is our slave address - needed only if we want to receive from
|
||||
* other masters.
|
||||
*/
|
||||
i2c_set_own_7bit_slave_address(I2C2, 0x32);
|
||||
|
||||
/* If everything is configured -> enable the peripheral. */
|
||||
i2c_peripheral_enable(I2C2);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i = 0;
|
||||
u16 temperature;
|
||||
|
||||
rcc_clock_setup_in_hse_16mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
i2c_setup();
|
||||
|
||||
gpio_clear(GPIOB, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOB, GPIO6); /* LED2 off */
|
||||
|
||||
/* Send a message on USART1. */
|
||||
usart_send(USART1, 's');
|
||||
usart_send(USART1, 't');
|
||||
usart_send(USART1, 'm');
|
||||
usart_send(USART1, '\r');
|
||||
usart_send(USART1, '\n');
|
||||
|
||||
stts75_write_config(I2C2, STTS75_SENSOR0);
|
||||
stts75_write_temp_os(I2C2, STTS75_SENSOR0, 0x1a00); /* 26 degrees */
|
||||
stts75_write_temp_hyst(I2C2, STTS75_SENSOR0, 0x1a00);
|
||||
temperature = stts75_read_temperature(I2C2, STTS75_SENSOR0);
|
||||
|
||||
/* Send the temperature as binary over USART1. */
|
||||
for (i = 15; i >= 0 ; i--) {
|
||||
if (temperature & (1 << i))
|
||||
usart_send(USART1, '1');
|
||||
else
|
||||
usart_send(USART1, '0');
|
||||
}
|
||||
|
||||
usart_send(USART1, '\r');
|
||||
usart_send(USART1, '\n');
|
||||
|
||||
gpio_clear(GPIOB, GPIO6); /* LED2 on */
|
||||
|
||||
while(1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/i2c.h>
|
||||
#include "stts75.h"
|
||||
|
||||
void stts75_write_config(u32 i2c, u8 sensor)
|
||||
{
|
||||
u32 reg32;
|
||||
|
||||
/* Send START condition. */
|
||||
i2c_send_start(i2c);
|
||||
|
||||
/* Waiting for START is send and switched to master mode. */
|
||||
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
|
||||
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
|
||||
|
||||
/* Send destination address. */
|
||||
i2c_send_7bit_address(i2c, sensor, I2C_WRITE);
|
||||
|
||||
/* Waiting for address is transferred. */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_ADDR));
|
||||
|
||||
/* Cleaning ADDR condition sequence. */
|
||||
reg32 = I2C_SR2(i2c);
|
||||
|
||||
/* Sending the data. */
|
||||
i2c_send_data(i2c, 0x1); /* stts75 config register */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_BTF)); /* Await ByteTransferedFlag. */
|
||||
i2c_send_data(i2c, 0x4); /* pol reverse - LED glows if temp is below Tos/Thyst */
|
||||
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE)));
|
||||
|
||||
/* Send STOP condition. */
|
||||
i2c_send_stop(i2c);
|
||||
}
|
||||
|
||||
void stts75_write_temp_os(u32 i2c, u8 sensor, u16 temp_os)
|
||||
{
|
||||
u32 reg32;
|
||||
|
||||
/* Send START condition. */
|
||||
i2c_send_start(i2c);
|
||||
|
||||
/* Waiting for START is send and switched to master mode. */
|
||||
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
|
||||
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
|
||||
|
||||
/* Send destination address. */
|
||||
i2c_send_7bit_address(i2c, sensor, I2C_WRITE);
|
||||
|
||||
/* Waiting for address is transferred. */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_ADDR));
|
||||
|
||||
/* Cleaning ADDR condition sequence. */
|
||||
reg32 = I2C_SR2(i2c);
|
||||
|
||||
/* Sending the data. */
|
||||
i2c_send_data(i2c, 0x3); /* OvertemperatureShutdown register */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
|
||||
i2c_send_data(i2c, (u8)(temp_os >> 8)); /* MSB */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
|
||||
i2c_send_data(i2c, (u8)(temp_os & 0xff00)); /* LSB */
|
||||
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE))); /* After the last byte we have to wait for TxE too. */
|
||||
|
||||
/* Send STOP condition. */
|
||||
i2c_send_stop(i2c);
|
||||
}
|
||||
|
||||
void stts75_write_temp_hyst(u32 i2c, u8 sensor, u16 temp_hyst)
|
||||
{
|
||||
u32 reg32;
|
||||
|
||||
/* Send START condition. */
|
||||
i2c_send_start(i2c);
|
||||
|
||||
/* Waiting for START is send and therefore switched to master mode. */
|
||||
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
|
||||
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
|
||||
|
||||
/* Say to what address we want to talk to. */
|
||||
i2c_send_7bit_address(i2c, sensor, I2C_WRITE);
|
||||
|
||||
/* Waiting for address is transferred. */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_ADDR));
|
||||
|
||||
/* Cleaning ADDR condition sequence. */
|
||||
reg32 = I2C_SR2(i2c);
|
||||
|
||||
/* Sending the data. */
|
||||
i2c_send_data(i2c, 0x2); /* TemperatureHysteresis register */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
|
||||
i2c_send_data(i2c, (u8)(temp_hyst >> 8)); /* MSB */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
|
||||
i2c_send_data(i2c, (u8)(temp_hyst & 0xff00)); /* LSB */
|
||||
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF | I2C_SR1_TxE))); /* After the last byte we have to wait for TxE too. */
|
||||
|
||||
/* Send STOP condition. */
|
||||
i2c_send_stop(i2c);
|
||||
}
|
||||
|
||||
u16 stts75_read_temperature(u32 i2c, u8 sensor)
|
||||
{
|
||||
u32 reg32;
|
||||
u16 temperature;
|
||||
|
||||
/* Send START condition. */
|
||||
i2c_send_start(i2c);
|
||||
|
||||
/* Waiting for START is send and switched to master mode. */
|
||||
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
|
||||
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
|
||||
|
||||
/* Say to what address we want to talk to. */
|
||||
/* Yes, WRITE is correct - for selecting register in STTS75. */
|
||||
i2c_send_7bit_address(i2c, sensor, I2C_WRITE);
|
||||
|
||||
/* Waiting for address is transferred. */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_ADDR));
|
||||
|
||||
/* Cleaning ADDR condition sequence. */
|
||||
reg32 = I2C_SR2(i2c);
|
||||
|
||||
i2c_send_data(i2c, 0x0); /* temperature register */
|
||||
while (!(I2C_SR1(i2c) & (I2C_SR1_BTF|I2C_SR1_TxE)));
|
||||
|
||||
/*
|
||||
* Now we transferred that we want to ACCESS the temperature register.
|
||||
* Now we send another START condition (repeated START) and then
|
||||
* transfer the destination but with flag READ.
|
||||
*/
|
||||
|
||||
/* Send START condition. */
|
||||
i2c_send_start(i2c);
|
||||
|
||||
/* Waiting for START is send and switched to master mode. */
|
||||
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
|
||||
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
|
||||
|
||||
/* Say to what address we want to talk to. */
|
||||
i2c_send_7bit_address(i2c, sensor, I2C_READ);
|
||||
|
||||
/* 2-byte receive is a special case. See datasheet POS bit. */
|
||||
I2C_CR1(i2c) |= (I2C_CR1_POS | I2C_CR1_ACK);
|
||||
|
||||
/* Waiting for address is transferred. */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_ADDR));
|
||||
|
||||
/* Cleaning ADDR condition sequence. */
|
||||
reg32 = I2C_SR2(i2c);
|
||||
|
||||
/* Cleaning I2C_SR1_ACK. */
|
||||
I2C_CR1(i2c) &= ~ I2C_CR1_ACK;
|
||||
|
||||
/* Now the slave should begin to send us the first byte. Await BTF. */
|
||||
while (!(I2C_SR1(i2c) & I2C_SR1_BTF));
|
||||
temperature = (u16)(I2C_DR(i2c) << 8); /* MSB */
|
||||
|
||||
/*
|
||||
* Yes they mean it: we have to generate the STOP condition before
|
||||
* saving the 1st byte.
|
||||
*/
|
||||
I2C_CR1(i2c) |= I2C_CR1_STOP;
|
||||
|
||||
temperature |= I2C_DR(i2c); /* LSB */
|
||||
|
||||
/* Original state. */
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_POS;
|
||||
|
||||
return temperature;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 STTS75_H
|
||||
#define STTS75_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define STTS75_SENSOR0 0x48
|
||||
#define STTS75_SENSOR1 0x49
|
||||
#define STTS75_SENSOR2 0x4a
|
||||
#define STTS75_SENSOR3 0x4b
|
||||
#define STTS75_SENSOR4 0x4c
|
||||
#define STTS75_SENSOR5 0x4d
|
||||
#define STTS75_SENSOR6 0x4e
|
||||
#define STTS75_SENSOR7 0x4f
|
||||
|
||||
void stts75_write_config(u32 i2c, u8 sensor);
|
||||
void stts75_write_temp_os(u32 i2c, u8 sensor, u16 temp_os);
|
||||
void stts75_write_temp_hyst(u32 i2c, u8 sensor, u16 temp_hyst);
|
||||
u16 stts75_read_temperature(u32 i2c, u8 sensor);
|
||||
|
||||
#endif
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = rtc
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is a small RTC example project.
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Lord James <lordjames@y7mail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/rtc.h>
|
||||
#include <libopencm3/stm32/pwr.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz();
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
usart_set_baudrate(USART1, 38400);
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO12 (in GPIO port C) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
|
||||
}
|
||||
|
||||
void nvic_setup(void)
|
||||
{
|
||||
/* Without this the RTC interrupt routine will never be called. */
|
||||
nvic_enable_irq(NVIC_RTC_IRQ);
|
||||
nvic_set_priority(NVIC_RTC_IRQ, 1);
|
||||
}
|
||||
|
||||
void rtc_isr(void)
|
||||
{
|
||||
volatile u32 j = 0, c = 0;
|
||||
|
||||
/* The interrupt flag isn't cleared by hardware, we have to do it. */
|
||||
rtc_clear_flag(RTC_SEC);
|
||||
|
||||
/* Visual output. */
|
||||
gpio_toggle(GPIOC, GPIO12);
|
||||
|
||||
c = rtc_get_counter_val();
|
||||
|
||||
/* Display the current counter value in binary via USART1. */
|
||||
for (j = 0; j < 32; j++) {
|
||||
if ((c & (0x80000000 >> j)) != 0) {
|
||||
usart_send(USART1, '1');
|
||||
} else {
|
||||
usart_send(USART1, '0');
|
||||
}
|
||||
}
|
||||
usart_send(USART1, '\n');
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/*
|
||||
* If the RTC is pre-configured just allow access, don't reconfigure.
|
||||
* Otherwise enable it with the LSE as clock source and 0x7fff as
|
||||
* prescale value.
|
||||
*/
|
||||
rtc_auto_awake(LSE, 0x7fff);
|
||||
|
||||
/* Setup the RTC interrupt. */
|
||||
nvic_setup();
|
||||
|
||||
/* Enable the RTC interrupt to occur off the SEC flag. */
|
||||
rtc_interrupt_enable(RTC_SEC);
|
||||
|
||||
while(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = systick
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program blinks a LED on PortB Pin 6. 1 second on / 1 second off.
|
||||
Blinking is done via the systick timer interrupt.
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
|
||||
u32 temp32;
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
}
|
||||
|
||||
void sys_tick_handler()
|
||||
{
|
||||
temp32++;
|
||||
|
||||
/* we call this handler every 1ms so 1000ms = 1s on/off */
|
||||
if (temp32 == 1000) {
|
||||
gpio_toggle(GPIOB, GPIO6); /* LED2 on/off */
|
||||
temp32 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_16mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
|
||||
gpio_clear(GPIOB, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOB, GPIO6); /* LED2 off */
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
/* 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();
|
||||
|
||||
while(1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = timer
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program blinks a LED on PortB Pin 6. 1 second on / 1 second off.
|
||||
Blinking is made only with the timer interrupt of the TIM2 timer.
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOB clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
|
||||
|
||||
/* Set GPIO6/7 (in GPIO port B) to 'output push-pull' for the LEDs. */
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
|
||||
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
|
||||
}
|
||||
|
||||
void nvic_setup()
|
||||
{
|
||||
/* without this the timer interrupt routine will never be called */
|
||||
nvic_enable_irq(NVIC_TIM2_IRQ);
|
||||
nvic_set_priority(NVIC_TIM2_IRQ, 1);
|
||||
}
|
||||
|
||||
void tim2_isr()
|
||||
{
|
||||
/* LED2 on/off */
|
||||
gpio_toggle(GPIOB, GPIO6);
|
||||
|
||||
/* clear interrrupt flag */
|
||||
TIM_SR(TIM2) &= ~TIM_SR_UIF;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_16mhz_out_72mhz();
|
||||
gpio_setup();
|
||||
nvic_setup();
|
||||
|
||||
gpio_clear(GPIOB, GPIO7); /* LED1 on */
|
||||
gpio_set(GPIOB, GPIO6); /* LED2 off */
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN);
|
||||
|
||||
/* the goal is to let the LED2 glow for a second and then be off for a second */
|
||||
|
||||
/* Set timer start value */
|
||||
TIM_CNT(TIM2) = 1;
|
||||
|
||||
/* Set timer prescaler. 72MHz/1440 => 50000 counts per second */
|
||||
TIM_PSC(TIM2) = 1440;
|
||||
|
||||
/* End timer value. If this value is reached an interrupt is generated */
|
||||
TIM_ARR(TIM2) = 50000;
|
||||
|
||||
/* Update interrupt enable */
|
||||
TIM_DIER(TIM2) |= TIM_DIER_UIE;
|
||||
|
||||
/* Start timer */
|
||||
TIM_CR1(TIM2) |= TIM_CR1_CEN;
|
||||
|
||||
while(1); /* Halt. */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for an STM32F103RBT6 board (128K flash, 20K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = cdcacm
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB CDC-ACM device (aka Virtual Serial Port)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/cdc.h>
|
||||
|
||||
static const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = USB_CLASS_CDC,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x0483,
|
||||
.idProduct = 0x5740,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
/* This notification endpoint isn't implemented. According to CDC spec its
|
||||
* optional, but its absence causes a NULL pointer dereference in Linux cdc_acm
|
||||
* driver. */
|
||||
static const struct usb_endpoint_descriptor comm_endp[] = {{
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = 0x83,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 16,
|
||||
.bInterval = 255,
|
||||
}};
|
||||
|
||||
static const struct usb_endpoint_descriptor data_endp[] = {{
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = 0x01,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 1,
|
||||
}, {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = 0x82,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_BULK,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 1,
|
||||
}};
|
||||
|
||||
static const struct {
|
||||
struct usb_cdc_header_descriptor header;
|
||||
struct usb_cdc_call_management_descriptor call_mgmt;
|
||||
struct usb_cdc_acm_descriptor acm;
|
||||
struct usb_cdc_union_descriptor cdc_union;
|
||||
} __attribute__((packed)) cdcacm_functional_descriptors = {
|
||||
.header = {
|
||||
.bFunctionLength = sizeof(struct usb_cdc_header_descriptor),
|
||||
.bDescriptorType = CS_INTERFACE,
|
||||
.bDescriptorSubtype = USB_CDC_TYPE_HEADER,
|
||||
.bcdCDC = 0x0110,
|
||||
},
|
||||
.call_mgmt = {
|
||||
.bFunctionLength =
|
||||
sizeof(struct usb_cdc_call_management_descriptor),
|
||||
.bDescriptorType = CS_INTERFACE,
|
||||
.bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
|
||||
.bmCapabilities = 0,
|
||||
.bDataInterface = 1,
|
||||
},
|
||||
.acm = {
|
||||
.bFunctionLength = sizeof(struct usb_cdc_acm_descriptor),
|
||||
.bDescriptorType = CS_INTERFACE,
|
||||
.bDescriptorSubtype = USB_CDC_TYPE_ACM,
|
||||
.bmCapabilities = 0,
|
||||
},
|
||||
.cdc_union = {
|
||||
.bFunctionLength = sizeof(struct usb_cdc_union_descriptor),
|
||||
.bDescriptorType = CS_INTERFACE,
|
||||
.bDescriptorSubtype = USB_CDC_TYPE_UNION,
|
||||
.bControlInterface = 0,
|
||||
.bSubordinateInterface0 = 1,
|
||||
}
|
||||
};
|
||||
|
||||
static const struct usb_interface_descriptor comm_iface[] = {{
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 1,
|
||||
.bInterfaceClass = USB_CLASS_CDC,
|
||||
.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
|
||||
.bInterfaceProtocol = USB_CDC_PROTOCOL_AT,
|
||||
.iInterface = 0,
|
||||
|
||||
.endpoint = comm_endp,
|
||||
|
||||
.extra = &cdcacm_functional_descriptors,
|
||||
.extralen = sizeof(cdcacm_functional_descriptors)
|
||||
}};
|
||||
|
||||
static const struct usb_interface_descriptor data_iface[] = {{
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 1,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 2,
|
||||
.bInterfaceClass = USB_CLASS_DATA,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = 0,
|
||||
|
||||
.endpoint = data_endp,
|
||||
}};
|
||||
|
||||
static const struct usb_interface ifaces[] = {{
|
||||
.num_altsetting = 1,
|
||||
.altsetting = comm_iface,
|
||||
}, {
|
||||
.num_altsetting = 1,
|
||||
.altsetting = data_iface,
|
||||
}};
|
||||
|
||||
static const struct usb_config_descriptor config = {
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
.bNumInterfaces = 2,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0x80,
|
||||
.bMaxPower = 0x32,
|
||||
|
||||
.interface = ifaces,
|
||||
};
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"CDC-ACM Demo",
|
||||
"DEMO"
|
||||
};
|
||||
|
||||
static int cdcacm_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
(void)buf;
|
||||
|
||||
switch(req->bRequest) {
|
||||
case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
|
||||
/* This Linux cdc_acm driver requires this to be implemented
|
||||
* even though it's optional in the CDC spec, and we don't
|
||||
* advertise it in the ACM functional descriptor. */
|
||||
char buf[10];
|
||||
struct usb_cdc_notification *notif = (void*)buf;
|
||||
|
||||
/* We echo signals back to host as notification */
|
||||
notif->bmRequestType = 0xA1;
|
||||
notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE;
|
||||
notif->wValue = 0;
|
||||
notif->wIndex = 0;
|
||||
notif->wLength = 2;
|
||||
buf[8] = req->wValue & 3;
|
||||
buf[9] = 0;
|
||||
//usbd_ep_write_packet(0x83, buf, 10);
|
||||
return 1;
|
||||
}
|
||||
case USB_CDC_REQ_SET_LINE_CODING:
|
||||
if(*len < sizeof(struct usb_cdc_line_coding))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cdcacm_data_rx_cb(u8 ep)
|
||||
{
|
||||
(void)ep;
|
||||
|
||||
char buf[64];
|
||||
int len = usbd_ep_read_packet(0x01, buf, 64);
|
||||
if(len) {
|
||||
usbd_ep_write_packet(0x82, buf, len);
|
||||
buf[len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void cdcacm_set_config(u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
|
||||
usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
|
||||
usbd_ep_setup(0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
cdcacm_control_request);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(cdcacm_set_config);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usbdfu
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB Device Firmware Upgrade (DFU) bootloader
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/stm32/scb.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
|
||||
#define APP_ADDRESS 0x08002000
|
||||
|
||||
/* Commands sent with wBlockNum == 0 as per ST implementation. */
|
||||
#define CMD_SETADDR 0x21
|
||||
#define CMD_ERASE 0x41
|
||||
|
||||
/* We need a special large control buffer for this device: */
|
||||
u8 usbd_control_buffer[1024];
|
||||
|
||||
static enum dfu_state usbdfu_state = STATE_DFU_IDLE;
|
||||
|
||||
static struct {
|
||||
u8 buf[sizeof(usbd_control_buffer)];
|
||||
u16 len;
|
||||
u32 addr;
|
||||
u16 blocknum;
|
||||
} prog;
|
||||
|
||||
const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x0483,
|
||||
.idProduct = 0xDF11,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
const struct usb_dfu_descriptor dfu_function = {
|
||||
.bLength = sizeof(struct usb_dfu_descriptor),
|
||||
.bDescriptorType = DFU_FUNCTIONAL,
|
||||
.bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH,
|
||||
.wDetachTimeout = 255,
|
||||
.wTransferSize = 1024,
|
||||
.bcdDFUVersion = 0x011A,
|
||||
};
|
||||
|
||||
const struct usb_interface_descriptor iface = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 0,
|
||||
.bInterfaceClass = 0xFE, /* Device Firmware Upgrade */
|
||||
.bInterfaceSubClass = 1,
|
||||
.bInterfaceProtocol = 2,
|
||||
|
||||
/* The ST Microelectronics DfuSe application needs this string.
|
||||
* The format isn't documented... */
|
||||
.iInterface = 4,
|
||||
|
||||
.extra = &dfu_function,
|
||||
.extralen = sizeof(dfu_function),
|
||||
};
|
||||
|
||||
const struct usb_interface ifaces[] = {{
|
||||
.num_altsetting = 1,
|
||||
.altsetting = &iface,
|
||||
}};
|
||||
|
||||
const struct usb_config_descriptor config = {
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0xC0,
|
||||
.bMaxPower = 0x32,
|
||||
|
||||
.interface = ifaces,
|
||||
};
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"DFU Demo",
|
||||
"DEMO",
|
||||
/* This string is used by ST Microelectronics' DfuSe utility */
|
||||
"@Internal Flash /0x08000000/8*001Ka,56*001Kg"
|
||||
};
|
||||
|
||||
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
|
||||
{
|
||||
switch(usbdfu_state) {
|
||||
case STATE_DFU_DNLOAD_SYNC:
|
||||
usbdfu_state = STATE_DFU_DNBUSY;
|
||||
*bwPollTimeout = 100;
|
||||
return DFU_STATUS_OK;
|
||||
|
||||
case STATE_DFU_MANIFEST_SYNC:
|
||||
/* Device will reset when read is complete */
|
||||
usbdfu_state = STATE_DFU_MANIFEST;
|
||||
return DFU_STATUS_OK;
|
||||
|
||||
default:
|
||||
return DFU_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static void usbdfu_getstatus_complete(struct usb_setup_data *req)
|
||||
{
|
||||
int i;
|
||||
(void)req;
|
||||
|
||||
switch(usbdfu_state) {
|
||||
case STATE_DFU_DNBUSY:
|
||||
|
||||
flash_unlock();
|
||||
if(prog.blocknum == 0) {
|
||||
switch(prog.buf[0]) {
|
||||
case CMD_ERASE:
|
||||
flash_erase_page(*(u32*)(prog.buf+1));
|
||||
case CMD_SETADDR:
|
||||
prog.addr = *(u32*)(prog.buf+1);
|
||||
}
|
||||
} else {
|
||||
u32 baseaddr = prog.addr +
|
||||
((prog.blocknum - 2) *
|
||||
dfu_function.wTransferSize);
|
||||
for(i = 0; i < prog.len; i += 2)
|
||||
flash_program_half_word(baseaddr + i,
|
||||
*(u16*)(prog.buf+i));
|
||||
}
|
||||
flash_lock();
|
||||
|
||||
/* We jump straight to dfuDNLOAD-IDLE,
|
||||
* skipping dfuDNLOAD-SYNC
|
||||
*/
|
||||
usbdfu_state = STATE_DFU_DNLOAD_IDLE;
|
||||
return;
|
||||
|
||||
case STATE_DFU_MANIFEST:
|
||||
/* USB device must detach, we just reset... */
|
||||
scb_reset_system();
|
||||
return; /* Will never return */
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int usbdfu_control_request(struct usb_setup_data *req, u8 **buf,
|
||||
u16 *len, void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
|
||||
if((req->bmRequestType & 0x7F) != 0x21)
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
switch(req->bRequest) {
|
||||
case DFU_DNLOAD:
|
||||
if((len == NULL) || (*len == 0)) {
|
||||
usbdfu_state = STATE_DFU_MANIFEST_SYNC;
|
||||
return 1;
|
||||
} else {
|
||||
/* Copy download data for use on GET_STATUS */
|
||||
prog.blocknum = req->wValue;
|
||||
prog.len = *len;
|
||||
memcpy(prog.buf, *buf, *len);
|
||||
usbdfu_state = STATE_DFU_DNLOAD_SYNC;
|
||||
return 1;
|
||||
}
|
||||
case DFU_CLRSTATUS:
|
||||
/* Clear error and return to dfuIDLE */
|
||||
if(usbdfu_state == STATE_DFU_ERROR)
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
case DFU_ABORT:
|
||||
/* Abort returns to dfuIDLE state */
|
||||
usbdfu_state = STATE_DFU_IDLE;
|
||||
return 1;
|
||||
case DFU_UPLOAD:
|
||||
/* Upload not supported for now */
|
||||
return 0;
|
||||
case DFU_GETSTATUS: {
|
||||
u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */
|
||||
|
||||
(*buf)[0] = usbdfu_getstatus(&bwPollTimeout);
|
||||
(*buf)[1] = bwPollTimeout & 0xFF;
|
||||
(*buf)[2] = (bwPollTimeout >> 8) & 0xFF;
|
||||
(*buf)[3] = (bwPollTimeout >> 16) & 0xFF;
|
||||
(*buf)[4] = usbdfu_state;
|
||||
(*buf)[5] = 0; /* iString not used here */
|
||||
*len = 6;
|
||||
|
||||
*complete = usbdfu_getstatus_complete;
|
||||
|
||||
return 1;
|
||||
}
|
||||
case DFU_GETSTATE:
|
||||
/* Return state with no state transision */
|
||||
*buf[0] = usbdfu_state;
|
||||
*len = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
if(!gpio_get(GPIOA, GPIO10)) {
|
||||
/* Boot the application if it's valid */
|
||||
if((*(volatile u32*)APP_ADDRESS & 0x2FFE0000) == 0x20000000) {
|
||||
/* Set vector table base address */
|
||||
SCB_VTOR = APP_ADDRESS & 0xFFFF;
|
||||
/* Initialise master stack pointer */
|
||||
asm volatile ("msr msp, %0"::"g"
|
||||
(*(volatile u32*)APP_ADDRESS));
|
||||
/* Jump to application */
|
||||
(*(void(**)())(APP_ADDRESS + 4))();
|
||||
}
|
||||
}
|
||||
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_set_control_buffer_size(sizeof(usbd_control_buffer));
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
usbdfu_control_request);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 8K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usbhid
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example implements a USB Human Interface Device (HID)
|
||||
to demonstrate the use of the USB device stack.
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/systick.h>
|
||||
#include <libopencm3/usb/usbd.h>
|
||||
#include <libopencm3/usb/hid.h>
|
||||
|
||||
/* Define this to include the DFU APP interface. */
|
||||
#define INCLUDE_DFU_INTERFACE
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
#include <libopencm3/stm32/scb.h>
|
||||
#include <libopencm3/usb/dfu.h>
|
||||
#endif
|
||||
|
||||
const struct usb_device_descriptor dev = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
.bDeviceClass = 0,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x0483,
|
||||
.idProduct = 0x5710,
|
||||
.bcdDevice = 0x0200,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
/* I have no idea what this means. I haven't read the HID spec. */
|
||||
static const u8 hid_report_descriptor[] = {
|
||||
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
|
||||
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
|
||||
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
|
||||
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,
|
||||
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38,
|
||||
0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x03,
|
||||
0x81, 0x06, 0xC0, 0x09, 0x3c, 0x05, 0xff, 0x09,
|
||||
0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95,
|
||||
0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1,
|
||||
0x01, 0xc0
|
||||
};
|
||||
|
||||
static const struct {
|
||||
struct usb_hid_descriptor hid_descriptor;
|
||||
struct {
|
||||
u8 bReportDescriptorType;
|
||||
u16 wDescriptorLength;
|
||||
} __attribute__((packed)) hid_report;
|
||||
} __attribute__((packed)) hid_function = {
|
||||
.hid_descriptor = {
|
||||
.bLength = sizeof(hid_function),
|
||||
.bDescriptorType = USB_DT_HID,
|
||||
.bcdHID = 0x0100,
|
||||
.bCountryCode = 0,
|
||||
.bNumDescriptors = 1,
|
||||
},
|
||||
.hid_report = {
|
||||
.bReportDescriptorType = USB_DT_REPORT,
|
||||
.wDescriptorLength = sizeof(hid_report_descriptor),
|
||||
}
|
||||
};
|
||||
|
||||
const struct usb_endpoint_descriptor hid_endpoint = {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = 0x81,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 4,
|
||||
.bInterval = 0x20,
|
||||
};
|
||||
|
||||
const struct usb_interface_descriptor hid_iface = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 0,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 1,
|
||||
.bInterfaceClass = USB_CLASS_HID,
|
||||
.bInterfaceSubClass = 1, /* boot */
|
||||
.bInterfaceProtocol = 2, /* mouse */
|
||||
.iInterface = 0,
|
||||
|
||||
.endpoint = &hid_endpoint,
|
||||
|
||||
.extra = &hid_function,
|
||||
.extralen = sizeof(hid_function),
|
||||
};
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
const struct usb_dfu_descriptor dfu_function = {
|
||||
.bLength = sizeof(struct usb_dfu_descriptor),
|
||||
.bDescriptorType = DFU_FUNCTIONAL,
|
||||
.bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH,
|
||||
.wDetachTimeout = 255,
|
||||
.wTransferSize = 1024,
|
||||
.bcdDFUVersion = 0x011A,
|
||||
};
|
||||
|
||||
const struct usb_interface_descriptor dfu_iface = {
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = 1,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 0,
|
||||
.bInterfaceClass = 0xFE,
|
||||
.bInterfaceSubClass = 1,
|
||||
.bInterfaceProtocol = 1,
|
||||
.iInterface = 0,
|
||||
|
||||
.extra = &dfu_function,
|
||||
.extralen = sizeof(dfu_function),
|
||||
};
|
||||
#endif
|
||||
|
||||
const struct usb_interface ifaces[] = {{
|
||||
.num_altsetting = 1,
|
||||
.altsetting = &hid_iface,
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
}, {
|
||||
.num_altsetting = 1,
|
||||
.altsetting = &dfu_iface,
|
||||
#endif
|
||||
}};
|
||||
|
||||
const struct usb_config_descriptor config = {
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
.bNumInterfaces = 2,
|
||||
#else
|
||||
.bNumInterfaces = 1,
|
||||
#endif
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0xC0,
|
||||
.bMaxPower = 0x32,
|
||||
|
||||
.interface = ifaces,
|
||||
};
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"x",
|
||||
"Black Sphere Technologies",
|
||||
"HID Demo",
|
||||
"DEMO",
|
||||
};
|
||||
|
||||
static int hid_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
(void)complete;
|
||||
|
||||
if((req->bmRequestType != 0x81) ||
|
||||
(req->bRequest != USB_REQ_GET_DESCRIPTOR) ||
|
||||
(req->wValue != 0x2200))
|
||||
return 0;
|
||||
|
||||
/* Handle the HID report descriptor */
|
||||
*buf = (u8*)hid_report_descriptor;
|
||||
*len = sizeof(hid_report_descriptor);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
static void dfu_detach_complete(struct usb_setup_data *req)
|
||||
{
|
||||
(void)req;
|
||||
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO10);
|
||||
gpio_set(GPIOA, GPIO10);
|
||||
scb_reset_core();
|
||||
}
|
||||
|
||||
static int dfu_control_request(struct usb_setup_data *req, u8 **buf, u16 *len,
|
||||
void (**complete)(struct usb_setup_data *req))
|
||||
{
|
||||
(void)buf;
|
||||
(void)len;
|
||||
|
||||
if((req->bmRequestType != 0x21) || (req->bRequest != DFU_DETACH))
|
||||
return 0; /* Only accept class request */
|
||||
|
||||
*complete = dfu_detach_complete;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hid_set_config(u16 wValue)
|
||||
{
|
||||
(void)wValue;
|
||||
|
||||
usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
|
||||
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
hid_control_request);
|
||||
#ifdef INCLUDE_DFU_INTERFACE
|
||||
usbd_register_control_callback(
|
||||
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
|
||||
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
|
||||
dfu_control_request);
|
||||
#endif
|
||||
|
||||
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
|
||||
systick_set_reload(100000);
|
||||
systick_interrupt_enable();
|
||||
systick_counter_enable();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hsi_out_48mhz();
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
|
||||
|
||||
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO15);
|
||||
|
||||
usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings);
|
||||
usbd_register_set_config_callback(hid_set_config);
|
||||
|
||||
gpio_set(GPIOA, GPIO15);
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
|
||||
|
||||
while (1)
|
||||
usbd_poll();
|
||||
}
|
||||
|
||||
void sys_tick_handler(void)
|
||||
{
|
||||
static int x = 0;
|
||||
static int dir = 1;
|
||||
u8 buf[4] = {0, 0, 0, 0};
|
||||
|
||||
buf[1] = dir;
|
||||
x += dir;
|
||||
if(x > 30) dir = -dir;
|
||||
if(x < -30) dir = -dir;
|
||||
|
||||
usbd_ep_write_packet(0x81, buf, 4);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = button
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example blinks the green LED on the ST STM32VLDISCOVERY eval board.
|
||||
|
||||
When you press the 'USER' button, the blinking is slower.
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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 program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
u16 exti_line_state;
|
||||
|
||||
/* Set STM32 to 24 MHz. */
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_24mhz();
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Set GPIO9 (in GPIO port C) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
|
||||
}
|
||||
|
||||
void button_setup(void)
|
||||
{
|
||||
/* Enable GPIOA clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
|
||||
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, GPIO0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
button_setup();
|
||||
|
||||
/* Blink the LED (PC9) on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO9);
|
||||
|
||||
/* Upon button press, blink more slowly. */
|
||||
exti_line_state = GPIOA_IDR;
|
||||
if ((exti_line_state & (1 << 0)) != 0) {
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for ST STM32VLDISCOVERY (STM32F100RB, 128K flash, 8K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = fancyblink
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is the smallest-possible example program using libopencm3.
|
||||
|
||||
It's intended for the ST STM32VLDISCOVERY eval board. It should blink
|
||||
the LEDs on the board.
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
* Copyright (C) 2011 Damjan Marion <damjan.marion@gmail.com>
|
||||
* Copyright (C) 2011 Mark Panajotovic <marko@electrontube.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
/* Set STM32 to 24 MHz. */
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_24mhz();
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO8/9 (in GPIO port C) to 'output push-pull'. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
|
||||
/* Set one LED for wigwag effect when toggling. */
|
||||
gpio_set(GPIOC, GPIO8);
|
||||
|
||||
/* Blink the LEDs (PC8 and PC9) on the board. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO8 | GPIO9); /* Toggle LEDs. */
|
||||
for (i = 0; i < 2000000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for ST STM32VLDISCOVERY (STM32F100RB, 128K flash, 8K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = miniblink
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is the smallest-possible example program using libopencm3.
|
||||
|
||||
It's intended for the ST STM32VLDISCOVERY eval board. It should blink
|
||||
the blue LED on the board.
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Enable GPIOC clock. */
|
||||
/* Manually: */
|
||||
// RCC_APB2ENR |= RCC_APB2ENR_IOPCEN;
|
||||
/* Using API functions: */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Set GPIO8 (in GPIO port C) to 'output push-pull'. */
|
||||
/* Manually: */
|
||||
// GPIOC_CRH = (GPIO_CNF_OUTPUT_PUSHPULL << (((8 - 8) * 4) + 2));
|
||||
// GPIOC_CRH |= (GPIO_MODE_OUTPUT_2_MHZ << ((8 - 8) * 4));
|
||||
/* Using API functions: */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
gpio_setup();
|
||||
|
||||
/* Blink the LED (PC8) on the board. */
|
||||
while (1) {
|
||||
/* Manually: */
|
||||
// GPIOC_BSRR = GPIO8; /* LED off */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
// GPIOC_BRR = GPIO8; /* LED on */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
|
||||
/* Using API functions gpio_set()/gpio_clear(): */
|
||||
// gpio_set(GPIOC, GPIO8); /* LED off */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
// gpio_clear(GPIOC, GPIO8); /* LED on */
|
||||
// for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
// __asm__("nop");
|
||||
|
||||
/* Using API function gpio_toggle(): */
|
||||
gpio_toggle(GPIOC, GPIO8); /* LED on/off */
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("nop");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for ST STM32VLDISCOVERY (STM32F100RB, 128K flash, 8K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = rtc
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This is a small RTC example project.
|
||||
|
||||
It blinks the ST STM32VLDISCOVERY's blue LED at 1Hz, and sends the value of
|
||||
the RTC counter register down the serial line (PA9) at 38400,8N1.
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2010 Lord James <lordjames@y7mail.com>
|
||||
* Copyright (C) 2011 Mark Panajotovic <marko@electrontube.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/rtc.h>
|
||||
#include <libopencm3/stm32/pwr.h>
|
||||
#include <libopencm3/stm32/nvic.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_24mhz();
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
// usart_set_baudrate(USART1, 38400);
|
||||
/* TODO usart_set_baudrate() doesn't support 24MHz clock (yet). */
|
||||
/* This is the equivalent: */
|
||||
USART_BRR(USART1) = (u16)((24000000 << 4) / (38400 * 16));
|
||||
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO8 (in GPIO port C) to 'output push-pull'. */
|
||||
/* This drives the blue LED on the STM32VLDISCOVERY. */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
|
||||
}
|
||||
|
||||
void nvic_setup(void)
|
||||
{
|
||||
/* Without this the RTC interrupt routine will never be called. */
|
||||
nvic_enable_irq(NVIC_RTC_IRQ);
|
||||
nvic_set_priority(NVIC_RTC_IRQ, 1);
|
||||
}
|
||||
|
||||
void rtc_isr(void)
|
||||
{
|
||||
volatile u32 j = 0, c = 0;
|
||||
|
||||
/* The interrupt flag isn't cleared by hardware, we have to do it. */
|
||||
rtc_clear_flag(RTC_SEC);
|
||||
|
||||
/* Visual output. */
|
||||
gpio_toggle(GPIOC, GPIO8);
|
||||
|
||||
c = rtc_get_counter_val();
|
||||
|
||||
/* Display the current counter value in binary via USART1. */
|
||||
for (j = 0; j < 32; j++) {
|
||||
if ((c & (0x80000000 >> j)) != 0)
|
||||
usart_send_blocking(USART1, '1');
|
||||
else
|
||||
usart_send_blocking(USART1, '0');
|
||||
}
|
||||
usart_send_blocking(USART1, '\n');
|
||||
usart_send_blocking(USART1, '\r');
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/*
|
||||
* If the RTC is pre-configured just allow access, don't reconfigure.
|
||||
* Otherwise enable it with the LSE as clock source and 0x7fff as
|
||||
* prescale value.
|
||||
*/
|
||||
rtc_auto_awake(LSE, 0x7fff);
|
||||
|
||||
/* The above mode will not reset the RTC when you press the RST button.
|
||||
* It will also continue to count while the MCU is held in reset. If
|
||||
* you want it to reset, comment out the above and use the following:
|
||||
*/
|
||||
// rtc_awake_from_off(LSE);
|
||||
// rtc_set_prescale_val(0x7fff);
|
||||
|
||||
/* Setup the RTC interrupt. */
|
||||
nvic_setup();
|
||||
|
||||
/* Enable the RTC interrupt to occur off the SEC flag. */
|
||||
rtc_interrupt_enable(RTC_SEC);
|
||||
|
||||
while(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* Linker script for ST STM32VLDISCOVERY (STM32F100RB, 128K flash, 8K RAM). */
|
||||
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32.ld
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
##
|
||||
## This file is part of the libopencm3 project.
|
||||
##
|
||||
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
##
|
||||
## This program is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## 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/>.
|
||||
##
|
||||
|
||||
BINARY = usart
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
------------------------------------------------------------------------------
|
||||
README
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
This example program sends some characters on USART1 on the
|
||||
ST STM32VLDISCOVERY eval board.
|
||||
|
||||
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.
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
|
||||
void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_24mhz();
|
||||
|
||||
/* Enable GPIOC clock. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
/* Enable clocks for GPIO port A (for GPIO_USART1_TX) and USART1. */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
||||
}
|
||||
|
||||
void usart_setup(void)
|
||||
{
|
||||
/* Setup GPIO pin GPIO_USART1_TX/GPIO9 on GPIO port A for transmit. */
|
||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||
|
||||
/* Setup UART parameters. */
|
||||
// usart_set_baudrate(USART1, 38400);
|
||||
/* TODO usart_set_baudrate() doesn't support 24MHz clock (yet). */
|
||||
/* This is the equivalent: */
|
||||
USART_BRR(USART1) = (u16)((24000000 << 4) / (38400 * 16));
|
||||
|
||||
usart_set_databits(USART1, 8);
|
||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||
usart_set_mode(USART1, USART_MODE_TX);
|
||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||
|
||||
/* Finally enable the USART. */
|
||||
usart_enable(USART1);
|
||||
}
|
||||
|
||||
void gpio_setup(void)
|
||||
{
|
||||
/* Set GPIO9 (in GPIO port C) to 'output push-pull'. [LED] */
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j = 0, c = 0;
|
||||
|
||||
clock_setup();
|
||||
gpio_setup();
|
||||
usart_setup();
|
||||
|
||||
/* Blink the LED (PC9) on the board with every transmitted byte. */
|
||||
while (1) {
|
||||
gpio_toggle(GPIOC, GPIO9); /* LED on/off */
|
||||
usart_send_blocking(USART1, c + '0'); /* USART1: Send byte. */
|
||||
c = (c == 9) ? 0 : c + 1; /* Increment c. */
|
||||
if ((j++ % 80) == 0) { /* Newline after line full. */
|
||||
usart_send_blocking(USART1, '\r');
|
||||
usart_send_blocking(USART1, '\n');
|
||||
}
|
||||
for (i = 0; i < 800000; i++) /* Wait a bit. */
|
||||
__asm__("NOP");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user