Merge pull request #375 from bcostm/dev_F072RB_assert

[NUCLEO_F072RB] mbed assert addition
pull/379/head
Martin Kojtal 2014-06-26 09:09:29 +01:00
commit ea64ad4ac2
8 changed files with 25 additions and 30 deletions

View File

@ -25,6 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * 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. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "mbed_assert.h"
#include "analogin_api.h" #include "analogin_api.h"
#if DEVICE_ANALOGIN #if DEVICE_ANALOGIN
@ -32,7 +33,6 @@
#include "wait_api.h" #include "wait_api.h"
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_ADC[] = { static const PinMap PinMap_ADC[] = {
{PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0 {PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0
@ -61,10 +61,7 @@ int adc_inited = 0;
void analogin_init(analogin_t *obj, PinName pin) { void analogin_init(analogin_t *obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object // Get the peripheral name from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);
if (obj->adc == (ADCName)NC) {
error("ADC error: pinout mapping failed.");
}
// Configure GPIO // Configure GPIO
pinmap_pinout(pin, PinMap_ADC); pinmap_pinout(pin, PinMap_ADC);

View File

@ -25,6 +25,7 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * 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. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "mbed_assert.h"
#include "analogout_api.h" #include "analogout_api.h"
#if DEVICE_ANALOGOUT #if DEVICE_ANALOGOUT
@ -50,10 +51,7 @@ void analogout_init(dac_t *obj, PinName pin) {
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
MBED_ASSERT(obj->dac != (DACName)NC);
if (obj->dac == (DACName)NC) {
error("DAC pin mapping failed");
}
// Configure GPIO // Configure GPIO
pinmap_pinout(pin, PinMap_DAC); pinmap_pinout(pin, PinMap_DAC);

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *******************************************************************************
*/ */
#include "mbed_assert.h"
#include "gpio_api.h" #include "gpio_api.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h" #include "error.h"
@ -34,7 +35,7 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx); extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
uint32_t gpio_set(PinName pin) { 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)); pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@ -42,7 +43,10 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { 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); uint32_t port_index = STM_PORT(pin);
@ -51,7 +55,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add; GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
// Fill GPIO object structure for future use // Fill GPIO object structure for future use
obj->pin = pin;
obj->mask = gpio_set(pin); obj->mask = gpio_set(pin);
obj->reg_in = &gpio->IDR; obj->reg_in = &gpio->IDR;
obj->reg_set = &gpio->BSRRL; obj->reg_set = &gpio->BSRRL;
@ -63,6 +66,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
} }
void gpio_dir(gpio_t *obj, PinDirection direction) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (direction == PIN_OUTPUT) { if (direction == PIN_OUTPUT) {
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0)); pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
} else { // PIN_INPUT } else { // PIN_INPUT

View File

@ -30,6 +30,7 @@
#ifndef MBED_GPIO_OBJECT_H #ifndef MBED_GPIO_OBJECT_H
#define MBED_GPIO_OBJECT_H #define MBED_GPIO_OBJECT_H
#include "mbed_assert.h"
#include "cmsis.h" #include "cmsis.h"
#include "PortNames.h" #include "PortNames.h"
#include "PeripheralNames.h" #include "PeripheralNames.h"
@ -48,6 +49,7 @@ typedef struct {
} gpio_t; } gpio_t;
static inline void gpio_write(gpio_t *obj, int value) { static inline void gpio_write(gpio_t *obj, int value) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) { if (value) {
*obj->reg_set = obj->mask; *obj->reg_set = obj->mask;
} else { } else {
@ -56,6 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
} }
static inline int gpio_read(gpio_t *obj) { static inline int gpio_read(gpio_t *obj) {
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0); return ((*obj->reg_in & obj->mask) ? 1 : 0);
} }

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *******************************************************************************
*/ */
#include "mbed_assert.h"
#include "i2c_api.h" #include "i2c_api.h"
#if DEVICE_I2C #if DEVICE_I2C
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
/* Timeout values for flags and events waiting loops. These timeouts are /* Timeout values for flags and events waiting loops. These timeouts are
not based on accurate values, they just guarantee that the application will not based on accurate values, they just guarantee that the application will
@ -65,10 +65,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
MBED_ASSERT(obj->i2c != (I2CName)NC);
if (obj->i2c == (I2CName)NC) {
error("I2C error: pinout mapping failed.");
}
// Enable I2C clock // Enable I2C clock
if (obj->i2c == I2C_1) { if (obj->i2c == I2C_1) {
@ -93,6 +90,8 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
} }
void i2c_frequency(i2c_t *obj, int hz) { void i2c_frequency(i2c_t *obj, int hz) {
MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c); I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
// Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0 // Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0
@ -107,7 +106,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
I2cHandle.Init.Timing = 0x00700818; // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns I2cHandle.Init.Timing = 0x00700818; // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns
break; break;
default: default:
error("Only 100kHz, 400kHz and 1MHz I2C frequencies are supported.");
break; break;
} }

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *******************************************************************************
*/ */
#include "mbed_assert.h"
#include "pinmap.h" #include "pinmap.h"
#include "PortNames.h" #include "PortNames.h"
#include "error.h" #include "error.h"
@ -82,7 +83,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
* Configure pin (mode, speed, output type and pull-up/pull-down) * Configure pin (mode, speed, output type and pull-up/pull-down)
*/ */
void pin_function(PinName pin, int data) { void pin_function(PinName pin, int data) {
if (pin == NC) return; MBED_ASSERT(pin != (PinName)NC);
// Get the pin informations // Get the pin informations
uint32_t mode = STM_PIN_MODE(data); uint32_t mode = STM_PIN_MODE(data);
@ -116,7 +117,7 @@ void pin_function(PinName pin, int data) {
* Configure pin pull-up/pull-down * Configure pin pull-up/pull-down
*/ */
void pin_mode(PinName pin, PinMode mode) { 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 port_index = STM_PORT(pin);
uint32_t pin_index = STM_PIN(pin); uint32_t pin_index = STM_PIN(pin);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *******************************************************************************
*/ */
#include "mbed_assert.h"
#include "serial_api.h" #include "serial_api.h"
#if DEVICE_SERIAL #if DEVICE_SERIAL
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
#include <string.h> #include <string.h>
static const PinMap PinMap_UART_TX[] = { static const PinMap PinMap_UART_TX[] = {
@ -100,10 +100,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object // 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); obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
MBED_ASSERT(obj->uart != (UARTName)NC);
if (obj->uart == (UARTName)NC) {
error("Serial error: pinout mapping failed.");
}
// Enable USART clock // Enable USART clock
if (obj->uart == UART_1) { if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************* *******************************************************************************
*/ */
#include "mbed_assert.h"
#include "spi_api.h" #include "spi_api.h"
#if DEVICE_SPI #if DEVICE_SPI
@ -34,7 +35,6 @@
#include <math.h> #include <math.h>
#include "cmsis.h" #include "cmsis.h"
#include "pinmap.h" #include "pinmap.h"
#include "error.h"
static const PinMap PinMap_SPI_MOSI[] = { static const PinMap PinMap_SPI_MOSI[] = {
{PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)}, {PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)},
@ -103,10 +103,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl); obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
MBED_ASSERT(obj->spi != (SPIName)NC);
if (obj->spi == (SPIName)NC) {
error("SPI error: pinout mapping failed.");
}
// Enable SPI clock // Enable SPI clock
if (obj->spi == SPI_1) { if (obj->spi == SPI_1) {