mbed w/ spi bug fig

Dependents:   display-puck

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Thu Jun 26 09:15:07 2014 +0100
Parent:
238:bda0417c579a
Child:
240:9a7c54113eaf
Commit message:
Synchronized with git revision ea64ad4ac220cd7180724d8bb43310da3e692767

Full URL: https://github.com/mbedmicro/mbed/commit/ea64ad4ac220cd7180724d8bb43310da3e692767/

[NUCLEO_F072RB] mbed assert addition

Changed in this revision

targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogin_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogout_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_object.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pinmap.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/serial_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogin_api.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogin_api.c	Thu Jun 26 09:15:07 2014 +0100
@@ -25,6 +25,7 @@
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+#include "mbed_assert.h"
 #include "analogin_api.h"
 
 #if DEVICE_ANALOGIN
@@ -32,7 +33,6 @@
 #include "wait_api.h"
 #include "cmsis.h"
 #include "pinmap.h"
-#include "error.h"
 
 static const PinMap PinMap_ADC[] = {
     {PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0
@@ -61,10 +61,7 @@
 void analogin_init(analogin_t *obj, PinName pin) {
     // Get the peripheral name from the pin and assign it to the object
     obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
-
-    if (obj->adc == (ADCName)NC) {
-        error("ADC error: pinout mapping failed.");
-    }
+    MBED_ASSERT(obj->adc != (ADCName)NC);
 
     // Configure GPIO
     pinmap_pinout(pin, PinMap_ADC);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogout_api.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogout_api.c	Thu Jun 26 09:15:07 2014 +0100
@@ -25,6 +25,7 @@
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+#include "mbed_assert.h"
 #include "analogout_api.h"
 
 #if DEVICE_ANALOGOUT
@@ -50,10 +51,7 @@
 
     // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
     obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
-
-    if (obj->dac == (DACName)NC) {
-        error("DAC pin mapping failed");
-    }
+    MBED_ASSERT(obj->dac != (DACName)NC);
 
     // Configure GPIO
     pinmap_pinout(pin, PinMap_DAC);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_api.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_api.c	Thu Jun 26 09:15:07 2014 +0100
@@ -27,6 +27,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************
  */
+#include "mbed_assert.h"
 #include "gpio_api.h"
 #include "pinmap.h"
 #include "error.h"
@@ -34,7 +35,7 @@
 extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
 
 uint32_t gpio_set(PinName pin) {
-    if (pin == NC) return 0;
+    MBED_ASSERT(pin != (PinName)NC);
 
     pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
 
@@ -42,7 +43,10 @@
 }
 
 void gpio_init(gpio_t *obj, PinName pin) {
-    if (pin == NC) return;
+    obj->pin = pin;
+    if (pin == (PinName)NC) {
+        return;
+    }
 
     uint32_t port_index = STM_PORT(pin);
 
@@ -51,7 +55,6 @@
     GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
 
     // Fill GPIO object structure for future use
-    obj->pin     = pin;
     obj->mask    = gpio_set(pin);
     obj->reg_in  = &gpio->IDR;
     obj->reg_set = &gpio->BSRRL;
@@ -63,6 +66,7 @@
 }
 
 void gpio_dir(gpio_t *obj, PinDirection direction) {
+    MBED_ASSERT(obj->pin != (PinName)NC);
     if (direction == PIN_OUTPUT) {
         pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
     } else { // PIN_INPUT
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_object.h	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_object.h	Thu Jun 26 09:15:07 2014 +0100
@@ -30,6 +30,7 @@
 #ifndef MBED_GPIO_OBJECT_H
 #define MBED_GPIO_OBJECT_H
 
+#include "mbed_assert.h"
 #include "cmsis.h"
 #include "PortNames.h"
 #include "PeripheralNames.h"
@@ -48,6 +49,7 @@
 } gpio_t;
 
 static inline void gpio_write(gpio_t *obj, int value) {
+    MBED_ASSERT(obj->pin != (PinName)NC);
     if (value) {
         *obj->reg_set = obj->mask;
     } else {
@@ -56,6 +58,7 @@
 }
 
 static inline int gpio_read(gpio_t *obj) {
+    MBED_ASSERT(obj->pin != (PinName)NC);
     return ((*obj->reg_in & obj->mask) ? 1 : 0);
 }
 
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c	Thu Jun 26 09:15:07 2014 +0100
@@ -27,13 +27,13 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************
  */
+#include "mbed_assert.h"
 #include "i2c_api.h"
 
 #if DEVICE_I2C
 
 #include "cmsis.h"
 #include "pinmap.h"
-#include "error.h"
 
 /* Timeout values for flags and events waiting loops. These timeouts are
    not based on accurate values, they just guarantee that the application will
@@ -65,10 +65,7 @@
     I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
 
     obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
-
-    if (obj->i2c == (I2CName)NC) {
-        error("I2C error: pinout mapping failed.");
-    }
+    MBED_ASSERT(obj->i2c != (I2CName)NC);
 
     // Enable I2C clock
     if (obj->i2c == I2C_1) {
@@ -93,6 +90,8 @@
 }
 
 void i2c_frequency(i2c_t *obj, int hz) {
+    MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
+
     I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
 
     // Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0
@@ -107,7 +106,6 @@
             I2cHandle.Init.Timing = 0x00700818; // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns
             break;
         default:
-            error("Only 100kHz, 400kHz and 1MHz I2C frequencies are supported.");
             break;
     }
 
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pinmap.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pinmap.c	Thu Jun 26 09:15:07 2014 +0100
@@ -27,6 +27,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************
  */
+#include "mbed_assert.h"
 #include "pinmap.h"
 #include "PortNames.h"
 #include "error.h"
@@ -82,7 +83,7 @@
  * Configure pin (mode, speed, output type and pull-up/pull-down)
  */
 void pin_function(PinName pin, int data) {
-    if (pin == NC) return;
+    MBED_ASSERT(pin != (PinName)NC);
 
     // Get the pin informations
     uint32_t mode  = STM_PIN_MODE(data);
@@ -116,7 +117,7 @@
  * Configure pin pull-up/pull-down
  */
 void pin_mode(PinName pin, PinMode mode) {
-    if (pin == NC) return;
+    MBED_ASSERT(pin != (PinName)NC);
 
     uint32_t port_index = STM_PORT(pin);
     uint32_t pin_index  = STM_PIN(pin);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/serial_api.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/serial_api.c	Thu Jun 26 09:15:07 2014 +0100
@@ -27,13 +27,13 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************
  */
+#include "mbed_assert.h"
 #include "serial_api.h"
 
 #if DEVICE_SERIAL
 
 #include "cmsis.h"
 #include "pinmap.h"
-#include "error.h"
 #include <string.h>
 
 static const PinMap PinMap_UART_TX[] = {
@@ -100,10 +100,7 @@
 
     // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
     obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
-
-    if (obj->uart == (UARTName)NC) {
-        error("Serial error: pinout mapping failed.");
-    }
+    MBED_ASSERT(obj->uart != (UARTName)NC);
 
     // Enable USART clock
     if (obj->uart == UART_1) {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c	Thu Jun 26 09:00:08 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c	Thu Jun 26 09:15:07 2014 +0100
@@ -27,6 +27,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *******************************************************************************
  */
+#include "mbed_assert.h"
 #include "spi_api.h"
 
 #if DEVICE_SPI
@@ -34,7 +35,6 @@
 #include <math.h>
 #include "cmsis.h"
 #include "pinmap.h"
-#include "error.h"
 
 static const PinMap PinMap_SPI_MOSI[] = {
     {PA_7,  SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)},
@@ -103,10 +103,7 @@
     SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
 
     obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
-
-    if (obj->spi == (SPIName)NC) {
-        error("SPI error: pinout mapping failed.");
-    }
+    MBED_ASSERT(obj->spi != (SPIName)NC);
 
     // Enable SPI clock
     if (obj->spi == SPI_1) {