mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Revision:
239:8cadf13dff33
Parent:
219:993c9b0acbcc
Child:
250:a49055e7a707
--- 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