aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmaple/usb/usb.c30
-rw-r--r--libmaple/usb/usb.h3
-rw-r--r--libmaple/usb/usb_callbacks.c4
-rw-r--r--libmaple/usb/usb_hardware.c21
-rw-r--r--libmaple/usb/usb_hardware.h19
5 files changed, 19 insertions, 58 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 5c4c35a..173673e 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -36,6 +36,7 @@
#include "gpio.h"
#include "usb_hardware.h"
#include "delay.h"
+#include "nvic.h"
#include "usb_config.h"
#include "usb_callbacks.h"
@@ -111,9 +112,9 @@ void usb_cdcacm_enable(gpio_dev *disc_dev, uint8 disc_bit) {
}
void usb_cdcacm_disable(gpio_dev *disc_dev, uint8 disc_bit) {
- // These are just guesses about how to do this
- // TODO: real disable function
- usbDsbISR();
+ // These are just guesses about how to do this, but it seems to work.
+ // TODO: verify this with USB spec
+ nvic_irq_disable(NVIC_USB_LP_CAN_RX0);
gpio_write_bit(disc_dev, disc_bit, 1);
}
@@ -218,27 +219,6 @@ RESULT usbPowerOff(void) {
return USB_SUCCESS;
}
-
-// These two functions (usbEnbISR/usbDsbISR) are implementented in ST style,
-// and at least the DsbISR doesn't seem to work?
-void usbEnbISR(void) {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = TRUE;
- nvicInit(&NVIC_InitStructure);
-}
-
-void usbDsbISR(void) {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = FALSE;
- nvicInit(&NVIC_InitStructure);
-}
-
/* overloaded ISR routine, this is the main usb ISR */
void __irq_usb_lp_can_rx0(void) {
wIstr = _GetISTR();
@@ -321,7 +301,7 @@ if (wIstr & ISTR_CTR & wInterrupt_Mask) {
void usbWaitReset(void) {
delay_us(RESET_DELAY);
- systemHardReset();
+ nvic_sys_reset();
}
/* This low-level send bytes function is NON-BLOCKING; blocking behavior, with
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index c3d587d..9498dcf 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -66,9 +66,6 @@ void usbResume(RESUME_STATE);
RESULT usbPowerOn(void);
RESULT usbPowerOff(void);
-void usbDsbISR(void);
-void usbEnbISR(void);
-
/* overloaded ISR routine, this is the main usb ISR */
void __irq_usb_lp_can_rx0(void);
void usbWaitReset(void);
diff --git a/libmaple/usb/usb_callbacks.c b/libmaple/usb/usb_callbacks.c
index 890a97f..b2edd8a 100644
--- a/libmaple/usb/usb_callbacks.c
+++ b/libmaple/usb/usb_callbacks.c
@@ -1,5 +1,7 @@
/* insert license */
+#include "nvic.h"
+
#include "usb_callbacks.h"
#include "usb_lib.h"
#include "descriptors.h"
@@ -140,7 +142,7 @@ void usbInit(void) {
wInterrupt_Mask = ISR_MSK;
_SetCNTR(wInterrupt_Mask);
- usbEnbISR();
+ nvic_irq_enable(NVIC_USB_LP_CAN_RX0);
bDeviceState = UNCONNECTED;
}
diff --git a/libmaple/usb/usb_hardware.c b/libmaple/usb/usb_hardware.c
index 9a7d12c..e7fd078 100644
--- a/libmaple/usb/usb_hardware.c
+++ b/libmaple/usb/usb_hardware.c
@@ -31,6 +31,7 @@
*
*/
+#include "nvic.h"
#include "usb_hardware.h"
void nvicInit(NVIC_InitTypeDef* NVIC_InitStruct) {
@@ -40,9 +41,7 @@ void nvicInit(NVIC_InitTypeDef* NVIC_InitStruct) {
u32 tmppre = 0;
u32 tmpsub = 0x0F;
- SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE;
- NVIC_TypeDef* rNVIC = (NVIC_TypeDef *) NVIC_BASE;
-
+ SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE_ADDR;
/* Compute the Corresponding IRQ Priority -------------------------------*/
tmppriority = (0x700 - (rSCB->AIRCR & (u32)0x700))>> 0x08;
@@ -57,33 +56,31 @@ void nvicInit(NVIC_InitTypeDef* NVIC_InitStruct) {
tmppriority = ((u32)tmppriority) <<
((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
- tmpreg = rNVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
+ tmpreg = NVIC_BASE->IP[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
tmpmask = (u32)0xFF <<
((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
tmpreg &= ~tmpmask;
tmppriority &= tmpmask;
tmpreg |= tmppriority;
- rNVIC->IPR[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
+ NVIC_BASE->IP[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
/* Enable the Selected IRQ Channels -------------------------------------*/
- rNVIC->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
+ NVIC_BASE->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
(u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
}
void nvicDisableInterrupts() {
- NVIC_TypeDef* rNVIC = (NVIC_TypeDef *) NVIC_BASE;
- rNVIC->ICER[0] = 0xFFFFFFFF;
- rNVIC->ICER[1] = 0xFFFFFFFF;
- rNVIC->ICPR[0] = 0xFFFFFFFF;
- rNVIC->ICPR[1] = 0xFFFFFFFF;
+ nvic_irq_disable_all();
+ NVIC_BASE->ICPR[0] = 0xFFFFFFFF;
+ NVIC_BASE->ICPR[1] = 0xFFFFFFFF;
/* Disable the systick timer, which operates separately from NVIC */
SET_REG(STK_CTRL,0x04);
}
void systemHardReset(void) {
- SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE;
+ SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE_ADDR;
typedef void (*funcPtr)(void);
/* Reset */
diff --git a/libmaple/usb/usb_hardware.h b/libmaple/usb/usb_hardware.h
index cfead1a..6f347bb 100644
--- a/libmaple/usb/usb_hardware.h
+++ b/libmaple/usb/usb_hardware.h
@@ -36,9 +36,8 @@
#define USB_PACKET_BUFFER ((u32)0x40006000)
-#define SCS_BASE ((u32)0xE000E000)
-#define NVIC_BASE (SCS_BASE + 0x0100)
-#define SCB_BASE (SCS_BASE + 0x0D00)
+#define SCS_BASE_ADDR ((u32)0xE000E000)
+#define SCB_BASE_ADDR (SCS_BASE_ADDR + 0x0D00)
#define SCS 0xE000E000
#define NVIC (SCS+0x100)
@@ -86,20 +85,6 @@ typedef struct
#define pRCC ((RCC_RegStruct *) RCC_BASE)
typedef struct {
- vu32 ISER[2];
- u32 RESERVED0[30];
- vu32 ICER[2];
- u32 RSERVED1[30];
- vu32 ISPR[2];
- u32 RESERVED2[30];
- vu32 ICPR[2];
- u32 RESERVED3[30];
- vu32 IABR[2];
- u32 RESERVED4[62];
- vu32 IPR[15];
-} NVIC_TypeDef;
-
-typedef struct {
u8 NVIC_IRQChannel;
u8 NVIC_IRQChannelPreemptionPriority;
u8 NVIC_IRQChannelSubPriority;