[ALL TARGETS] error replaced by assert for preconditions

pull/316/head
0xc0170 2014-05-19 17:09:04 +01:00
parent fb90157c9a
commit d843d56c08
69 changed files with 333 additions and 545 deletions

View File

@ -397,11 +397,13 @@ extern "C" WEAK void __cxa_pure_virtual(void) {
#endif
#include "mbed_interface.h"
// mbed abort invokes only mbed die. The abort function is called from failing assert for example.
namespace std {
extern "C" void abort(void) {
mbed_die();
while(1);
}
}
// ****************************************************************************
// mbed_main is a function that is called before main()

View File

@ -116,6 +116,10 @@ void serial_baud(serial_t *obj, int baudrate) {
}
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
assert((stop_bits == 1) || (stop_bits == 2));
assert(parity < (ParityEven + 1));
assert((data_bits == 8) || (data_bits == 9));
assert((data_bits == 2) && (obj->index != 0));
// save C2 state
uint32_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK));
@ -124,9 +128,6 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
// 8 data bits = 0 ... 9 data bits = 1
if ((data_bits < 8) || (data_bits > 9))
error("Invalid number of bits (%d) in serial format, should be 8..9", data_bits);
data_bits -= 8;
uint32_t parity_enable, parity_select;
@ -135,22 +136,15 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
default:
error("Invalid serial parity setting");
return;
break;
}
// 1 stop bits = 0, 2 stop bits = 1
if ((stop_bits != 1) && (stop_bits != 2))
error("Invalid stop bits specified");
stop_bits -= 1;
uint32_t m10 = 0;
// 9 data bits + parity
if (data_bits == 2) {
// only uart0 supports 10 bit communication
if (obj->index != 0)
error("Invalid number of bits (9) to be used with parity");
data_bits = 0;
m10 = 1;
}

View File

