Improve system routines API for STM32F103
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2016-05-16 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* example-cdc/sys.c (nvic_enable_vector): Remove.
|
||||||
|
(usb_lld_sys_init): Don't setup NVIC priority.
|
||||||
|
(sys_version): sys version 3.0.
|
||||||
|
|
||||||
2016-05-16 NIIBE Yutaka <gniibe@fsij.org>
|
2016-05-16 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* chopstx.h (CHOPSTX_EXIT_SUCCESS, CHOPSTX_EXIT_CANCELED)
|
* chopstx.h (CHOPSTX_EXIT_SUCCESS, CHOPSTX_EXIT_CANCELED)
|
||||||
|
|||||||
@@ -65,24 +65,31 @@ usb_intr (void *arg)
|
|||||||
chopstx_intr_t interrupt;
|
chopstx_intr_t interrupt;
|
||||||
|
|
||||||
(void)arg;
|
(void)arg;
|
||||||
usb_lld_init (0x80); /* Bus powered. */
|
#if defined(OLDER_SYS_H)
|
||||||
chopstx_claim_irq (&interrupt, INTR_REQ_USB);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Historically (before sys < 3.0), NVIC priority setting for USB
|
||||||
|
* interrupt was done in usb_lld_sys_init. Thus this code.
|
||||||
|
*
|
||||||
* When USB interrupt occurs between usb_lld_init (which assumes
|
* When USB interrupt occurs between usb_lld_init (which assumes
|
||||||
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
* ISR) and chopstx_claim_irq (which clears pending interrupt),
|
||||||
* invocation of usb_interrupt_handler won't occur.
|
* invocation of usb_interrupt_handler won't occur.
|
||||||
*
|
*
|
||||||
* We can't call usb_lld_init after chopstx_claim_irq, as
|
|
||||||
* usb_lld_init does its own setting for NVIC. Calling
|
|
||||||
* chopstx_claim_irq after usb_lld_init overrides that.
|
|
||||||
*
|
|
||||||
* Calling usb_interrupt_handler is no harm even if there were no
|
* Calling usb_interrupt_handler is no harm even if there were no
|
||||||
* interrupts, thus, we call it unconditionally here, just in case
|
* interrupts, thus, we call it unconditionally here, just in case
|
||||||
* if there is a request.
|
* if there is a request.
|
||||||
*
|
*
|
||||||
|
* We can't call usb_lld_init after chopstx_claim_irq, as
|
||||||
|
* usb_lld_init does its own setting for NVIC. Calling
|
||||||
|
* chopstx_claim_irq after usb_lld_init overrides that.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
usb_lld_init (0x80); /* Bus powered. */
|
||||||
|
chopstx_claim_irq (&interrupt, INTR_REQ_USB);
|
||||||
usb_interrupt_handler ();
|
usb_interrupt_handler ();
|
||||||
|
#else
|
||||||
|
chopstx_claim_irq (&interrupt, INTR_REQ_USB);
|
||||||
|
usb_lld_init (0x80); /* Bus powered. */
|
||||||
|
#endif
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* sys.c - system routines for the initial page for STM32F103.
|
* sys.c - system routines for the initial page for STM32F103.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013, 2014, 2015 Flying Stone Technology
|
* Copyright (C) 2013, 2014, 2015, 2016 Flying Stone Technology
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||||
*
|
*
|
||||||
* Copying and distribution of this file, with or without modification,
|
* Copying and distribution of this file, with or without modification,
|
||||||
@@ -19,39 +19,6 @@
|
|||||||
|
|
||||||
#include "clk_gpio_init-stm32.c"
|
#include "clk_gpio_init-stm32.c"
|
||||||
|
|
||||||
#define CORTEX_PRIORITY_BITS 4
|
|
||||||
#define CORTEX_PRIORITY_MASK(n) ((n) << (8 - CORTEX_PRIORITY_BITS))
|
|
||||||
#define USB_LP_CAN1_RX0_IRQn 20
|
|
||||||
#define STM32_USB_IRQ_PRIORITY 11
|
|
||||||
|
|
||||||
struct NVIC {
|
|
||||||
volatile uint32_t ISER[8];
|
|
||||||
volatile uint32_t unused1[24];
|
|
||||||
volatile uint32_t ICER[8];
|
|
||||||
volatile uint32_t unused2[24];
|
|
||||||
volatile uint32_t ISPR[8];
|
|
||||||
volatile uint32_t unused3[24];
|
|
||||||
volatile uint32_t ICPR[8];
|
|
||||||
volatile uint32_t unused4[24];
|
|
||||||
volatile uint32_t IABR[8];
|
|
||||||
volatile uint32_t unused5[56];
|
|
||||||
volatile uint32_t IPR[60];
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct NVIC *const NVICBase = ((struct NVIC *const)0xE000E100);
|
|
||||||
#define NVIC_ISER(n) (NVICBase->ISER[n >> 5])
|
|
||||||
#define NVIC_ICPR(n) (NVICBase->ICPR[n >> 5])
|
|
||||||
#define NVIC_IPR(n) (NVICBase->IPR[n >> 2])
|
|
||||||
|
|
||||||
static void
|
|
||||||
nvic_enable_vector (uint32_t n, uint32_t prio)
|
|
||||||
{
|
|
||||||
unsigned int sh = (n & 3) << 3;
|
|
||||||
|
|
||||||
NVIC_IPR (n) = (NVIC_IPR(n) & ~(0xFF << sh)) | (prio << sh);
|
|
||||||
NVIC_ICPR (n) = 1 << (n & 0x1F);
|
|
||||||
NVIC_ISER (n) = 1 << (n & 0x1F);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usb_cable_config (int enable)
|
usb_cable_config (int enable)
|
||||||
@@ -118,13 +85,6 @@ usb_lld_sys_init (void)
|
|||||||
|
|
||||||
usb_cable_config (1);
|
usb_cable_config (1);
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
|
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
|
||||||
nvic_enable_vector (USB_LP_CAN1_RX0_IRQn,
|
|
||||||
CORTEX_PRIORITY_MASK (STM32_USB_IRQ_PRIORITY));
|
|
||||||
/*
|
|
||||||
* Note that we also have other IRQ(s):
|
|
||||||
* USB_HP_CAN1_TX_IRQn (for double-buffered or isochronous)
|
|
||||||
* USBWakeUp_IRQn (suspend/resume)
|
|
||||||
*/
|
|
||||||
RCC->APB1RSTR = RCC_APB1RSTR_USBRST;
|
RCC->APB1RSTR = RCC_APB1RSTR_USBRST;
|
||||||
RCC->APB1RSTR = 0;
|
RCC->APB1RSTR = 0;
|
||||||
}
|
}
|
||||||
@@ -423,8 +383,8 @@ handler vector[] __attribute__ ((section(".vectors"))) = {
|
|||||||
const uint8_t sys_version[8] __attribute__((section(".sys.version"))) = {
|
const uint8_t sys_version[8] __attribute__((section(".sys.version"))) = {
|
||||||
3*2+2, /* bLength */
|
3*2+2, /* bLength */
|
||||||
0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE */
|
0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE */
|
||||||
/* sys version: "2.1" */
|
/* sys version: "3.0" */
|
||||||
'2', 0, '.', 0, '1', 0,
|
'3', 0, '.', 0, '0', 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t __attribute__((section(".sys.board_id")))
|
const uint32_t __attribute__((section(".sys.board_id")))
|
||||||
|
|||||||
Reference in New Issue
Block a user