aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/f4discovery
diff options
context:
space:
mode:
Diffstat (limited to 'src/platforms/f4discovery')
-rw-r--r--src/platforms/f4discovery/Makefile.inc8
-rw-r--r--src/platforms/f4discovery/Readme17
-rw-r--r--src/platforms/f4discovery/platform.c172
-rw-r--r--src/platforms/f4discovery/platform.h105
4 files changed, 117 insertions, 185 deletions
diff --git a/src/platforms/f4discovery/Makefile.inc b/src/platforms/f4discovery/Makefile.inc
index 4c56bd6..8d9b3c1 100644
--- a/src/platforms/f4discovery/Makefile.inc
+++ b/src/platforms/f4discovery/Makefile.inc
@@ -3,13 +3,13 @@ CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
CFLAGS += -Istm32/include -mcpu=cortex-m3 -mthumb \
- -DSTM32F1 -DBLACKMAGIC -I../libopencm3/include
+ -DSTM32F4 -DF4DISCOVERY -I../libopencm3/include
-LDFLAGS_BOOT = -lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
- -Wl,-T,platforms/stm32/blackmagic.ld -nostartfiles -lc -lnosys \
+LDFLAGS_BOOT = -lopencm3_stm32f4 -Wl,--defsym,_stack=0x20020000 \
+ -Wl,-T,platforms/stm32/f4discovery.ld -nostartfiles -lc -lnosys \
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m3 -Wl,-gc-sections \
-L../libopencm3/lib
-LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000
+LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8010000
VPATH += platforms/stm32
diff --git a/src/platforms/f4discovery/Readme b/src/platforms/f4discovery/Readme
new file mode 100644
index 0000000..6035917
--- /dev/null
+++ b/src/platforms/f4discovery/Readme
@@ -0,0 +1,17 @@
+Application start address:
+=========================
+
+Use 0x8010000
+- lower 3 16 k pages may be used for parameter storage
+- Erasing a single 64 k Page is faster then erasing 2 16 k Pages
+ eventual the 64 k page
+
+
+Internal boot loader:
+====================
+
+When we request invokation of a bootloader from inside the application,
+we boot the device internal bootloader with the blue botton pressed.
+
+That way, we can easy exchange the custom bootloader via the device
+internale bootloader \ No newline at end of file
diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c
index 0e81ba4..4aa14a6 100644
--- a/src/platforms/f4discovery/platform.c
+++ b/src/platforms/f4discovery/platform.c
@@ -22,14 +22,14 @@
* implementation.
*/
-#include <libopencm3/stm32/f1/rcc.h>
+#include <libopencm3/stm32/f4/rcc.h>
#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/scb.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/exti.h>
#include <libopencm3/stm32/usart.h>
+#include <libopencm3/stm32/syscfg.h>
#include <libopencm3/usb/usbd.h>
-#include <libopencm3/stm32/f1/adc.h>
#include "platform.h"
#include "jtag_scan.h"
@@ -44,64 +44,39 @@ jmp_buf fatal_error_jmpbuf;
static void morse_update(void);
-static void adc_init(void);
-
-/* Pins PB[7:5] are used to detect hardware revision.
- * 000 - Original production build.
- * 001 - Mini production build.
- */
-int platform_hwversion(void)
-{
- static int hwversion = -1;
- if (hwversion == -1) {
- gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
- GPIO_CNF_INPUT_PULL_UPDOWN,
- GPIO7 | GPIO6 | GPIO5);
- gpio_clear(GPIOB, GPIO7 | GPIO6 | GPIO5);
- hwversion = gpio_get(GPIOB, GPIO7 | GPIO6 | GPIO5) >> 5;
- }
- return hwversion;
-}
-
int platform_init(void)
{
- rcc_clock_setup_in_hse_8mhz_out_72mhz();
+ rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);
/* Enable peripherals */
- rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
- rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
- rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
- rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
-
- /* Setup GPIO ports */
- gpio_clear(USB_PU_PORT, USB_PU_PIN);
- gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT,
- USB_PU_PIN);
-
- gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL,
- TMS_PIN | TCK_PIN | TDI_PIN);
+ rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);
+ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
+ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN);
+ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
- /* This needs some fixing... */
- /* Toggle required to sort out line drivers... */
- gpio_port_write(GPIOA, 0x8100);
- gpio_port_write(GPIOB, 0x2000);
- gpio_port_write(GPIOA, 0x8180);
- gpio_port_write(GPIOB, 0x2002);
+ /* Set up USB Pins and alternate function*/
+ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
+ GPIO9 | GPIO11 | GPIO12);
+ gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
+
+ GPIOA_OSPEEDR &=~0xfc;
+ GPIOA_OSPEEDR |= 0xa8;
+ gpio_mode_setup(JTAG_PORT, GPIO_MODE_OUTPUT,
+ GPIO_PUPD_NONE,
+ TMS_PIN | TCK_PIN | TDI_PIN);
- gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL,
- LED_UART | LED_IDLE_RUN | LED_ERROR);
+ gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT,
+ GPIO_PUPD_NONE,
+ TDO_PIN);
- /* FIXME: This pin in intended to be input, but the TXS0108 fails
- * to release the device from reset if this floats. */
- gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL, GPIO7);
+ gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT,
+ GPIO_PUPD_NONE,
+ LED_UART | LED_IDLE_RUN | LED_ERROR | LED_SPARE1);
/* Setup heartbeat timer */
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
- systick_set_reload(900000); /* Interrupt us at 10 Hz */
+ systick_set_reload(168000000/(10*8)); /* Interrupt us at 10 Hz */
SCB_SHPR(11) &= ~((15 << 4) & 0xff);
SCB_SHPR(11) |= ((14 << 4) & 0xff);
systick_interrupt_enable();
@@ -109,15 +84,7 @@ int platform_init(void)
usbuart_init();
- if (platform_hwversion() > 0) {
- adc_init();
- } else {
- gpio_clear(GPIOB, GPIO0);
- gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
- GPIO_CNF_INPUT_PULL_UPDOWN, GPIO0);
- }
-
- SCB_VTOR = 0x2000; // Relocate interrupt vector table here
+ SCB_VTOR = 0x10000; // Relocate interrupt vector table here
cdcacm_init();
@@ -219,88 +186,23 @@ static void morse_update(void)
code >>= 1; bits--;
}
-static void adc_init(void)
-{
- rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
-
- gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
- GPIO_CNF_INPUT_ANALOG, GPIO0);
-
- adc_off(ADC1);
- adc_disable_scan_mode(ADC1);
- adc_set_single_conversion_mode(ADC1);
- adc_disable_external_trigger_regular(ADC1);
- adc_set_right_aligned(ADC1);
- adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
-
- adc_power_on(ADC1);
-
- /* Wait for ADC starting up. */
- for (int i = 0; i < 800000; i++) /* Wait a bit. */
- __asm__("nop");
-
- adc_reset_calibration(ADC1);
- adc_calibration(ADC1);
-}
-
const char *platform_target_voltage(void)
{
- if (platform_hwversion() == 0)
- return gpio_get(GPIOB, GPIO0) ? "OK" : "ABSENT!";
-
- static char ret[] = "0.0V";
- const u8 channel = 8;
- adc_set_regular_sequence(ADC1, 1, (u8*)&channel);
-
- adc_on(ADC1);
-
- /* Wait for end of conversion. */
- while (!(ADC_SR(ADC1) & ADC_SR_EOC));
-
- u32 val = ADC_DR(ADC1) * 99; /* 0-4095 */
- ret[0] = '0' + val / 81910;
- ret[2] = '0' + (val / 8191) % 10;
-
- return ret;
+ return "ABSENT!";
}
void assert_boot_pin(void)
{
- gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
- gpio_clear(GPIOB, GPIO12);
-}
-
-void exti15_10_isr(void)
-{
- if (gpio_get(USB_VBUS_PORT, USB_VBUS_PIN)) {
- /* Drive pull-up high if VBUS connected */
- gpio_set_mode(USB_PU_PORT, GPIO_MODE_OUTPUT_10_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL, USB_PU_PIN);
- } else {
- /* Allow pull-up to float if VBUS disconnected */
- gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT,
- GPIO_CNF_INPUT_FLOAT, USB_PU_PIN);
+ if (gpio_get(GPIOA, GPIO0)) {
+ /* Jump to the built in bootloader by mapping System flash */
+ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_SYSCFGEN);
+ SYSCFG_MEMRM &= ~3;
+ SYSCFG_MEMRM |= 1;
+ }
+ else {
+ /* Flag Bootloader Request by mimicing a pushed USER button*/
+ gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT,
+ GPIO_PUPD_NONE, GPIO0);
+ gpio_set(GPIOA, GPIO0);
}
-
- exti_reset_request(USB_VBUS_PIN);
-}
-
-void setup_vbus_irq(void)
-{
- nvic_set_priority(USB_VBUS_IRQ, IRQ_PRI_USB_VBUS);
- nvic_enable_irq(USB_VBUS_IRQ);
-
- gpio_set(USB_VBUS_PORT, USB_VBUS_PIN);
- gpio_set(USB_PU_PORT, USB_PU_PIN);
-
- gpio_set_mode(USB_VBUS_PORT, GPIO_MODE_INPUT,
- GPIO_CNF_INPUT_PULL_UPDOWN, USB_VBUS_PIN);
-
- /* Configure EXTI for USB VBUS monitor */
- exti_select_source(USB_VBUS_PIN, USB_VBUS_PORT);
- exti_set_trigger(USB_VBUS_PIN, EXTI_TRIGGER_BOTH);
- exti_enable_request(USB_VBUS_PIN);
-
- exti15_10_isr();
}
diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h
index 7d84533..6cbbc1b 100644
--- a/src/platforms/f4discovery/platform.h
+++ b/src/platforms/f4discovery/platform.h
@@ -24,7 +24,7 @@
#ifndef __PLATFORM_H
#define __PLATFORM_H
-#include <libopencm3/stm32/f1/gpio.h>
+#include <libopencm3/stm32/f4/gpio.h>
#include <libopencm3/usb/usbd.h>
#include <setjmp.h>
@@ -42,18 +42,18 @@ extern usbd_device *usbdev;
/* Important pin mappings for STM32 implementation:
*
- * LED0 = PB2 (Yellow LED : Running)
- * LED1 = PB10 (Yellow LED : Idle)
- * LED2 = PB11 (Red LED : Error)
+ * LED0 = PD12 (Green LED : Running)
+ * LED1 = PD13 (Orange LED : Idle)
+ * LED2 = PD12 (Red LED : Error)
*
- * TPWR = RB0 (input) -- analogue on mini design ADC1, ch8
- * nTRST = PB1
- * SRST_OUT = PA2
- * TDI = PA3
- * TMS = PA4 (input for SWDP)
- * TCK = PA5
- * TDO = PA6 (input)
- * nSRST = PA7 (input)
+ * TPWR = XXX (input) -- analogue on mini design ADC1, ch8
+ * nTRST = PD0
+ * SRST_OUT = PD1
+ * TDI = PA1
+ * TMS = PA3 (input for SWDP)
+ * TCK = PA8
+ * TDO = PB4 (input)
+ * nSRST = PD2 (input)
*
* USB cable pull-up: PA8
* USB VBUS detect: PB13 -- New on mini design.
@@ -66,55 +66,68 @@ extern usbd_device *usbdev;
#define TDI_PORT JTAG_PORT
#define TMS_PORT JTAG_PORT
#define TCK_PORT JTAG_PORT
-#define TDO_PORT JTAG_PORT
-#define TDI_PIN GPIO3
-#define TMS_PIN GPIO4
-#define TCK_PIN GPIO5
-#define TDO_PIN GPIO6
+#define TDO_PORT GPIOB
+#define TDI_PIN GPIO1
+#define TMS_PIN GPIO3
+#define TCK_PIN GPIO2
+#define TDO_PIN GPIO4
#define SWDIO_PORT JTAG_PORT
#define SWCLK_PORT JTAG_PORT
#define SWDIO_PIN TMS_PIN
#define SWCLK_PIN TCK_PIN
-#define TRST_PORT GPIOB
-#define TRST_PIN GPIO1
-#define SRST_PORT GPIOA
-#define SRST_PIN GPIO2
+#define TRST_PORT GPIOD
+#define TRST_PIN GPIO0
+#define SRST_PORT GPIOD
+#define SRST_PIN GPIO1
-#define USB_PU_PORT GPIOA
-#define USB_PU_PIN GPIO8
+#define LED_PORT GPIOD
+#define LED_PORT_UART GPIOD
+#define LED_UART GPIO12
+#define LED_IDLE_RUN GPIO13
+#define LED_ERROR GPIO14
+#define LED_SPARE1 GPIO15
-#define USB_VBUS_PORT GPIOB
-#define USB_VBUS_PIN GPIO13
-#define USB_VBUS_IRQ NVIC_EXTI15_10_IRQ
+#define TMS_SET_MODE() gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, \
+ GPIO_PUPD_NONE, TMS_PIN);
+#define SWDIO_MODE_FLOAT() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_INPUT, \
+ GPIO_PUPD_NONE, SWDIO_PIN);
-#define LED_PORT GPIOB
-#define LED_PORT_UART GPIOB
-#define LED_UART GPIO2
-#define LED_IDLE_RUN GPIO10
-#define LED_ERROR GPIO11
+#define SWDIO_MODE_DRIVE() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_OUTPUT, \
+ GPIO_PUPD_NONE, SWDIO_PIN);
-#define USB_DRIVER stm32f103_usb_driver
-#define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ
-#define USB_ISR usb_lp_can_rx0_isr
+
+#define USB_DRIVER stm32f107_usb_driver
+#define USB_IRQ NVIC_OTG_FS_IRQ
+#define USB_ISR otg_fs_isr
/* Interrupt priorities. Low numbers are high priority.
* For now USART1 preempts USB which may spin while buffer is drained.
* TIM3 is used for traceswo capture and must be highest priority.
*/
#define IRQ_PRI_USB (2 << 4)
#define IRQ_PRI_USBUSART (1 << 4)
-#define IRQ_PRI_USB_VBUS (14 << 4)
#define IRQ_PRI_TRACE (0 << 4)
-#define USBUSART USART1
-#define USBUSART_CR1 USART1_CR1
-#define USBUSART_IRQ NVIC_USART1_IRQ
-#define USBUSART_APB_ENR RCC_APB2ENR
-#define USBUSART_CLK_ENABLE RCC_APB2ENR_USART1EN
-#define USBUSART_PORT GPIOA
-#define USBUSART_TX_PIN GPIO9
-#define USBUSART_ISR usart1_isr
+#define USBUSART USART3
+#define USBUSART_CR1 USART3_CR1
+#define USBUSART_IRQ NVIC_USART3_IRQ
+#define USBUSART_APB_ENR RCC_APB1ENR
+#define USBUSART_CLK_ENABLE RCC_APB1ENR_USART3EN
+#define USBUSART_TX_PORT GPIOD
+#define USBUSART_TX_PIN GPIO8
+#define USBUSART_RX_PORT GPIOD
+#define USBUSART_RX_PIN GPIO9
+#define USBUSART_ISR usart3_isr
+
+#define UART_PIN_SETUP() do { \
+ gpio_mode_setup(USBUSART_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \
+ USBUSART_TX_PIN); \
+ gpio_mode_setup(USBUSART_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \
+ USBUSART_RX_PIN); \
+ gpio_set_af(USBUSART_TX_PORT, GPIO_AF7, USBUSART_TX_PIN); \
+ gpio_set_af(USBUSART_RX_PORT, GPIO_AF7, USBUSART_RX_PIN); \
+ } while(0)
#define TRACE_TIM TIM3
#define TRACE_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN)
@@ -180,7 +193,7 @@ static inline void _gpio_set(u32 gpioport, u16 gpios)
static inline void _gpio_clear(u32 gpioport, u16 gpios)
{
- GPIO_BRR(gpioport) = gpios;
+ GPIO_BSRR(gpioport) = gpios<<16;
}
#define gpio_clear _gpio_clear
@@ -193,6 +206,6 @@ static inline u16 _gpio_get(u32 gpioport, u16 gpios)
#endif
-#define disconnect_usb() gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT, 0, USB_PU_PIN);
+#define disconnect_usb() do {usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0)
void assert_boot_pin(void);
-void setup_vbus_irq(void);
+#define setup_vbus_irq()