@ -91,13 +91,8 @@ void spi_free(spi_t *obj) {
// [TODO]
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if ((bits != 8) && (bits != 16)) {
error("Only 8/16 bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
assert((bits == 8) || (bits == 16));
assert((mode > -1) && (mode < 4));
uint32_t polarity = (mode & 0x2) ? 1 : 0;
uint32_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -19,7 +19,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_SPI_SCLK[] = {
{PTB0, SPI_0, 3},
@ -51,9 +50,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);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
assert((int)obj->spi != NC);
// enable power and clocking
switch ((int)obj->spi) {
@ -87,13 +84,8 @@ void spi_free(spi_t *obj) {
// [TODO]
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if (bits != 8) {
error("Only 8bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
assert(bits == 8);
assert((mode > -1) && (mode < 4));
uint8_t polarity = (mode & 0x2) ? 1 : 0;
uint8_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -19,7 +19,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "clk_freqs.h"
#include "PeripheralPins.h"
@ -33,9 +32,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);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
assert((int)obj->spi != NC);
// enable power and clocking
switch ((int)obj->spi) {
@ -67,13 +64,8 @@ void spi_free(spi_t *obj) {
// [TODO]
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if (bits != 8) {
error("Only 8bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
assert(bits == 8);
assert((mode > -1) && (mode < 4));
uint8_t polarity = (mode & 0x2) ? 1 : 0;
uint8_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <assert.h>
#include "spi_api.h"
#include <math.h>
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_SPI_SCLK[] = {
{PTA15, SPI_0, 2},
@ -90,9 +90,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);
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
assert((int)obj->spi != NC);
// enable power and clocking
switch ((int)obj->spi) {
@ -125,13 +123,8 @@ void spi_free(spi_t *obj) {
// [TODO]
}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
if ((bits != 8) && (bits != 16)) {
error("Only 8/16 bits SPI supported");
}
if ((mode < 0) || (mode > 3)) {
error("SPI mode unsupported");
}
assert((bits == 8) || (bits == 16));
assert((mode > -1) && (mode < 4));
uint8_t polarity = (mode & 0x2) ? 1 : 0;
uint8_t phase = (mode & 0x1) ? 1 : 0;

View File

@ -43,7 +43,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
assert(obj->i2c != (PinName)NC);
assert((int)obj->i2c != NC);
// enable power
switch ((int)obj->i2c) {

View File

@ -148,6 +148,9 @@ void serial_baud(serial_t *obj, int baudrate) {
}
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
assert((stop_bits == 1) || (stop_bits == 2));
assert(parity < (ParityEven + 1));
assert(data_bits == 8); // TODO: Support other number of data bits (also in the write method!)
// save C2 state
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
@ -155,10 +158,6 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
// TODO: Support other number of data bits (also in the write method!)
if ((data_bits < 8) || (data_bits > 8)) {
error("Invalid number of bits (%d) in serial format, should be 8", data_bits);
}
uint8_t parity_enable, parity_select;
switch (parity) {
@ -166,14 +165,9 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
default:
error("Invalid serial parity setting");
return;
break;
}
// 1 stop bits = 0, 2 stop bits = 1
if ((stop_bits != 1) && (stop_bits != 2)) {
error("Invalid stop bits specified");
}
stop_bits -= 1;
// data bits, parity and parity mode

View File

@ -43,7 +43,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
assert(pin != (PinName)NC);
assert(obj->pin != (PinName)NC);
switch (direction) {
case PIN_INPUT :
*obj->reg_dir &= ~obj->mask;

View File

@ -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 <assert.h>
#include "analogin_api.h"
#include "wait_api.h"
@ -32,7 +33,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_ADC[] = {
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN0
@ -53,10 +53,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -57,10 +57,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -84,6 +81,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz == 100000) || (hz == 200000) || (hz == 400000)); //"Only 100kHz, 200kHz and 400kHz I2C frequencies are supported."
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure;
uint32_t tim = 0;
@ -101,7 +99,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
tim = 0x0010020A; // Fast mode
break;
default:
error("Only 100kHz, 200kHz and 400kHz I2C frequencies are supported.");
break;
}

View File

@ -27,10 +27,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "serial_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include <string.h>
static const PinMap PinMap_UART_TX[] = {
@ -78,10 +78,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_AF_0)},
@ -90,10 +90,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -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 <assert.h>
#include "analogin_api.h"
#include "wait_api.h"
@ -32,7 +33,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_ADC[] = {
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
@ -53,10 +53,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -57,10 +57,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {

View File

@ -27,11 +27,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_PWM[] = {
// TIM2 full remap
@ -46,10 +46,7 @@ static const PinMap PinMap_PWM[] = {
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM pinout mapping failed");
}
assert(obj->pwm != (PWMName)NC);
// Enable TIM clock
if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

View File

@ -27,10 +27,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "serial_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include <string.h>
static const PinMap PinMap_UART_TX[] = {
@ -80,10 +80,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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(GPIO_Mode_AF_PP, 0)},
@ -91,10 +91,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -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 <assert.h>
#include "analogin_api.h"
#include "wait_api.h"
@ -32,7 +33,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_ADC[] = {
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
@ -63,10 +63,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 pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -68,10 +68,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -98,6 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure;
uint32_t tim;
@ -140,7 +138,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
}
break;
default:
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
break;
}

View File

@ -27,11 +27,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
// TIM2 cannot be used because already used by the us_ticker
static const PinMap PinMap_PWM[] = {
@ -88,10 +88,7 @@ static const PinMap PinMap_PWM[] = {
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM pinout mapping failed");
}
assert(obj->pwm != (PWMName)NC);
// Enable TIM clock
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

View File

@ -27,10 +27,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "serial_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include <string.h>
static const PinMap PinMap_UART_TX[] = {
@ -92,10 +92,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// Get the peripheral name 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 pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
@ -101,10 +101,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_2) {

View File

@ -32,7 +32,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "stm32f4xx_hal.h"
static const PinMap PinMap_ADC[] = {
@ -62,10 +61,7 @@ int adc_inited = 0;
void analogin_init(analogin_t *obj, PinName pin) {
// Get the peripheral name (ADC_1, ADC_2...) 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.");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "i2c_api.h"
#if DEVICE_I2C
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "stm32f4xx_hal.h"
/* Timeout values for flags and events waiting loops. These timeouts are
@ -71,10 +71,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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.");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -101,6 +98,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz != 0) && (hz <= 400000));
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
if ((hz != 0) && (hz <= 400000)) {
@ -115,9 +113,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
I2cHandle.Init.OwnAddress2 = 0;
HAL_I2C_Init(&I2cHandle);
}
else {
error("I2C error: frequency setting failed (max 400kHz).");
}
}
inline int i2c_start(i2c_t *obj) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#include "cmsis.h"
@ -87,10 +88,7 @@ static TIM_HandleTypeDef TimHandle;
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM error: pinout mapping failed.");
}
assert(obj->pwm != (PWMName)NC);
// Enable TIM clock
if (obj->pwm == PWM_1) __TIM1_CLK_ENABLE();

View File

@ -30,7 +30,6 @@
#include "serial_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include <string.h>
#include "stm32f4xx_hal.h"
@ -83,10 +82,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial error: pinout mapping failed.");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -34,7 +34,6 @@
#include <math.h>
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "stm32f4xx_hal.h"
static const PinMap PinMap_SPI_MOSI[] = {
@ -112,10 +111,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI error: pinout mapping failed.");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -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 <assert.h>
#include "analogin_api.h"
#if DEVICE_ANALOGIN
@ -63,10 +64,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -64,7 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
assert(pin != (PinName)NC);
assert(obj->pin != (PinName)NC);
if (direction == PIN_OUTPUT) {
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
}

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -61,10 +61,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -89,6 +86,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure;
uint32_t tim = 0;
@ -131,7 +129,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
}
break;
default:
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
break;
}

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#if DEVICE_PWMOUT
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
// TIM1 cannot be used because already used by the us_ticker
static const PinMap PinMap_PWM[] = {
@ -65,10 +65,7 @@ static const PinMap PinMap_PWM[] = {
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM pinout mapping failed");
}
assert(obj->pwm != (PWMName)NC);
// Enable TIM clock
if (obj->pwm == TIM_3) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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[] = {
@ -84,10 +84,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_AF_0)},
@ -98,10 +98,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -25,13 +25,13 @@
* 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 <assert.h>
#include "analogin_api.h"
#if DEVICE_ANALOGIN
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "wait_api.h"
static const PinMap PinMap_ADC[] = {
@ -62,10 +62,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 pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -61,10 +61,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#if DEVICE_PWMOUT
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
// TIM4 cannot be used because already used by the us_ticker
static const PinMap PinMap_PWM[] = {
@ -76,10 +76,7 @@ static const PinMap PinMap_PWM[] = {
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM pinout mapping failed");
}
assert(obj->pwm != (PWMName)NC);
// Enable TIM clock
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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[] = {
@ -87,10 +87,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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(GPIO_Mode_AF_PP, 0)},
@ -95,10 +95,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -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 <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(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
@ -63,10 +63,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 pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -25,13 +25,13 @@
* 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 <assert.h>
#include "analogout_api.h"
#if DEVICE_ANALOGOUT
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#define DAC_RANGE (0xFFF) // 12 bits
@ -46,10 +46,7 @@ void analogout_init(dac_t *obj, PinName pin) {
// 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");
}
assert(obj->dac != (DACName)NC);
dac = (DAC_TypeDef *)(obj->dac);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -68,10 +68,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -98,6 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure;
uint32_t tim = 0;
@ -140,7 +138,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
}
break;
default:
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
break;
}

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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[] = {
@ -95,10 +95,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// Get the peripheral name 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 pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
@ -101,10 +101,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_2) {

View File

@ -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 <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 @@ int adc_inited = 0;
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.");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -66,10 +66,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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.");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -99,6 +96,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz != 0) && (hz <= 400000));
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
if ((hz != 0) && (hz <= 400000)) {
@ -116,8 +114,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
/* Enable Address Acknowledge */
I2cHandle.Instance->CR1 |= I2C_CR1_ACK;
}
} else {
error("I2C error: frequency setting failed (max 400kHz).");
}
}

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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[] = {
@ -85,10 +85,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial error: pinout mapping failed.");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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_AF5_SPI1)},
@ -111,10 +111,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI error: pinout mapping failed.");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -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 <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 @@ int adc_inited = 0;
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.");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
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
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assert.h>
#include "analogout_api.h"
#if DEVICE_ANALOGOUT
@ -49,10 +50,7 @@ void analogout_init(dac_t *obj, PinName pin) {
// 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");
}
assert(obj->dac != (DACName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_DAC);

View File

@ -64,7 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
assert(pin != (PinName)NC);
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

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "i2c_api.h"
#if DEVICE_I2C
@ -65,10 +66,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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.");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -92,6 +90,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz == 100000) || (hz == 400000) || (hz == 1000000));
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
// Common settings: I2C clock = 32 MHz, Analog filter = ON, Digital filter coefficient = 0
@ -106,7 +105,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
I2cHandle.Init.Timing = 0x0030040E; // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns
break;
default:
error("Only 100kHz, 400kHz and 1MHz I2C frequencies are supported.");
break;
}

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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[] = {
@ -98,10 +98,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial error: pinout mapping failed.");
}
assert(obj->uart != (UARTName)NC);
// Enable UART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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)},
@ -105,10 +105,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI error: pinout mapping failed.");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -25,13 +25,13 @@
* 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 <assert.h>
#include "analogin_api.h"
#if DEVICE_ANALOGIN
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include "wait_api.h"
static const PinMap PinMap_ADC[] = {
@ -66,10 +66,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 pin mapping failed");
}
assert(obj->adc != (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -25,13 +25,13 @@
* 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 <assert.h>
#include "analogout_api.h"
#if DEVICE_ANALOGOUT
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#define RANGE_12BIT (0xFFF)
@ -46,10 +46,7 @@ void analogout_init(dac_t *obj, PinName pin) {
// 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");
}
assert(obj->dac != (DACName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_DAC);

View File

@ -27,13 +27,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -61,10 +62,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#if DEVICE_PWMOUT
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
// TIM5 cannot be used because already used by the us_ticker
static const PinMap PinMap_PWM[] = {
@ -77,10 +77,7 @@ static const PinMap PinMap_PWM[] = {
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM pinout mapping failed");
}
assert(obj->pwm != (PWMName)NC);
// Enable TIM clock
if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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[] = {
@ -91,10 +91,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
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
if (obj->uart == (UARTName)NC) {
error("Serial pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)},
@ -105,10 +105,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);
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_1) {

View File

@ -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 <assert.h>
#include "analogin_api.h"
#include "wait_api.h"
@ -32,7 +33,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_ADC[] = {
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
@ -63,10 +63,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 pin mapping failed");
}
assert(obj->adc == (ADCName)NC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);

View File

@ -25,13 +25,13 @@
* 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 <assert.h>
#include "analogout_api.h"
#if DEVICE_ANALOGOUT
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#define RANGE_12BIT (0xFFF)
@ -46,10 +46,7 @@ void analogout_init(dac_t *obj, PinName pin) {
// 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");
}
assert(obj->dac == (DACName)NC);
dac = (DAC_TypeDef *)(obj->dac);

View File

@ -27,13 +27,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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
@ -68,10 +68,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
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 pin mapping failed");
}
assert(obj->i2c != (I2CName)NC);
// Enable I2C clock
if (obj->i2c == I2C_1) {
@ -98,6 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
}
void i2c_frequency(i2c_t *obj, int hz) {
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure;
uint32_t tim;
@ -140,7 +138,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
}
break;
default:
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
break;
}

View File

@ -27,11 +27,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "pwmout_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
// TIM2 cannot be used because already used by the us_ticker
static const PinMap PinMap_PWM[] = {
@ -88,10 +88,7 @@ static const PinMap PinMap_PWM[] = {
void pwmout_init(pwmout_t* obj, PinName pin) {
// Get the peripheral name from the pin and assign it to the object
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (obj->pwm == (PWMName)NC) {
error("PWM pinout mapping failed");
}
assert(obj->pwm == (PWMName)NC);
// Enable TIM clock
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

View File

@ -27,10 +27,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <assert.h>
#include "serial_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
#include <string.h>
static const PinMap PinMap_UART_TX[] = {
@ -92,10 +92,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// Get the peripheral name 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 pinout mapping failed");
}
assert(obj->uart != (UARTName)NC);
// Enable USART clock
if (obj->uart == UART_1) {

View File

@ -27,6 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
*/
#include <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_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
@ -102,9 +102,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
if (obj->spi == (SPIName)NC) {
error("SPI pinout mapping failed");
}
assert(obj->spi != (SPIName)NC);
// Enable SPI clock
if (obj->spi == SPI_2) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <assert.h>
#include "analogin_api.h"
#if DEVICE_ANALOGIN
@ -48,9 +49,7 @@ static const PinMap PinMap_ADC[] = {
void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) {
error("ADC pin mapping failed");
}
assert(obj->adc != (uint32_t)NC);
// ensure power is turned on
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN |

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <assert.h>
#include "i2c_api.h"
#if DEVICE_I2C
@ -124,10 +125,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
obj->i2c = (I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
if ((int)obj->i2c == NC) {
error("I2C pin mapping failed");
}
assert((int)obj->i2c != NC);
// enable power
i2c_power_enable(obj);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <assert.h>
#include "spi_api.h"
#if DEVICE_SPI
@ -20,7 +21,6 @@
#include "cmsis.h"
#include "pinmap.h"
#include "error.h"
static const PinMap PinMap_SPI_SCLK[] = {
{PA_5, SPI_1, STM_PIN_DATA(2, 5)},
@ -75,9 +75,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
obj->spi = (SPI_TypeDef*)pinmap_merge(spi_data, spi_cntl);
if ((int)obj->spi == NC) {
error("SPI pinout mapping failed");
}
assert((int)obj->spi != NC)
// enable power and clocking
switch ((int)obj->spi) {
@ -123,13 +121,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
void spi_free(spi_t *obj) {}
void spi_format(spi_t *obj, int bits, int mode, int slave) {
assert((bits == 8 || bits == 16) || (mode >= 0 && mode <= 3));
ssp_disable(obj);
if (!(bits == 8 || bits == 16) || !(mode >= 0 && mode <= 3)) {
error("SPI format error");
}
int polarity = (mode & 0x2) ? 1 : 0;
int phase = (mode & 0x1) ? 1 : 0;