aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/source/bootloader.rst58
-rw-r--r--docs/source/conf.py8
-rw-r--r--docs/source/epilog.rst8
-rw-r--r--docs/source/index.rst2
-rw-r--r--docs/source/language.rst4
-rw-r--r--docs/source/libmaple-api.rst5
-rw-r--r--docs/source/maple-quickstart.rst5
-rw-r--r--docs/source/troubleshooting.rst8
-rw-r--r--docs/source/unix-toolchain.rst4
-rw-r--r--libmaple/adc.c2
-rw-r--r--libmaple/dac.c4
-rw-r--r--libmaple/dac.h4
-rw-r--r--libmaple/exti.c2
-rw-r--r--libmaple/flash.h3
-rw-r--r--libmaple/fsmc.c4
-rw-r--r--libmaple/fsmc.h4
-rw-r--r--libmaple/gpio.c2
-rw-r--r--libmaple/nvic.c2
-rw-r--r--libmaple/nvic.h3
-rw-r--r--libmaple/rcc.h3
-rw-r--r--libmaple/ring_buffer.h3
-rw-r--r--libmaple/spi.h1
-rw-r--r--libmaple/systick.c2
-rw-r--r--libmaple/timers.c2
-rw-r--r--libmaple/usart.c2
-rw-r--r--libmaple/usart.h1
-rw-r--r--libmaple/usb/usb_hardware.c157
-rw-r--r--libmaple/util.c2
28 files changed, 165 insertions, 140 deletions
diff --git a/docs/source/bootloader.rst b/docs/source/bootloader.rst
index 17cd34b..9280c68 100644
--- a/docs/source/bootloader.rst
+++ b/docs/source/bootloader.rst
@@ -23,22 +23,22 @@ remake of the core library as well as the upload process. Some of
these changes are aesthetic, refactoring and reorganization. Some are
performance minded. The changes to the bootloader, however, were
implemented to solve some really gritty cross platform issues. Before
-delving in to how the Rev1 bootloader worked and how the Rev 3
+delving in to how the Rev 1 bootloader worked and how the Rev 3
bootloader works now, lets look at the features common to both of them
and touch a bit on the Arduino setup. This is a fairly involved
explanation, with a lot of details that are likely only interesting to
a few. If you just want to get the rough idea, skim this article. If
you want to start hacking on the bootloader, get in touch with us to
get even more info on how this all works. Of course, you can always
-checkout the code at github!
+`check out the code at github <http://github.com/leaflabs/libmaple>`_!
Arduino
-^^^^^^^
+-------
Arduino is based off of AVR series micro controllers, most of which
lack USB support. Thus, boards like the Duemilanove add USB capability
via an FTDI USB to Serial converter chip. This chip interfaces with
-the AVR over…serial. When you plug an Arduino into a computer only an
+the AVR over…serial. When you plug an Arduino into a computer, only an
FTDI driver is needed. Since the FTDI chip is separate from the AVR,
you can reset the Arduino without closing this USB connection with the
FTDI chip. To program an Arduino, the host machine sends a command
@@ -50,8 +50,8 @@ and off you go. The whole process is quick, the bootloader doesn’t
live for very long, and will exit almost immediately if no upload
commands are received.
-Maple Rev1: The Horror...
-^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Maple Rev 1: The Horror...
+---------------------------
Maple is based off the STM32 (ARM cortex M3) series chips, which do
have embedded USB support. Thus, Maple doesn’t need the extra FTDI
@@ -71,7 +71,7 @@ serial port transactions. There was no reset necessary for uploads. No
waiting. The bootloader was always running the background, ready to
receive commands.
-The problem was that ONLY Linux did this. Windows refused to attach
+The problem was that *only* Linux did this. Windows refused to attach
more than one driver to a single USB device without repackaging the
DFU and CDC ACM into a single IAD Compound Device. It's not terribly
important what this means, except for two things.
@@ -86,35 +86,35 @@ were going to have to write some custom drivers across several
platforms to make everything work this way.
Maple Rev3
-^^^^^^^^^^
+----------
Maple Rev 3 takes a completely different tack, more along the lines of
Arduino. In Rev 3, the device resets into bootloader mode, which
-stays alive for a few moments to receive commands and then jumps to
-user code. The bootloader is implemented as a DFU device – just a DFU
-device, no serial port. This requires one driver for windows
-(:file:`drivers/mapleDrv/dfu`). As part of the :ref:`libmaple`
-library, user code is automatically supplied with serial support via
-some behind the scenes work that happens automatically when you
-compile (``setupUSB()`` is appended to ``setup()``). This user mode
-code only implements a CDC ACM class USB device, giving you functions
-like ``Usb.print()``. Separating these two modes fixed the driver
-issue, there are no complicated compound usb device nonsense, and the
-scheme works well across platforms, requiring only two drivers (serial
-and DFU) on Windows.
+stays alive for a few moments to receive commands, and then jumps to
+user code. The bootloader is implemented as a DFU device -- just a DFU
+device, no serial port. This requires one driver for Windows
+(:file:`drivers/mapleDrv/dfu` in the Windows IDE directory). As part
+of the :ref:`libmaple <libmaple>` library, user code is automatically
+supplied with serial support via some behind the scenes work that
+happens automatically when you compile (``setupUSB()`` is appended to
+``setup()``). This user mode code only implements a CDC ACM class USB
+device, giving you functions like ``Usb.print()``. Separating these
+two modes fixed the driver issue, required no complicated compound USB
+device nonsense, and works well across platforms, requiring only two
+drivers (serial and DFU) on Windows.
However, it is no longer possible to upload code at will, since there
is no bootloader quietly listening in the background. Instead you have
to reset the board, then initiate a DFU transaction. This reset is
performed automatically by the IDE by sending a command over the USB
-serial port. You can generate this reset on your own using a python
+serial port. You can generate this reset on your own using a Python
script or some other scheme. All you need do is:
-1. Pulse DTR (high and then low, so that youve created a negative
+1. Pulse DTR (high and then low, so that you've created a negative
edge)
-2. Write “1EAF” in ASCII over the serial pipe. This will cause Maple
+2. Write "1EAF" in ASCII over the serial pipe. This will cause Maple
to reset. Only the first 4 bytes after a negative edge of DTR are
- checked for this command, so its important you actually create a
+ checked for this command, so it's important you actually create a
negative edge, rather than just ensuring DTR is low.
After the reset, the host OS takes a few moments (.5-2 seconds) to
@@ -122,8 +122,8 @@ re-enumerate the device as DFU. This delay is unpredictable, and its
the reason the bootloader on Maple Rev3 stays alive for so
long. Sometimes the bootloader was exiting before the OS had even
enumerated the device! Once in bootloader mode, however,
-:command:`dfu-util` uploads your sketch into either flash or ram (dfu
-alternate setting 0 or 1 respectively) and resets the board again.
-This time, however, no DFU transaction is initiated and the bootloader
-gives way to user code, closing down the DFU pipe and bringing up the
-USB serial.
+:command:`dfu-util` uploads your sketch into either flash or RAM (DFU
+alternate setting 0 or 1, respectively) and resets the board again.
+This time, however, no DFU transaction is initiated, and the
+bootloader gives way to user code, closing down the DFU pipe and
+bringing up the USB serial.
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 7f2b3b4..5fcb939 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -68,7 +68,11 @@ release = '0.0.7'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
-exclude_patterns = []
+exclude_patterns = ['epilog.rst']
+
+# Included at the end of every source file that is read.
+with open('epilog.rst', 'r') as ep:
+ rst_epilog = ep.read()
# The reST default role (used for this markup: `text`) to use for all
# documents.
@@ -91,6 +95,8 @@ pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
+# Warn about all references where the target cannot be found.
+#nitpicky = True
# -- Options for HTML output --------------------------------------------------
diff --git a/docs/source/epilog.rst b/docs/source/epilog.rst
new file mode 100644
index 0000000..0e430c8
--- /dev/null
+++ b/docs/source/epilog.rst
@@ -0,0 +1,8 @@
+.. This file automatically gets included at the end of every file, so
+.. it's useful for common references, etc.
+
+.. Common URL references
+.. _forum: http://forums.leaflabs.com
+.. _contact: http://leaflabs.com/contact/
+.. _setup(): http://arduino.cc/en/Reference/Setup
+.. _loop(): http://arduino.cc/en/Reference/Loop
diff --git a/docs/source/index.rst b/docs/source/index.rst
index cdf151d..e5af08f 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -28,9 +28,9 @@ Table of contents:
Maple Language Reference <language>
Maple Library Reference <libraries>
libmaple Documentation and APIs <libmaple>
- Maple bootloader <bootloader>
Troubleshooting <troubleshooting>
Hardware-Specific Documentation <hardware>
+ Maple bootloader <bootloader>
Known Problems <errata>
Indices and tables
diff --git a/docs/source/language.rst b/docs/source/language.rst
index 7bf71c6..8115d6b 100644
--- a/docs/source/language.rst
+++ b/docs/source/language.rst
@@ -210,9 +210,7 @@ Arduino Documentation Links
typedef uint16 word;
-
-.. _setup(): http://arduino.cc/en/Reference/Setup
-.. _loop(): http://arduino.cc/en/Reference/Loop
+.. setup()/loop() are part of the standard rst_epilog in conf.py
.. _if: http://arduino.cc/en/Reference/If
.. _if...else: http://arduino.cc/en/Reference/Else
.. _for: http://arduino.cc/en/Reference/For
diff --git a/docs/source/libmaple-api.rst b/docs/source/libmaple-api.rst
index df9a4d9..af283cb 100644
--- a/docs/source/libmaple-api.rst
+++ b/docs/source/libmaple-api.rst
@@ -4,4 +4,7 @@
libmaple API reference
========================
-Stub.
+This page documents the lower-level features of libmaple, which may be
+of use to programmers who don't wish to use the Arduino-style
+environment provided by the `Maple IDE <maple-ide-install>`_.
+
diff --git a/docs/source/maple-quickstart.rst b/docs/source/maple-quickstart.rst
index 9337611..20d84a0 100644
--- a/docs/source/maple-quickstart.rst
+++ b/docs/source/maple-quickstart.rst
@@ -13,10 +13,7 @@ that computer.
If you have trouble along the way, try the :ref:`troubleshooting page
<troubleshooting>` for help with some common problems. If all else
-fails, try our `forum`_, or `contact us directly
-<http://leaflabs.com/contact>`_!
-
-.. _forum: http://forums.leaflabs.com
+fails, try our `forum`_, or `contact us directly <contact>`_!
The steps are:
diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst
index 7fdfe17..b878ae4 100644
--- a/docs/source/troubleshooting.rst
+++ b/docs/source/troubleshooting.rst
@@ -133,10 +133,10 @@ Common compiler problems
``undefined reference to setup()/loop()``
- Your sketch/program either does not include one of the :ref:`setup
- <setup()>` or :ref:`loop <loop()>` functions, or it was not found
- by the compiler. Your program must include both ``void setup()``
- and ``void loop()`` functions; they don't have to do anything, but
+ Your sketch/program either does not include one of the `setup
+ <setup()>`_ or `loop <loop()>`_ functions, or it was not found by
+ the compiler. Your program must include both ``void setup()`` and
+ ``void loop()`` functions; they don't have to do anything, but
they **must** be there.
You can start with an example program (to see one in the IDE,
diff --git a/docs/source/unix-toolchain.rst b/docs/source/unix-toolchain.rst
index 0328a5c..295090e 100644
--- a/docs/source/unix-toolchain.rst
+++ b/docs/source/unix-toolchain.rst
@@ -19,9 +19,7 @@ editing your shell startup script (.bashrc, .tcshrc, etc.) and using
generic installation/setup issues, the `IDE install
<http://leaflabs.com/docs/libmaple/install/>`_ and
:ref:`troubleshooting` pages may be helpful. If all else fails, try
-our `forum`_, or `contact us directly <http://leaflabs.com/contact>`_!
-
-.. _forum: http://forums.leaflabs.com
+our `forum`_, or `contact us directly <contact>`_!
We currently have instructions for 32- and 64-bit Linux and OS X Snow
Leopard. If you're on another Unix platform, Windows, or an earlier
diff --git a/libmaple/adc.c b/libmaple/adc.c
index 9b21b49..b70c8bd 100644
--- a/libmaple/adc.c
+++ b/libmaple/adc.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file adc.c
- *
* @brief Analog to digital converter routines
*/
diff --git a/libmaple/dac.c b/libmaple/dac.c
index 4c00edb..7f6101d 100644
--- a/libmaple/dac.c
+++ b/libmaple/dac.c
@@ -27,6 +27,10 @@
#include "gpio.h"
#include "dac.h"
+/**
+ * @brief DAC peripheral routines.
+ */
+
/* Only one, so global to this file */
DAC_Map *dac = (DAC_Map*)(DAC_BASE);
diff --git a/libmaple/dac.h b/libmaple/dac.h
index 17b67b7..9c84f2e 100644
--- a/libmaple/dac.h
+++ b/libmaple/dac.h
@@ -26,6 +26,10 @@
* See ../notes/dac.txt for more info
*/
+/**
+ * @file dac.h
+ */
+
#ifndef _DAC_H_
#define _DAC_H_
diff --git a/libmaple/exti.c b/libmaple/exti.c
index acd7c94..496f0a1 100644
--- a/libmaple/exti.c
+++ b/libmaple/exti.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file exti.c
- *
* @brief External interrupt control routines
*/
diff --git a/libmaple/flash.h b/libmaple/flash.h
index 54bda0e..7b74c83 100644
--- a/libmaple/flash.h
+++ b/libmaple/flash.h
@@ -24,7 +24,8 @@
/**
- * @brief basic stm32 flash setup routines
+ * @file flash.h
+ * @brief basic stm32 flash setup routines
*/
#ifndef _FLASH_H_
diff --git a/libmaple/fsmc.c b/libmaple/fsmc.c
index 301a90d..49526f4 100644
--- a/libmaple/fsmc.c
+++ b/libmaple/fsmc.c
@@ -22,6 +22,10 @@
* THE SOFTWARE.
*****************************************************************************/
+/**
+ * @brief
+ */
+
#include "libmaple.h"
#include "rcc.h"
#include "gpio.h"
diff --git a/libmaple/fsmc.h b/libmaple/fsmc.h
index 471cad1..e83b529 100644
--- a/libmaple/fsmc.h
+++ b/libmaple/fsmc.h
@@ -26,6 +26,10 @@
* See ../notes/fsmc.txt for more info
*/
+/**
+ * @file fsmc.h
+ */
+
#ifndef _FSMC_H_
#define _FSMC_H_
diff --git a/libmaple/gpio.c b/libmaple/gpio.c
index f7aee2b..3940837 100644
--- a/libmaple/gpio.c
+++ b/libmaple/gpio.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file gpio.c
- *
* @brief GPIO initialization routine
*/
diff --git a/libmaple/nvic.c b/libmaple/nvic.c
index 5b32d16..fc77054 100644
--- a/libmaple/nvic.c
+++ b/libmaple/nvic.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file nvic.c
- *
* @brief Nested interrupt controller routines
*/
diff --git a/libmaple/nvic.h b/libmaple/nvic.h
index 3cdac5a..d99e57d 100644
--- a/libmaple/nvic.h
+++ b/libmaple/nvic.h
@@ -23,7 +23,8 @@
*****************************************************************************/
/**
- * @brief Nested interrupt controller defines and prototypes
+ * @file nvic.h
+ * @brief Nested interrupt controller defines and prototypes
*/
#ifndef _NVIC_H_
diff --git a/libmaple/rcc.h b/libmaple/rcc.h
index f245fe9..a12f4b4 100644
--- a/libmaple/rcc.h
+++ b/libmaple/rcc.h
@@ -23,7 +23,8 @@
*****************************************************************************/
/**
- * @brief reset and clock control definitions and prototypes
+ * @file rcc.h
+ * @brief reset and clock control definitions and prototypes
*/
#ifndef _RCC_H_
diff --git a/libmaple/ring_buffer.h b/libmaple/ring_buffer.h
index 6a54747..aa4f83f 100644
--- a/libmaple/ring_buffer.h
+++ b/libmaple/ring_buffer.h
@@ -1,5 +1,6 @@
/**
- * @brief simple circular buffer
+ * @file ring_buffer.h
+ * @brief simple circular buffer
*/
#ifndef _RING_BUFFER_H_
diff --git a/libmaple/spi.h b/libmaple/spi.h
index d1973c5..db8aa9c 100644
--- a/libmaple/spi.h
+++ b/libmaple/spi.h
@@ -23,6 +23,7 @@
*****************************************************************************/
/**
+ * @file spi.h
* @brief libmaple serial peripheral interface (SPI) prototypes and
* declarations
*/
diff --git a/libmaple/systick.c b/libmaple/systick.c
index 12a3e22..7935cc0 100644
--- a/libmaple/systick.c
+++ b/libmaple/systick.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file systick.c
- *
* @brief System timer interrupt handler and initialization routines
*/
diff --git a/libmaple/timers.c b/libmaple/timers.c
index 04bfa9f..5b97e20 100644
--- a/libmaple/timers.c
+++ b/libmaple/timers.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file timers.c
- *
* @brief General timer routines
*/
diff --git a/libmaple/usart.c b/libmaple/usart.c
index 34095f8..e63e8f6 100644
--- a/libmaple/usart.c
+++ b/libmaple/usart.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file usart.c
- *
* @brief USART control routines
*/
diff --git a/libmaple/usart.h b/libmaple/usart.h
index 593fb8f..49978e9 100644
--- a/libmaple/usart.h
+++ b/libmaple/usart.h
@@ -23,6 +23,7 @@
*****************************************************************************/
/**
+ * @file usart.h
* @brief USART definitions and prototypes
*/
diff --git a/libmaple/usb/usb_hardware.c b/libmaple/usb/usb_hardware.c
index 2f37df6..d0cd693 100644
--- a/libmaple/usb/usb_hardware.c
+++ b/libmaple/usb/usb_hardware.c
@@ -1,4 +1,4 @@
-/* *****************************************************************************
+/******************************************************************************
* The MIT License
*
* Copyright (c) 2010 LeafLabs LLC.
@@ -20,10 +20,10 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- * ****************************************************************************/
+*****************************************************************************/
/**
- * @file hardware.c
+ * @file usb_hardware.c
*
* @brief init routines to setup clocks and interrupts for usb.
*
@@ -32,97 +32,106 @@
#include "usb_hardware.h"
void setPin(u32 bank, u8 pin) {
- u32 pinMask = 0x1 << (pin);
- SET_REG(GPIO_BSRR(bank),pinMask);
+ u32 pinMask = 0x1 << (pin);
+ SET_REG(GPIO_BSRR(bank),pinMask);
}
void resetPin(u32 bank, u8 pin) {
- u32 pinMask = 0x1 << (16+pin);
- SET_REG(GPIO_BSRR(bank),pinMask);
+ u32 pinMask = 0x1 << (16+pin);
+ SET_REG(GPIO_BSRR(bank),pinMask);
}
void systemReset(void) {
- SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x00000001);
- SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xF8FF0000);
- SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFEF6FFFF);
- SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFFFBFFFF);
- SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xFF80FFFF);
+ SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x00000001);
+ SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xF8FF0000);
+ SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFEF6FFFF);
+ SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFFFBFFFF);
+ SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xFF80FFFF);
- SET_REG(RCC_CIR, 0x00000000); /* disable all RCC interrupts */
+ SET_REG(RCC_CIR, 0x00000000); // disable all RCC interrupts
}
void setupCLK (void) {
- /* enable HSE */
- SET_REG(RCC_CR,GET_REG(RCC_CR) | 0x00010001);
- while ((GET_REG(RCC_CR) & 0x00020000) == 0); /* for it to come on */
-
- /* Configure PLL */
- SET_REG(RCC_CFGR,GET_REG(RCC_CFGR) | 0x001D0400); /* pll=72Mhz,APB1=36Mhz,AHB=72Mhz */
- SET_REG(RCC_CR,GET_REG(RCC_CR) | 0x01000000); /* enable the pll */
- while ((GET_REG(RCC_CR) & 0x03000000) == 0); /* wait for it to come on */
-
- /* Set SYSCLK as PLL */
- SET_REG(RCC_CFGR,GET_REG(RCC_CFGR) | 0x00000002);
- while ((GET_REG(RCC_CFGR) & 0x00000008) == 0); /* wait for it to come on */
+ /* enable HSE */
+ SET_REG(RCC_CR,GET_REG(RCC_CR) | 0x00010001);
+ /* for it to come on */
+ while ((GET_REG(RCC_CR) & 0x00020000) == 0);
+
+ /* Configure PLL */
+ /* pll=72Mhz,APB1=36Mhz,AHB=72Mhz */
+ SET_REG(RCC_CFGR,GET_REG(RCC_CFGR) | 0x001D0400);
+ /* enable the pll */
+ SET_REG(RCC_CR,GET_REG(RCC_CR) | 0x01000000);
+ /* wait for it to come on */
+ while ((GET_REG(RCC_CR) & 0x03000000) == 0);
+
+ /* Set SYSCLK as PLL */
+ SET_REG(RCC_CFGR,GET_REG(RCC_CFGR) | 0x00000002);
+ /* wait for it to come on */
+ while ((GET_REG(RCC_CFGR) & 0x00000008) == 0);
}
void nvicInit(NVIC_InitTypeDef* NVIC_InitStruct) {
- u32 tmppriority = 0x00;
- u32 tmpreg = 0x00;
- u32 tmpmask = 0x00;
- u32 tmppre = 0;
- u32 tmpsub = 0x0F;
-
- SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE;
- NVIC_TypeDef* rNVIC = (NVIC_TypeDef *) NVIC_BASE;
-
-
- /* Compute the Corresponding IRQ Priority --------------------------------*/
- tmppriority = (0x700 - (rSCB->AIRCR & (u32)0x700))>> 0x08;
- tmppre = (0x4 - tmppriority);
- tmpsub = tmpsub >> tmppriority;
-
- tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
- tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
-
- tmppriority = tmppriority << 0x04;
- tmppriority = ((u32)tmppriority) << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
-
- tmpreg = rNVIC->IPR[(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;
-
- /* Enable the Selected IRQ Channels --------------------------------------*/
- rNVIC->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
- (u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
+ u32 tmppriority = 0x00;
+ u32 tmpreg = 0x00;
+ u32 tmpmask = 0x00;
+ u32 tmppre = 0;
+ u32 tmpsub = 0x0F;
+
+ SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE;
+ NVIC_TypeDef* rNVIC = (NVIC_TypeDef *) NVIC_BASE;
+
+
+ /* Compute the Corresponding IRQ Priority -------------------------------*/
+ tmppriority = (0x700 - (rSCB->AIRCR & (u32)0x700))>> 0x08;
+ tmppre = (0x4 - tmppriority);
+ tmpsub = tmpsub >> tmppriority;
+
+ tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority <<
+ tmppre;
+ tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
+
+ tmppriority = tmppriority << 0x04;
+ tmppriority = ((u32)tmppriority) <<
+ ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
+
+ tmpreg = rNVIC->IPR[(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;
+
+ /* Enable the Selected IRQ Channels -------------------------------------*/
+ rNVIC->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;
-
- SET_REG(STK_CTRL,0x04); /* disable the systick, which operates separately from nvic */
+ NVIC_TypeDef* rNVIC = (NVIC_TypeDef *) NVIC_BASE;
+ rNVIC->ICER[0] = 0xFFFFFFFF;
+ rNVIC->ICER[1] = 0xFFFFFFFF;
+ rNVIC->ICPR[0] = 0xFFFFFFFF;
+ rNVIC->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;
- typedef void (*funcPtr)(void);
-
- /* Reset */
- rSCB->AIRCR = (u32)AIRCR_RESET_REQ;
-
- /* should never get here */
- while (1) {
- asm volatile("nop");
- }
+ SCB_TypeDef* rSCB = (SCB_TypeDef *) SCB_BASE;
+ typedef void (*funcPtr)(void);
+
+ /* Reset */
+ rSCB->AIRCR = (u32)AIRCR_RESET_REQ;
+
+ /* Should never get here */
+ while (1) {
+ asm volatile("nop");
+ }
}
diff --git a/libmaple/util.c b/libmaple/util.c
index be29e7e..135f005 100644
--- a/libmaple/util.c
+++ b/libmaple/util.c
@@ -23,8 +23,6 @@
*****************************************************************************/
/**
- * @file util.h
- *
* @brief Utility procedures for debugging, mostly an error LED fade
* and messages dumped over a uart for failed asserts.
*/