aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/stm32
diff options
context:
space:
mode:
authorUwe Bonnes2013-01-15 16:55:24 +0100
committerUwe Bonnes2013-01-21 11:02:44 +0100
commit72ca77af530047c47646d0450f8a759d2ed595a1 (patch)
treede3cbbef3feb65c1ab2cc291201d27741824fda5 /src/platforms/stm32
parent313a24b31676e4d74362f9280e54d467815e7514 (diff)
stm32_can: Changes to get blackmagic to work
Diffstat (limited to 'src/platforms/stm32')
-rw-r--r--src/platforms/stm32/stm32_can.ld28
-rw-r--r--src/platforms/stm32/usbdfu.c36
2 files changed, 61 insertions, 3 deletions
diff --git a/src/platforms/stm32/stm32_can.ld b/src/platforms/stm32/stm32_can.ld
new file mode 100644
index 0000000..86861b8
--- /dev/null
+++ b/src/platforms/stm32/stm32_can.ld
@@ -0,0 +1,28 @@
+/*
+ * This file is part of the libopenstm32 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 = 256K
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
+}
+
+/* Include the common ld script from libopenstm32. */
+INCLUDE libopencm3_stm32f1.ld
diff --git a/src/platforms/stm32/usbdfu.c b/src/platforms/stm32/usbdfu.c
index f809a2a..e33eddb 100644
--- a/src/platforms/stm32/usbdfu.c
+++ b/src/platforms/stm32/usbdfu.c
@@ -130,14 +130,26 @@ static char serial_no[9];
static const char *usb_strings[] = {
"Black Sphere Technologies",
-#if defined(DISCOVERY_STLINK)
+#if defined(BLACKMAGIC)
+ "Black Magic Probe (Upgrade)",
+#elif defined(DISCOVERY_STLINK)
"Black Magic (Upgrade) for STLink/Discovery",
+#elif defined(STM32_CAN)
+ "Black Magic (Upgrade) for STM32_CAN",
#else
- "Black Magic Probe (Upgrade)",
+#warning "Unhandled board"
#endif
serial_no,
/* This string is used by ST Microelectronics' DfuSe utility */
+#if defined(BLACKMAGIC)
"@Internal Flash /0x08000000/8*001Ka,120*001Kg"
+#elif defined(DISCOVERY_STLINK)
+ "@Internal Flash /0x08000000/8*001Ka,56*001Kg"
+#elif defined(STM32_CAN)
+ "@Internal Flash /0x08000000/4*002Ka,124*002Kg"
+#else
+#warning "Unhandled board"
+#endif
};
static u8 usbdfu_getstatus(u32 *bwPollTimeout)
@@ -190,6 +202,7 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req)
flash_erase_page(page_start);
last_erased_pages = page_start;
}
+
}
case CMD_SETADDR:
prog.addr = *(u32*)(prog.buf+1);
@@ -295,6 +308,9 @@ int main(void)
#if defined (DISCOVERY_STLINK)
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
if(!gpio_get(GPIOC, GPIO13)) {
+#elif defined (STM32_CAN)
+ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
+ if(!gpio_get(GPIOA, GPIO0)) {
#else
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
if(gpio_get(GPIOB, GPIO12)) {
@@ -316,6 +332,8 @@ int main(void)
FLASH_CR = 0;
flash_erase_option_bytes();
flash_program_option_bytes(FLASH_OBP_RDP, FLASH_OBP_RDP_KEY);
+ /* CL Device: Protect 2 bits with (2 * 2k pages each)*/
+ /* MD Device: Protect 2 bits with (4 * 1k pages each)*/
flash_program_option_bytes(FLASH_OBP_WRP10, 0x03FC);
}
@@ -332,13 +350,18 @@ int main(void)
#endif
rcc_clock_setup_in_hse_8mhz_out_72mhz();
- rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
#if defined(DISCOVERY_STLINK)
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_ANALOG, GPIO0);
+#elif defined (STM32_CAN)
+ rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);
+ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
+ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_PUSHPULL, GPIO0);
#else
+ rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO8);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
@@ -353,8 +376,13 @@ int main(void)
get_dev_unique_id(serial_no);
+#if defined(STM32_CAN)
+ usbdev = usbd_init(&stm32f107_usb_driver,
+ &dev, &config, usb_strings, 4);
+#else
usbdev = usbd_init(&stm32f103_usb_driver,
&dev, &config, usb_strings, 4);
+#endif
usbd_set_control_buffer_size(usbdev, sizeof(usbd_control_buffer));
usbd_register_control_callback(usbdev,
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
@@ -401,6 +429,8 @@ void sys_tick_handler()
gpio_set_mode(GPIOA, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_ANALOG, GPIO9);
led2_state++;
+#elif defined(STM32_CAN)
+ gpio_toggle(GPIOB, GPIO0); /* LED2 on/off */
#else
gpio_toggle(GPIOB, GPIO11); /* LED2 on/off */
#endif