Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
Revision 402:09075a3b15e3, committed 2014-11-14
- Comitter:
- mbed_official
- Date:
- Fri Nov 14 09:00:07 2014 +0000
- Parent:
- 401:6d559ae9fd59
- Child:
- 403:91a4bea587f4
- Commit message:
- Synchronized with git revision dffeedc96e731e30785ca4a7842fb9769412bea1
Full URL: https://github.com/mbedmicro/mbed/commit/dffeedc96e731e30785ca4a7842fb9769412bea1/
Targets: add USBTX and USBRX pin definitions for targets that don't provide them
Changed in this revision
--- a/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U35_401/PinNames.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U35_401/PinNames.h Fri Nov 14 09:00:07 2014 +0000
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
+ * Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -132,6 +132,11 @@
// Not connected
NC = (int)0xFFFFFFFF,
+
+ // Standard but not supported pins
+ USBTX = NC,
+ USBRX = NC,
+
} PinName;
typedef enum {
--- a/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPCCAPPUCCINO/PinNames.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPCCAPPUCCINO/PinNames.h Fri Nov 14 09:00:07 2014 +0000
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
+ * Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,6 +105,11 @@
// Not connected
NC = (int)0xFFFFFFFF,
+
+ // Standard but not supported pins
+ USBTX = NC,
+ USBRX = NC,
+
} PinName;
typedef enum {
--- a/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_MCU_LPC11U35_501/TARGET_LPC11U35_501/PinNames.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_MCU_LPC11U35_501/TARGET_LPC11U35_501/PinNames.h Fri Nov 14 09:00:07 2014 +0000
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
+ * Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -147,6 +147,11 @@
// Not connected
NC = (int)0xFFFFFFFF,
+
+ // Standard but not supported pins
+ USBTX = NC,
+ USBRX = NC,
+
} PinName;
typedef enum {
--- a/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_MCU_LPC11U35_501/TARGET_XADOW_M0/PinNames.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_MCU_LPC11U35_501/TARGET_XADOW_M0/PinNames.h Fri Nov 14 09:00:07 2014 +0000
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
+ * Copyright (c) 2006-2014 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -150,6 +150,11 @@
// Not connected
NC = (int)0xFFFFFFFF,
+
+ // Standard but not supported pins
+ USBTX = NC,
+ USBRX = NC,
+
} PinName;
typedef enum {
--- a/targets/hal/TARGET_NXP/TARGET_LPC13XX/PinNames.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_NXP/TARGET_LPC13XX/PinNames.h Fri Nov 14 09:00:07 2014 +0000
@@ -121,7 +121,12 @@
LED1 = p21,
LED2 = p21,
LED3 = p21,
- LED4 = p21
+ LED4 = p21,
+
+ // Standard but not supported pins
+ USBTX = NC,
+ USBRX = NC,
+
} PinName;
typedef enum {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/analogin_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/analogin_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -58,7 +58,8 @@
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
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);
@@ -98,7 +99,8 @@
}
}
-static inline uint16_t adc_read(analogin_t *obj) {
+static inline uint16_t adc_read(analogin_t *obj)
+{
ADC_ChannelConfTypeDef sConfig;
AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
@@ -175,14 +177,16 @@
}
}
-uint16_t analogin_read_u16(analogin_t *obj) {
+uint16_t analogin_read_u16(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
// 12-bit to 16-bit conversion
value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F);
return value;
}
-float analogin_read(analogin_t *obj) {
+float analogin_read(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -34,7 +34,8 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-uint32_t gpio_set(PinName pin) {
+uint32_t gpio_set(PinName pin)
+{
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@@ -42,7 +43,8 @@
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
-void gpio_init(gpio_t *obj, PinName pin) {
+void gpio_init(gpio_t *obj, PinName pin)
+{
obj->pin = pin;
if (pin == (PinName)NC) {
return;
@@ -61,11 +63,13 @@
obj->reg_clr = &gpio->BRR;
}
-void gpio_mode(gpio_t *obj, PinMode mode) {
+void gpio_mode(gpio_t *obj, PinMode mode)
+{
pin_mode(obj->pin, 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) {
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_irq_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_irq_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -47,7 +47,8 @@
static gpio_irq_handler irq_handler;
-static void handle_interrupt_in(uint32_t irq_index) {
+static void handle_interrupt_in(uint32_t irq_index)
+{
// Retrieve the gpio and pin that generate the irq
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
@@ -68,21 +69,25 @@
}
// EXTI lines 0 to 1
-static void gpio_irq0(void) {
+static void gpio_irq0(void)
+{
handle_interrupt_in(0);
}
// EXTI lines 2 to 3
-static void gpio_irq1(void) {
+static void gpio_irq1(void)
+{
handle_interrupt_in(1);
}
// EXTI lines 4 to 15
-static void gpio_irq2(void) {
+static void gpio_irq2(void)
+{
handle_interrupt_in(2);
}
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
uint32_t irq_index;
@@ -134,7 +139,8 @@
return 0;
}
-void gpio_irq_free(gpio_irq_t *obj) {
+void gpio_irq_free(gpio_irq_t *obj)
+{
channel_ids[obj->irq_index] = 0;
channel_gpio[obj->irq_index] = 0;
channel_pin[obj->irq_index] = 0;
@@ -183,19 +189,21 @@
obj->event = EDGE_RISE;
} else { // NONE or FALL
mode = STM_MODE_IT_EVT_RESET;
- obj->event = EDGE_NONE;
- }
+ obj->event = EDGE_NONE;
+ }
}
}
pin_function(obj->pin, STM_PIN_DATA(mode, pull, 0));
}
-void gpio_irq_enable(gpio_irq_t *obj) {
+void gpio_irq_enable(gpio_irq_t *obj)
+{
NVIC_EnableIRQ(obj->irq_n);
}
-void gpio_irq_disable(gpio_irq_t *obj) {
+void gpio_irq_disable(gpio_irq_t *obj)
+{
NVIC_DisableIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_object.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/gpio_object.h Fri Nov 14 09:00:07 2014 +0000
@@ -48,7 +48,8 @@
__IO uint32_t *reg_clr;
} 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) {
*obj->reg_set = obj->mask;
@@ -57,7 +58,8 @@
}
}
-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);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -60,7 +60,8 @@
int i2c1_inited = 0;
int i2c2_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -69,7 +70,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C1 clock and pinout if not done
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
__HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
__I2C1_CLK_ENABLE();
@@ -80,14 +81,14 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C2 clock and pinout if not done
- if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+ if ((obj->i2c == I2C_2) && !i2c2_inited) {
i2c2_inited = 1;
__I2C2_CLK_ENABLE();
- // Configure I2C pins
- pinmap_pinout(sda, PinMap_I2C_SDA);
- pinmap_pinout(scl, PinMap_I2C_SCL);
- pin_mode(sda, OpenDrain);
- pin_mode(scl, OpenDrain);
+ // Configure I2C pins
+ pinmap_pinout(sda, PinMap_I2C_SDA);
+ pinmap_pinout(scl, PinMap_I2C_SCL);
+ pin_mode(sda, OpenDrain);
+ pin_mode(scl, OpenDrain);
}
// Reset to clear pending flags if any
@@ -97,14 +98,15 @@
i2c_frequency(obj, 100000); // 100 kHz per default
}
-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);
int timeout;
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0
switch (hz) {
@@ -132,7 +134,8 @@
HAL_I2C_Init(&I2cHandle);
}
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -155,7 +158,8 @@
return 0;
}
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
// Generate the STOP condition
@@ -164,7 +168,8 @@
return 0;
}
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -209,7 +214,8 @@
return length;
}
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -253,7 +259,8 @@
return count;
}
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -268,7 +275,8 @@
return (int)i2c->RXDR;
}
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -285,12 +293,13 @@
return 1;
}
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
if (obj->i2c == I2C_1) {
__I2C1_FORCE_RESET();
@@ -304,7 +313,8 @@
#if DEVICE_I2CSLAVE
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg = 0;
@@ -322,7 +332,8 @@
i2c->OAR1 |= I2C_OAR1_OA1EN;
}
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg;
@@ -348,7 +359,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int retValue = NoData;
@@ -366,7 +378,8 @@
return (retValue);
}
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
char size = 0;
while (size < length) data[size++] = (char)i2c_byte_read(obj, 0);
@@ -374,7 +387,8 @@
return size;
}
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
char size = 0;
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/mbed_overrides.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/mbed_overrides.c Fri Nov 14 09:00:07 2014 +0000
@@ -28,7 +28,8 @@
#include "cmsis.h"
// This function is called after RAM initialization and before main.
-void mbed_sdk_init() {
+void mbed_sdk_init()
+{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pinmap.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pinmap.c Fri Nov 14 09:00:07 2014 +0000
@@ -50,7 +50,8 @@
};
// Enable GPIO clock and return GPIO base address
-uint32_t Set_GPIO_Clock(uint32_t port_idx) {
+uint32_t Set_GPIO_Clock(uint32_t port_idx)
+{
uint32_t gpio_add = 0;
switch (port_idx) {
case PortA:
@@ -83,7 +84,8 @@
/**
* 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)
+{
MBED_ASSERT(pin != (PinName)NC);
// Get the pin informations
@@ -117,7 +119,8 @@
/**
* Configure pin pull-up/pull-down
*/
-void pin_mode(PinName pin, PinMode mode) {
+void pin_mode(PinName pin, PinMode mode)
+{
MBED_ASSERT(pin != (PinName)NC);
uint32_t port_index = STM_PORT(pin);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/port_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/port_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -38,11 +38,13 @@
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, ...)
// low nibble = pin number
-PinName port_pin(PortName port, int pin_n) {
+PinName port_pin(PortName port, int pin_n)
+{
return (PinName)(pin_n + (port << 4));
}
-void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
+void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
+{
uint32_t port_index = (uint32_t)port;
// Enable GPIO clock
@@ -59,7 +61,8 @@
port_dir(obj, dir);
}
-void port_dir(port_t *obj, PinDirection dir) {
+void port_dir(port_t *obj, PinDirection dir)
+{
uint32_t i;
obj->direction = dir;
for (i = 0; i < 16; i++) { // Process all pins
@@ -73,7 +76,8 @@
}
}
-void port_mode(port_t *obj, PinMode mode) {
+void port_mode(port_t *obj, PinMode mode)
+{
uint32_t i;
for (i = 0; i < 16; i++) { // Process all pins
if (obj->mask & (1 << i)) { // If the pin is used
@@ -82,11 +86,13 @@
}
}
-void port_write(port_t *obj, int value) {
+void port_write(port_t *obj, int value)
+{
*obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask);
}
-int port_read(port_t *obj) {
+int port_read(port_t *obj)
+{
if (obj->direction == PIN_OUTPUT) {
return (*obj->reg_out & obj->mask);
} else { // PIN_INPUT
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pwmout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pwmout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -36,8 +36,8 @@
#include "mbed_error.h"
// TIM1 cannot be used because already used by the us_ticker
-// Uncomment/comment line above to use an alternate timer,
-// If the channel is not the same,
+// Uncomment/comment line above to use an alternate timer,
+// If the channel is not the same,
// Please don't forget to uncomment/comment in the pwmout_write() function also
static const PinMap PinMap_PWM[] = {
{PA_4, PWM_14, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_TIM14)}, // TIM14_CH1
@@ -67,7 +67,8 @@
static TIM_HandleTypeDef TimHandle;
-void pwmout_init(pwmout_t* obj, PinName pin) {
+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);
@@ -92,12 +93,14 @@
pwmout_period_us(obj, 20000); // 20 ms per default
}
-void pwmout_free(pwmout_t* obj) {
+void pwmout_free(pwmout_t* obj)
+{
// Configure GPIO
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void pwmout_write(pwmout_t* obj, float value) {
+void pwmout_write(pwmout_t* obj, float value)
+{
TIM_OC_InitTypeDef sConfig;
int channel = 0;
int complementary_channel = 0;
@@ -137,12 +140,12 @@
// Channels 1N
case PB_6:
case PB_7:
-// case PB_15:
+// case PB_15:
channel = TIM_CHANNEL_1;
complementary_channel = 1;
break;
// Channels 2
- case PA_7:
+ case PA_7:
case PB_5:
case PB_15:
case PC_7:
@@ -171,7 +174,8 @@
}
}
-float pwmout_read(pwmout_t* obj) {
+float pwmout_read(pwmout_t* obj)
+{
float value = 0;
if (obj->period > 0) {
value = (float)(obj->pulse) / (float)(obj->period);
@@ -179,15 +183,18 @@
return ((value > (float)1.0) ? (float)(1.0) : (value));
}
-void pwmout_period(pwmout_t* obj, float seconds) {
+void pwmout_period(pwmout_t* obj, float seconds)
+{
pwmout_period_us(obj, seconds * 1000000.0f);
}
-void pwmout_period_ms(pwmout_t* obj, int ms) {
+void pwmout_period_ms(pwmout_t* obj, int ms)
+{
pwmout_period_us(obj, ms * 1000);
}
-void pwmout_period_us(pwmout_t* obj, int us) {
+void pwmout_period_us(pwmout_t* obj, int us)
+{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
@@ -212,15 +219,18 @@
__HAL_TIM_ENABLE(&TimHandle);
}
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
+void pwmout_pulsewidth(pwmout_t* obj, float seconds)
+{
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
}
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
+void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
+{
pwmout_pulsewidth_us(obj, ms * 1000);
}
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
+void pwmout_pulsewidth_us(pwmout_t* obj, int us)
+{
float value = (float)us / (float)obj->period;
pwmout_write(obj, value);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/rtc_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/rtc_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -37,7 +37,8 @@
static RTC_HandleTypeDef RtcHandle;
-void rtc_init(void) {
+void rtc_init(void)
+{
RCC_OscInitTypeDef RCC_OscInitStruct;
uint32_t rtc_freq = 0;
@@ -94,7 +95,8 @@
}
}
-void rtc_free(void) {
+void rtc_free(void)
+{
// Enable Power clock
__PWR_CLK_ENABLE();
@@ -119,7 +121,8 @@
rtc_inited = 0;
}
-int rtc_isenabled(void) {
+int rtc_isenabled(void)
+{
return rtc_inited;
}
@@ -140,7 +143,8 @@
tm_yday days since January 1 0-365
tm_isdst Daylight Saving Time flag
*/
-time_t rtc_read(void) {
+time_t rtc_read(void)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
struct tm timeinfo;
@@ -167,7 +171,8 @@
return t;
}
-void rtc_write(time_t t) {
+void rtc_write(time_t t)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -62,7 +62,8 @@
int stdio_uart_inited = 0;
serial_t stdio_uart;
-static void init_uart(serial_t *obj) {
+static void init_uart(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
UartHandle.Init.BaudRate = obj->baudrate;
@@ -82,11 +83,12 @@
// Disable the reception overrun detection
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
UartHandle.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
-
+
HAL_UART_Init(&UartHandle);
}
-void serial_init(serial_t *obj, PinName tx, PinName rx) {
+void serial_init(serial_t *obj, PinName tx, PinName rx)
+{
// Determine the UART to use (UART_1, UART_2, ...)
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
@@ -129,7 +131,8 @@
}
}
-void serial_free(serial_t *obj) {
+void serial_free(serial_t *obj)
+{
// Reset UART and disable clock
if (obj->uart == UART_1) {
__USART1_FORCE_RESET();
@@ -149,12 +152,14 @@
serial_irq_ids[obj->index] = 0;
}
-void serial_baud(serial_t *obj, int baudrate) {
+void serial_baud(serial_t *obj, int baudrate)
+{
obj->baudrate = baudrate;
init_uart(obj);
}
-void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
+void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
+{
if (data_bits == 9) {
obj->databits = UART_WORDLENGTH_9B;
} else {
@@ -188,7 +193,8 @@
* INTERRUPTS HANDLING
******************************************************************************/
-static void uart_irq(UARTName name, int id) {
+static void uart_irq(UARTName name, int id)
+{
UartHandle.Instance = (USART_TypeDef *)name;
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TC) != RESET) {
@@ -202,20 +208,24 @@
}
}
-static void uart1_irq(void) {
+static void uart1_irq(void)
+{
uart_irq(UART_1, 0);
}
-static void uart2_irq(void) {
+static void uart2_irq(void)
+{
uart_irq(UART_2, 1);
}
-void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
+void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
+{
irq_handler = handler;
serial_irq_ids[obj->index] = id;
}
-void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
+void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
@@ -265,19 +275,22 @@
* READ/WRITE
******************************************************************************/
-int serial_getc(serial_t *obj) {
+int serial_getc(serial_t *obj)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_readable(obj));
return (int)(uart->RDR & (uint16_t)0xFF);
}
-void serial_putc(serial_t *obj, int c) {
+void serial_putc(serial_t *obj, int c)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_writable(obj));
uart->TDR = (uint32_t)(c & (uint16_t)0xFF);
}
-int serial_readable(serial_t *obj) {
+int serial_readable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is received
@@ -285,7 +298,8 @@
return status;
}
-int serial_writable(serial_t *obj) {
+int serial_writable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is transmitted
@@ -293,21 +307,25 @@
return status;
}
-void serial_clear(serial_t *obj) {
+void serial_clear(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
__HAL_UART_CLEAR_IT(&UartHandle, UART_FLAG_TC);
__HAL_UART_SEND_REQ(&UartHandle, UART_RXDATA_FLUSH_REQUEST);
}
-void serial_pinout_tx(PinName tx) {
+void serial_pinout_tx(PinName tx)
+{
pinmap_pinout(tx, PinMap_UART_TX);
}
-void serial_break_set(serial_t *obj) {
+void serial_break_set(serial_t *obj)
+{
// [TODO]
}
-void serial_break_clear(serial_t *obj) {
+void serial_break_clear(serial_t *obj)
+{
// [TODO]
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/sleep.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/sleep.c Fri Nov 14 09:00:07 2014 +0000
@@ -33,7 +33,8 @@
#include "cmsis.h"
-void sleep(void) {
+void sleep(void)
+{
// Stop HAL systick
HAL_SuspendTick();
// Request to enter SLEEP mode
@@ -42,16 +43,17 @@
HAL_ResumeTick();
}
-void deepsleep(void) {
+void deepsleep(void)
+{
// Request to enter STOP mode with regulator in low power mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
- HAL_InitTick(TICK_INT_PRIORITY);
-
+ HAL_InitTick(TICK_INT_PRIORITY);
+
// After wake-up from STOP reconfigure the PLL
SetSysClock();
-
- HAL_InitTick(TICK_INT_PRIORITY);
+
+ HAL_InitTick(TICK_INT_PRIORITY);
}
#endif
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/spi_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/spi_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -66,7 +66,8 @@
static SPI_HandleTypeDef SpiHandle;
-static void init_spi(spi_t *obj) {
+static void init_spi(spi_t *obj)
+{
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
__HAL_SPI_DISABLE(&SpiHandle);
@@ -88,7 +89,8 @@
__HAL_SPI_ENABLE(&SpiHandle);
}
-void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
+void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
+{
// Determine the SPI to use
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
@@ -137,7 +139,8 @@
init_spi(obj);
}
-void spi_free(spi_t *obj) {
+void spi_free(spi_t *obj)
+{
// Reset SPI and disable clock
if (obj->spi == SPI_1) {
__SPI1_FORCE_RESET();
@@ -158,7 +161,8 @@
pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void spi_format(spi_t *obj, int bits, int mode, int slave) {
+void spi_format(spi_t *obj, int bits, int mode, int slave)
+{
// Save new values
if (bits == 16) {
obj->bits = SPI_DATASIZE_16BIT;
@@ -196,7 +200,8 @@
init_spi(obj);
}
-void spi_frequency(spi_t *obj, int hz) {
+void spi_frequency(spi_t *obj, int hz)
+{
// Note: The frequencies are obtained with SPI clock = 48 MHz (APB clock)
if (hz < 375000) {
obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 188 kHz
@@ -218,7 +223,8 @@
init_spi(obj);
}
-static inline int ssp_readable(spi_t *obj) {
+static inline int ssp_readable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is received
@@ -226,7 +232,8 @@
return status;
}
-static inline int ssp_writeable(spi_t *obj) {
+static inline int ssp_writeable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is transmitted
@@ -234,7 +241,8 @@
return status;
}
-static inline void ssp_write(spi_t *obj, int value) {
+static inline void ssp_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
@@ -248,7 +256,8 @@
}
}
-static inline int ssp_read(spi_t *obj) {
+static inline int ssp_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
@@ -262,35 +271,41 @@
}
}
-static inline int ssp_busy(spi_t *obj) {
+static inline int ssp_busy(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
return status;
}
-int spi_master_write(spi_t *obj, int value) {
- ssp_write(obj, value);
- return ssp_read(obj);
+int spi_master_write(spi_t *obj, int value)
+{
+ ssp_write(obj, value);
+ return ssp_read(obj);
}
-int spi_slave_receive(spi_t *obj) {
- return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);
+int spi_slave_receive(spi_t *obj)
+{
+ return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);
};
-int spi_slave_read(spi_t *obj) {
+int spi_slave_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
- while (!ssp_readable(obj));
+ while (!ssp_readable(obj));
return (int)spi->DR;
}
-void spi_slave_write(spi_t *obj, int value) {
+void spi_slave_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
- while (!ssp_writeable(obj));
+ while (!ssp_writeable(obj));
spi->DR = (uint16_t)value;
}
-int spi_busy(spi_t *obj) {
+int spi_busy(spi_t *obj)
+{
return ssp_busy(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -43,9 +43,10 @@
static volatile uint32_t oc_int_part = 0;
static volatile uint16_t oc_rem_part = 0;
-void set_compare(uint16_t count) {
+void set_compare(uint16_t count)
+{
TimMasterHandle.Instance = TIM_MST;
-
+
// Set new output compare value
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
// Enable IT
@@ -53,9 +54,10 @@
}
// Used to increment the slave counter
-static void tim_update_irq_handler(void) {
+static void tim_update_irq_handler(void)
+{
TimMasterHandle.Instance = TIM_MST;
-
+
// Clear Update interrupt flag
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE);
@@ -64,31 +66,33 @@
}
// Used by interrupt system
-static void tim_oc_irq_handler(void) {
+static void tim_oc_irq_handler(void)
+{
uint16_t cval = TIM_MST->CNT;
TimMasterHandle.Instance = TIM_MST;
-
+
// Clear CC1 interrupt flag
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
- }
- if (oc_rem_part > 0) {
- set_compare(oc_rem_part); // Finish the remaining time left
- oc_rem_part = 0;
+ }
+ if (oc_rem_part > 0) {
+ set_compare(oc_rem_part); // Finish the remaining time left
+ oc_rem_part = 0;
+ } else {
+ if (oc_int_part > 0) {
+ set_compare(0xFFFF);
+ oc_rem_part = cval; // To finish the counter loop the next time
+ oc_int_part--;
} else {
- if (oc_int_part > 0) {
- set_compare(0xFFFF);
- oc_rem_part = cval; // To finish the counter loop the next time
- oc_int_part--;
- } else {
- us_ticker_irq_handler();
- }
+ us_ticker_irq_handler();
}
-
+ }
+
}
-void us_ticker_init(void) {
-
+void us_ticker_init(void)
+{
+
if (us_ticker_inited) return;
us_ticker_inited = 1;
@@ -106,7 +110,7 @@
// Configure interrupts
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE);
- // Update interrupt used for 32-bit counter
+ // Update interrupt used for 32-bit counter
NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)tim_update_irq_handler);
NVIC_EnableIRQ(TIM_MST_UP_IRQ);
@@ -118,7 +122,8 @@
HAL_TIM_Base_Start(&TimMasterHandle);
}
-uint32_t us_ticker_read() {
+uint32_t us_ticker_read()
+{
uint32_t counter, counter2;
if (!us_ticker_inited) us_ticker_init();
// A situation might appear when Master overflows right after Slave is read and before the
@@ -139,7 +144,8 @@
return counter2;
}
-void us_ticker_set_interrupt(timestamp_t timestamp) {
+void us_ticker_set_interrupt(timestamp_t timestamp)
+{
int delta = (int)((uint32_t)timestamp - us_ticker_read());
uint16_t cval = TIM_MST->CNT;
@@ -158,14 +164,16 @@
}
}
-void us_ticker_disable_interrupt(void) {
+void us_ticker_disable_interrupt(void)
+{
TimMasterHandle.Instance = TIM_MST;
- __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
+ __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-void us_ticker_clear_interrupt(void) {
+void us_ticker_clear_interrupt(void)
+{
TimMasterHandle.Instance = TIM_MST;
- if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
+ if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
- }
+ }
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogin_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogin_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -58,7 +58,8 @@
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
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);
@@ -98,7 +99,8 @@
}
}
-static inline uint16_t adc_read(analogin_t *obj) {
+static inline uint16_t adc_read(analogin_t *obj)
+{
ADC_ChannelConfTypeDef sConfig;
AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
@@ -175,14 +177,16 @@
}
}
-uint16_t analogin_read_u16(analogin_t *obj) {
+uint16_t analogin_read_u16(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
// 12-bit to 16-bit conversion
value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F);
return value;
}
-float analogin_read(analogin_t *obj) {
+float analogin_read(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/analogout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -44,7 +44,8 @@
static DAC_HandleTypeDef DacHandle;
-void analogout_init(dac_t *obj, PinName pin) {
+void analogout_init(dac_t *obj, PinName pin)
+{
DAC_ChannelConfTypeDef sConfig;
DacHandle.Instance = DAC;
@@ -75,7 +76,8 @@
analogout_write_u16(obj, 0);
}
-void analogout_free(dac_t *obj) {
+void analogout_free(dac_t *obj)
+{
// Reset DAC and disable clock
__DAC1_FORCE_RESET();
__DAC1_RELEASE_RESET();
@@ -85,7 +87,8 @@
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-static inline void dac_write(dac_t *obj, uint16_t value) {
+static inline void dac_write(dac_t *obj, uint16_t value)
+{
if (obj->pin == PA_4) {
HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, value);
HAL_DAC_Start(&DacHandle, DAC_CHANNEL_1);
@@ -95,7 +98,8 @@
}
}
-static inline int dac_read(dac_t *obj) {
+static inline int dac_read(dac_t *obj)
+{
if (obj->pin == PA_4) {
return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_1);
} else { // PA_5
@@ -103,7 +107,8 @@
}
}
-void analogout_write(dac_t *obj, float value) {
+void analogout_write(dac_t *obj, float value)
+{
if (value < 0.0f) {
dac_write(obj, 0); // Min value
} else if (value > 1.0f) {
@@ -113,7 +118,8 @@
}
}
-void analogout_write_u16(dac_t *obj, uint16_t value) {
+void analogout_write_u16(dac_t *obj, uint16_t value)
+{
if (value > (uint16_t)DAC_RANGE) {
dac_write(obj, (uint16_t)DAC_RANGE); // Max value
} else {
@@ -121,12 +127,14 @@
}
}
-float analogout_read(dac_t *obj) {
+float analogout_read(dac_t *obj)
+{
uint32_t value = dac_read(obj);
return (float)((float)value * (1.0f / (float)DAC_RANGE));
}
-uint16_t analogout_read_u16(dac_t *obj) {
+uint16_t analogout_read_u16(dac_t *obj)
+{
return (uint16_t)dac_read(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -34,7 +34,8 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-uint32_t gpio_set(PinName pin) {
+uint32_t gpio_set(PinName pin)
+{
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@@ -42,7 +43,8 @@
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
-void gpio_init(gpio_t *obj, PinName pin) {
+void gpio_init(gpio_t *obj, PinName pin)
+{
obj->pin = pin;
if (pin == (PinName)NC) {
return;
@@ -61,11 +63,13 @@
obj->reg_clr = &gpio->BRR;
}
-void gpio_mode(gpio_t *obj, PinMode mode) {
+void gpio_mode(gpio_t *obj, PinMode mode)
+{
pin_mode(obj->pin, 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) {
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_irq_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_irq_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -47,7 +47,8 @@
static gpio_irq_handler irq_handler;
-static void handle_interrupt_in(uint32_t irq_index) {
+static void handle_interrupt_in(uint32_t irq_index)
+{
// Retrieve the gpio and pin that generate the irq
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
@@ -68,21 +69,25 @@
}
// EXTI lines 0 to 1
-static void gpio_irq0(void) {
+static void gpio_irq0(void)
+{
handle_interrupt_in(0);
}
// EXTI lines 2 to 3
-static void gpio_irq1(void) {
+static void gpio_irq1(void)
+{
handle_interrupt_in(1);
}
// EXTI lines 4 to 15
-static void gpio_irq2(void) {
+static void gpio_irq2(void)
+{
handle_interrupt_in(2);
}
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
uint32_t irq_index;
@@ -134,7 +139,8 @@
return 0;
}
-void gpio_irq_free(gpio_irq_t *obj) {
+void gpio_irq_free(gpio_irq_t *obj)
+{
channel_ids[obj->irq_index] = 0;
channel_gpio[obj->irq_index] = 0;
channel_pin[obj->irq_index] = 0;
@@ -191,11 +197,13 @@
pin_function(obj->pin, STM_PIN_DATA(mode, pull, 0));
}
-void gpio_irq_enable(gpio_irq_t *obj) {
+void gpio_irq_enable(gpio_irq_t *obj)
+{
NVIC_EnableIRQ(obj->irq_n);
}
-void gpio_irq_disable(gpio_irq_t *obj) {
+void gpio_irq_disable(gpio_irq_t *obj)
+{
NVIC_DisableIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_object.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/gpio_object.h Fri Nov 14 09:00:07 2014 +0000
@@ -48,7 +48,8 @@
__IO uint32_t *reg_clr;
} 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) {
*obj->reg_set = obj->mask;
@@ -57,7 +58,8 @@
}
}
-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);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -62,7 +62,8 @@
int i2c1_inited = 0;
int i2c2_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -71,7 +72,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C1 clock and pinout if not done
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
__HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
__I2C1_CLK_ENABLE();
@@ -82,14 +83,14 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C2 clock and pinout if not done
- if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+ if ((obj->i2c == I2C_2) && !i2c2_inited) {
i2c2_inited = 1;
__I2C2_CLK_ENABLE();
- // Configure I2C pins
- pinmap_pinout(sda, PinMap_I2C_SDA);
- pinmap_pinout(scl, PinMap_I2C_SCL);
- pin_mode(sda, OpenDrain);
- pin_mode(scl, OpenDrain);
+ // Configure I2C pins
+ pinmap_pinout(sda, PinMap_I2C_SDA);
+ pinmap_pinout(scl, PinMap_I2C_SCL);
+ pin_mode(sda, OpenDrain);
+ pin_mode(scl, OpenDrain);
}
// Reset to clear pending flags if any
@@ -99,14 +100,15 @@
i2c_frequency(obj, 100000); // 100 kHz per default
}
-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);
int timeout;
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0
switch (hz) {
@@ -134,7 +136,8 @@
HAL_I2C_Init(&I2cHandle);
}
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -157,7 +160,8 @@
return 0;
}
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
// Generate the STOP condition
@@ -166,7 +170,8 @@
return 0;
}
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -211,7 +216,8 @@
return length;
}
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -255,7 +261,8 @@
return count;
}
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -270,7 +277,8 @@
return (int)i2c->RXDR;
}
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -287,12 +295,13 @@
return 1;
}
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
if (obj->i2c == I2C_1) {
__I2C1_FORCE_RESET();
@@ -306,7 +315,8 @@
#if DEVICE_I2CSLAVE
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg = 0;
@@ -324,7 +334,8 @@
i2c->OAR1 |= I2C_OAR1_OA1EN;
}
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg;
@@ -350,7 +361,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int retValue = NoData;
@@ -368,7 +380,8 @@
return (retValue);
}
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
char size = 0;
while (size < length) data[size++] = (char)i2c_byte_read(obj, 0);
@@ -376,7 +389,8 @@
return size;
}
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
char size = 0;
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/mbed_overrides.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/mbed_overrides.c Fri Nov 14 09:00:07 2014 +0000
@@ -28,7 +28,8 @@
#include "cmsis.h"
// This function is called after RAM initialization and before main.
-void mbed_sdk_init() {
+void mbed_sdk_init()
+{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pinmap.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pinmap.c Fri Nov 14 09:00:07 2014 +0000
@@ -50,7 +50,8 @@
};
// Enable GPIO clock and return GPIO base address
-uint32_t Set_GPIO_Clock(uint32_t port_idx) {
+uint32_t Set_GPIO_Clock(uint32_t port_idx)
+{
uint32_t gpio_add = 0;
switch (port_idx) {
case PortA:
@@ -83,7 +84,8 @@
/**
* 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)
+{
MBED_ASSERT(pin != (PinName)NC);
// Get the pin informations
@@ -117,7 +119,8 @@
/**
* Configure pin pull-up/pull-down
*/
-void pin_mode(PinName pin, PinMode mode) {
+void pin_mode(PinName pin, PinMode mode)
+{
MBED_ASSERT(pin != (PinName)NC);
uint32_t port_index = STM_PORT(pin);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/port_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/port_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -38,11 +38,13 @@
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, ...)
// low nibble = pin number
-PinName port_pin(PortName port, int pin_n) {
+PinName port_pin(PortName port, int pin_n)
+{
return (PinName)(pin_n + (port << 4));
}
-void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
+void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
+{
uint32_t port_index = (uint32_t)port;
// Enable GPIO clock
@@ -59,7 +61,8 @@
port_dir(obj, dir);
}
-void port_dir(port_t *obj, PinDirection dir) {
+void port_dir(port_t *obj, PinDirection dir)
+{
uint32_t i;
obj->direction = dir;
for (i = 0; i < 16; i++) { // Process all pins
@@ -73,7 +76,8 @@
}
}
-void port_mode(port_t *obj, PinMode mode) {
+void port_mode(port_t *obj, PinMode mode)
+{
uint32_t i;
for (i = 0; i < 16; i++) { // Process all pins
if (obj->mask & (1 << i)) { // If the pin is used
@@ -82,11 +86,13 @@
}
}
-void port_write(port_t *obj, int value) {
+void port_write(port_t *obj, int value)
+{
*obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask);
}
-int port_read(port_t *obj) {
+int port_read(port_t *obj)
+{
if (obj->direction == PIN_OUTPUT) {
return (*obj->reg_out & obj->mask);
} else { // PIN_INPUT
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pwmout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/pwmout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -86,7 +86,8 @@
static TIM_HandleTypeDef TimHandle;
-void pwmout_init(pwmout_t* obj, PinName pin) {
+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);
@@ -113,12 +114,14 @@
pwmout_period_us(obj, 20000); // 20 ms per default
}
-void pwmout_free(pwmout_t* obj) {
+void pwmout_free(pwmout_t* obj)
+{
// Configure GPIO
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void pwmout_write(pwmout_t* obj, float value) {
+void pwmout_write(pwmout_t* obj, float value)
+{
TIM_OC_InitTypeDef sConfig;
int channel = 0;
int complementary_channel = 0;
@@ -197,7 +200,8 @@
}
}
-float pwmout_read(pwmout_t* obj) {
+float pwmout_read(pwmout_t* obj)
+{
float value = 0;
if (obj->period > 0) {
value = (float)(obj->pulse) / (float)(obj->period);
@@ -205,15 +209,18 @@
return ((value > (float)1.0) ? (float)(1.0) : (value));
}
-void pwmout_period(pwmout_t* obj, float seconds) {
+void pwmout_period(pwmout_t* obj, float seconds)
+{
pwmout_period_us(obj, seconds * 1000000.0f);
}
-void pwmout_period_ms(pwmout_t* obj, int ms) {
+void pwmout_period_ms(pwmout_t* obj, int ms)
+{
pwmout_period_us(obj, ms * 1000);
}
-void pwmout_period_us(pwmout_t* obj, int us) {
+void pwmout_period_us(pwmout_t* obj, int us)
+{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
@@ -238,15 +245,18 @@
__HAL_TIM_ENABLE(&TimHandle);
}
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
+void pwmout_pulsewidth(pwmout_t* obj, float seconds)
+{
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
}
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
+void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
+{
pwmout_pulsewidth_us(obj, ms * 1000);
}
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
+void pwmout_pulsewidth_us(pwmout_t* obj, int us)
+{
float value = (float)us / (float)obj->period;
pwmout_write(obj, value);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/rtc_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/rtc_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -37,7 +37,8 @@
static RTC_HandleTypeDef RtcHandle;
-void rtc_init(void) {
+void rtc_init(void)
+{
RCC_OscInitTypeDef RCC_OscInitStruct;
uint32_t rtc_freq = 0;
@@ -94,7 +95,8 @@
}
}
-void rtc_free(void) {
+void rtc_free(void)
+{
// Enable Power clock
__PWR_CLK_ENABLE();
@@ -119,7 +121,8 @@
rtc_inited = 0;
}
-int rtc_isenabled(void) {
+int rtc_isenabled(void)
+{
return rtc_inited;
}
@@ -140,7 +143,8 @@
tm_yday days since January 1 0-365
tm_isdst Daylight Saving Time flag
*/
-time_t rtc_read(void) {
+time_t rtc_read(void)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
struct tm timeinfo;
@@ -167,7 +171,8 @@
return t;
}
-void rtc_write(time_t t) {
+void rtc_write(time_t t)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -73,7 +73,8 @@
int stdio_uart_inited = 0;
serial_t stdio_uart;
-static void init_uart(serial_t *obj) {
+static void init_uart(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
UartHandle.Init.BaudRate = obj->baudrate;
@@ -93,11 +94,12 @@
// Disable the reception overrun detection
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
UartHandle.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
-
+
HAL_UART_Init(&UartHandle);
}
-void serial_init(serial_t *obj, PinName tx, PinName rx) {
+void serial_init(serial_t *obj, PinName tx, PinName rx)
+{
// Determine the UART to use (UART_1, UART_2, ...)
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
@@ -153,7 +155,8 @@
}
}
-void serial_free(serial_t *obj) {
+void serial_free(serial_t *obj)
+{
// Reset UART and disable clock
if (obj->uart == UART_1) {
__USART1_FORCE_RESET();
@@ -183,12 +186,14 @@
serial_irq_ids[obj->index] = 0;
}
-void serial_baud(serial_t *obj, int baudrate) {
+void serial_baud(serial_t *obj, int baudrate)
+{
obj->baudrate = baudrate;
init_uart(obj);
}
-void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
+void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
+{
if (data_bits == 9) {
obj->databits = UART_WORDLENGTH_9B;
} else {
@@ -222,7 +227,8 @@
* INTERRUPTS HANDLING
******************************************************************************/
-static void uart_irq(UARTName name, int id) {
+static void uart_irq(UARTName name, int id)
+{
UartHandle.Instance = (USART_TypeDef *)name;
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TC) != RESET) {
@@ -236,28 +242,34 @@
}
}
-static void uart1_irq(void) {
+static void uart1_irq(void)
+{
uart_irq(UART_1, 0);
}
-static void uart2_irq(void) {
+static void uart2_irq(void)
+{
uart_irq(UART_2, 1);
}
-static void uart3_irq(void) {
+static void uart3_irq(void)
+{
uart_irq(UART_3, 2);
}
-static void uart4_irq(void) {
+static void uart4_irq(void)
+{
uart_irq(UART_4, 3);
}
-void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
+void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
+{
irq_handler = handler;
serial_irq_ids[obj->index] = id;
}
-void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
+void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
@@ -317,19 +329,22 @@
* READ/WRITE
******************************************************************************/
-int serial_getc(serial_t *obj) {
+int serial_getc(serial_t *obj)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_readable(obj));
return (int)(uart->RDR & (uint16_t)0xFF);
}
-void serial_putc(serial_t *obj, int c) {
+void serial_putc(serial_t *obj, int c)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_writable(obj));
uart->TDR = (uint32_t)(c & (uint16_t)0xFF);
}
-int serial_readable(serial_t *obj) {
+int serial_readable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is received
@@ -337,7 +352,8 @@
return status;
}
-int serial_writable(serial_t *obj) {
+int serial_writable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is transmitted
@@ -345,21 +361,25 @@
return status;
}
-void serial_clear(serial_t *obj) {
+void serial_clear(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
__HAL_UART_CLEAR_IT(&UartHandle, UART_FLAG_TC);
__HAL_UART_SEND_REQ(&UartHandle, UART_RXDATA_FLUSH_REQUEST);
}
-void serial_pinout_tx(PinName tx) {
+void serial_pinout_tx(PinName tx)
+{
pinmap_pinout(tx, PinMap_UART_TX);
}
-void serial_break_set(serial_t *obj) {
+void serial_break_set(serial_t *obj)
+{
// [TODO]
}
-void serial_break_clear(serial_t *obj) {
+void serial_break_clear(serial_t *obj)
+{
// [TODO]
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/sleep.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/sleep.c Fri Nov 14 09:00:07 2014 +0000
@@ -33,7 +33,8 @@
#include "cmsis.h"
-void sleep(void) {
+void sleep(void)
+{
// Stop HAL systick
HAL_SuspendTick();
// Request to enter SLEEP mode
@@ -42,7 +43,8 @@
HAL_ResumeTick();
}
-void deepsleep(void) {
+void deepsleep(void)
+{
// Request to enter STOP mode with regulator in low power mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/spi_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -70,7 +70,8 @@
static SPI_HandleTypeDef SpiHandle;
-static void init_spi(spi_t *obj) {
+static void init_spi(spi_t *obj)
+{
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
__HAL_SPI_DISABLE(&SpiHandle);
@@ -92,7 +93,8 @@
__HAL_SPI_ENABLE(&SpiHandle);
}
-void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
+void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
+{
// Determine the SPI to use
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
@@ -141,7 +143,8 @@
init_spi(obj);
}
-void spi_free(spi_t *obj) {
+void spi_free(spi_t *obj)
+{
// Reset SPI and disable clock
if (obj->spi == SPI_1) {
__SPI1_FORCE_RESET();
@@ -162,7 +165,8 @@
pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void spi_format(spi_t *obj, int bits, int mode, int slave) {
+void spi_format(spi_t *obj, int bits, int mode, int slave)
+{
// Save new values
if (bits == 16) {
obj->bits = SPI_DATASIZE_16BIT;
@@ -200,7 +204,8 @@
init_spi(obj);
}
-void spi_frequency(spi_t *obj, int hz) {
+void spi_frequency(spi_t *obj, int hz)
+{
// Note: The frequencies are obtained with SPI clock = 48 MHz (APB clock)
if (hz < 375000) {
obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 188 kHz
@@ -222,7 +227,8 @@
init_spi(obj);
}
-static inline int ssp_readable(spi_t *obj) {
+static inline int ssp_readable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is received
@@ -230,7 +236,8 @@
return status;
}
-static inline int ssp_writeable(spi_t *obj) {
+static inline int ssp_writeable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is transmitted
@@ -238,7 +245,8 @@
return status;
}
-static inline void ssp_write(spi_t *obj, int value) {
+static inline void ssp_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -251,7 +259,8 @@
}
}
-static inline int ssp_read(spi_t *obj) {
+static inline int ssp_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -264,23 +273,27 @@
}
}
-static inline int ssp_busy(spi_t *obj) {
+static inline int ssp_busy(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
return status;
}
-int spi_master_write(spi_t *obj, int value) {
+int spi_master_write(spi_t *obj, int value)
+{
ssp_write(obj, value);
return ssp_read(obj);
}
-int spi_slave_receive(spi_t *obj) {
+int spi_slave_receive(spi_t *obj)
+{
return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);
};
-int spi_slave_read(spi_t *obj) {
+int spi_slave_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -293,7 +306,8 @@
}
}
-void spi_slave_write(spi_t *obj, int value) {
+void spi_slave_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -306,7 +320,8 @@
}
}
-int spi_busy(spi_t *obj) {
+int spi_busy(spi_t *obj)
+{
return ssp_busy(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -37,7 +37,8 @@
static TIM_HandleTypeDef TimMasterHandle;
static int us_ticker_inited = 0;
-void us_ticker_init(void) {
+void us_ticker_init(void)
+{
if (us_ticker_inited) return;
us_ticker_inited = 1;
@@ -63,22 +64,26 @@
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
}
-uint32_t us_ticker_read() {
+uint32_t us_ticker_read()
+{
if (!us_ticker_inited) us_ticker_init();
return TIM_MST->CNT;
}
-void us_ticker_set_interrupt(timestamp_t timestamp) {
+void us_ticker_set_interrupt(timestamp_t timestamp)
+{
// Set new output compare value
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-void us_ticker_disable_interrupt(void) {
+void us_ticker_disable_interrupt(void)
+{
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-void us_ticker_clear_interrupt(void) {
+void us_ticker_clear_interrupt(void)
+{
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/analogin_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/analogin_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -56,7 +56,8 @@
int adc_inited = 0;
-void analogin_init(analogin_t *obj, PinName pin) {
+void analogin_init(analogin_t *obj, PinName pin)
+{
ADC_TypeDef *adc;
ADC_InitTypeDef ADC_InitStructure;
@@ -102,7 +103,8 @@
}
}
-static inline uint16_t adc_read(analogin_t *obj) {
+static inline uint16_t adc_read(analogin_t *obj)
+{
// Get ADC registers structure address
ADC_TypeDef *adc = (ADC_TypeDef *)(obj->adc);
int channel = 0;
@@ -170,14 +172,16 @@
return (ADC_GetConversionValue(adc)); // Get conversion value
}
-uint16_t analogin_read_u16(analogin_t *obj) {
+uint16_t analogin_read_u16(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
// 12-bit to 16-bit conversion
value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F);
return value;
}
-float analogin_read(analogin_t *obj) {
+float analogin_read(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -34,14 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-uint32_t gpio_set(PinName pin) {
+uint32_t gpio_set(PinName pin)
+{
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
-void gpio_init(gpio_t *obj, PinName pin) {
+void gpio_init(gpio_t *obj, PinName pin)
+{
obj->pin = pin;
if (pin == (PinName)NC)
return;
@@ -59,11 +61,13 @@
obj->reg_clr = &gpio->BRR;
}
-void gpio_mode(gpio_t *obj, PinMode mode) {
+void gpio_mode(gpio_t *obj, PinMode mode)
+{
pin_mode(obj->pin, 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) {
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_irq_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -46,7 +46,8 @@
static gpio_irq_handler irq_handler;
-static void handle_interrupt_in(uint32_t irq_index) {
+static void handle_interrupt_in(uint32_t irq_index)
+{
// Retrieve the gpio and pin that generate the irq
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
@@ -67,31 +68,39 @@
}
// The irq_index is passed to the function
-static void gpio_irq0(void) {
+static void gpio_irq0(void)
+{
handle_interrupt_in(0); // EXTI line 0
}
-static void gpio_irq1(void) {
+static void gpio_irq1(void)
+{
handle_interrupt_in(1); // EXTI line 1
}
-static void gpio_irq2(void) {
+static void gpio_irq2(void)
+{
handle_interrupt_in(2); // EXTI line 2
}
-static void gpio_irq3(void) {
+static void gpio_irq3(void)
+{
handle_interrupt_in(3); // EXTI line 3
}
-static void gpio_irq4(void) {
+static void gpio_irq4(void)
+{
handle_interrupt_in(4); // EXTI line 4
}
-static void gpio_irq5(void) {
+static void gpio_irq5(void)
+{
handle_interrupt_in(5); // EXTI lines 5 to 9
}
-static void gpio_irq6(void) {
+static void gpio_irq6(void)
+{
handle_interrupt_in(6); // EXTI lines 10 to 15
}
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
uint32_t irq_index;
@@ -193,7 +202,8 @@
return 0;
}
-void gpio_irq_free(gpio_irq_t *obj) {
+void gpio_irq_free(gpio_irq_t *obj)
+{
channel_ids[obj->irq_index] = 0;
channel_gpio[obj->irq_index] = 0;
channel_pin[obj->irq_index] = 0;
@@ -204,7 +214,8 @@
obj->event = EDGE_NONE;
}
-void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
+void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
+{
EXTI_InitTypeDef EXTI_InitStructure;
uint32_t pin_index = channel_pin[obj->irq_index];
@@ -234,8 +245,7 @@
obj->event = EDGE_FALL;
}
}
- }
- else { // Disable
+ } else { // Disable
if (event == IRQ_RISE) {
if ((obj->event == EDGE_FALL) || (obj->event == EDGE_BOTH)) {
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
@@ -255,17 +265,19 @@
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
obj->event = EDGE_NONE;
}
- }
+ }
}
EXTI_Init(&EXTI_InitStructure);
}
-void gpio_irq_enable(gpio_irq_t *obj) {
+void gpio_irq_enable(gpio_irq_t *obj)
+{
NVIC_EnableIRQ(obj->irq_n);
}
-void gpio_irq_disable(gpio_irq_t *obj) {
+void gpio_irq_disable(gpio_irq_t *obj)
+{
NVIC_DisableIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_object.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/gpio_object.h Fri Nov 14 09:00:07 2014 +0000
@@ -48,7 +48,8 @@
__IO uint32_t *reg_clr;
} 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) {
*obj->reg_set = obj->mask;
@@ -57,7 +58,8 @@
}
}
-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);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -58,7 +58,8 @@
int i2c1_inited = 0;
int i2c2_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -67,7 +68,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C clock and configure I2C pins if not done before
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
// Configure I2C pins
@@ -76,7 +77,7 @@
pinmap_pinout(sda, PinMap_I2C_SDA);
pin_mode(sda, OpenDrain);
}
- if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+ if ((obj->i2c == I2C_2) && !i2c2_inited) {
i2c2_inited = 1;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
// Configure I2C pins
@@ -93,7 +94,8 @@
i2c_frequency(obj, 100000); // 100 kHz per default
}
-void i2c_frequency(i2c_t *obj, int hz) {
+void i2c_frequency(i2c_t *obj, int hz)
+{
int timeout;
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
@@ -120,7 +122,8 @@
}
}
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -141,7 +144,8 @@
return 0;
}
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_GenerateSTOP(i2c, ENABLE);
@@ -149,7 +153,8 @@
return 0;
}
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
int count;
@@ -188,7 +193,8 @@
return length;
}
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
int count;
@@ -222,7 +228,8 @@
return count;
}
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint8_t data;
int timeout;
@@ -249,7 +256,8 @@
return (int)data;
}
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -258,7 +266,7 @@
// Wait until the byte is transmitted
timeout = FLAG_TIMEOUT;
while ((I2C_GetFlagStatus(i2c, I2C_FLAG_TXE) == RESET) &&
- (I2C_GetFlagStatus(i2c, I2C_FLAG_BTF) == RESET)) {
+ (I2C_GetFlagStatus(i2c, I2C_FLAG_BTF) == RESET)) {
timeout--;
if (timeout == 0) {
return 0;
@@ -268,7 +276,8 @@
return 1;
}
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -289,7 +298,8 @@
#if DEVICE_I2CSLAVE
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg;
@@ -303,7 +313,8 @@
i2c->OAR1 = tmpreg;
}
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
// Nothing to do
}
@@ -313,7 +324,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
int retValue = NoData;
uint32_t event;
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
@@ -355,7 +367,8 @@
return (retValue);
}
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
int count = 0;
// Read all bytes
@@ -366,7 +379,8 @@
return count;
}
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
int count = 0;
// Write all bytes
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/mbed_overrides.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/mbed_overrides.c Fri Nov 14 09:00:07 2014 +0000
@@ -28,7 +28,8 @@
#include "cmsis.h"
// This function is called after RAM initialization and before main.
-void mbed_sdk_init() {
+void mbed_sdk_init()
+{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pinmap.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pinmap.c Fri Nov 14 09:00:07 2014 +0000
@@ -48,7 +48,8 @@
};
// Enable GPIO clock and return GPIO base address
-uint32_t Set_GPIO_Clock(uint32_t port_idx) {
+uint32_t Set_GPIO_Clock(uint32_t port_idx)
+{
uint32_t gpio_add = 0;
switch (port_idx) {
case PortA:
@@ -77,7 +78,8 @@
/**
* Configure pin (input, output, alternate function or analog) + output speed + AF
*/
-void pin_function(PinName pin, int data) {
+void pin_function(PinName pin, int data)
+{
MBED_ASSERT(pin != (PinName)NC);
// Get the pin informations
uint32_t mode = STM_PIN_MODE(data);
@@ -119,7 +121,8 @@
/**
* Configure pin pull-up/pull-down
*/
-void pin_mode(PinName pin, PinMode mode) {
+void pin_mode(PinName pin, PinMode mode)
+{
MBED_ASSERT(pin != (PinName)NC);
GPIO_InitTypeDef GPIO_InitStructure;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/port_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/port_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -39,11 +39,13 @@
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, ...)
// low nibble = pin number
-PinName port_pin(PortName port, int pin_n) {
+PinName port_pin(PortName port, int pin_n)
+{
return (PinName)(pin_n + (port << 4));
}
-void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
+void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
+{
uint32_t port_index = (uint32_t)port;
// Enable GPIO clock
@@ -60,7 +62,8 @@
port_dir(obj, dir);
}
-void port_dir(port_t *obj, PinDirection dir) {
+void port_dir(port_t *obj, PinDirection dir)
+{
uint32_t i;
obj->direction = dir;
for (i = 0; i < 16; i++) { // Process all pins
@@ -74,7 +77,8 @@
}
}
-void port_mode(port_t *obj, PinMode mode) {
+void port_mode(port_t *obj, PinMode mode)
+{
uint32_t i;
for (i = 0; i < 16; i++) { // Process all pins
if (obj->mask & (1 << i)) { // If the pin is used
@@ -83,11 +87,13 @@
}
}
-void port_write(port_t *obj, int value) {
+void port_write(port_t *obj, int value)
+{
*obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask);
}
-int port_read(port_t *obj) {
+int port_read(port_t *obj)
+{
if (obj->direction == PIN_OUTPUT) {
return (*obj->reg_out & obj->mask);
} else { // PIN_INPUT
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pwmout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pwmout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -73,7 +73,8 @@
{NC, NC, 0}
};
-void pwmout_init(pwmout_t* obj, PinName pin) {
+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);
MBED_ASSERT(obj->pwm != (PWMName)NC);
@@ -94,12 +95,14 @@
pwmout_period_us(obj, 20000); // 20 ms per default
}
-void pwmout_free(pwmout_t* obj) {
+void pwmout_free(pwmout_t* obj)
+{
// Configure GPIO
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
}
-void pwmout_write(pwmout_t* obj, float value) {
+void pwmout_write(pwmout_t* obj, float value)
+{
TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
TIM_OCInitTypeDef TIM_OCInitStructure;
@@ -193,7 +196,8 @@
TIM_CtrlPWMOutputs(tim, ENABLE);
}
-float pwmout_read(pwmout_t* obj) {
+float pwmout_read(pwmout_t* obj)
+{
float value = 0;
if (obj->period > 0) {
value = (float)(obj->pulse) / (float)(obj->period);
@@ -201,15 +205,18 @@
return ((value > 1.0) ? (1.0) : (value));
}
-void pwmout_period(pwmout_t* obj, float seconds) {
+void pwmout_period(pwmout_t* obj, float seconds)
+{
pwmout_period_us(obj, seconds * 1000000.0f);
}
-void pwmout_period_ms(pwmout_t* obj, int ms) {
+void pwmout_period_ms(pwmout_t* obj, int ms)
+{
pwmout_period_us(obj, ms * 1000);
}
-void pwmout_period_us(pwmout_t* obj, int us) {
+void pwmout_period_us(pwmout_t* obj, int us)
+{
TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
float dc = pwmout_read(obj);
@@ -231,15 +238,18 @@
TIM_Cmd(tim, ENABLE);
}
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
+void pwmout_pulsewidth(pwmout_t* obj, float seconds)
+{
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
}
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
+void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
+{
pwmout_pulsewidth_us(obj, ms * 1000);
}
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
+void pwmout_pulsewidth_us(pwmout_t* obj, int us)
+{
float value = (float)us / (float)obj->period;
pwmout_write(obj, value);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/rtc_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/rtc_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -37,7 +37,8 @@
static int rtc_inited = 0;
-void rtc_init(void) {
+void rtc_init(void)
+{
uint32_t StartUpCounter = 0;
uint32_t LSEStatus = 0;
uint32_t rtc_freq = 0;
@@ -86,7 +87,8 @@
rtc_inited = 1;
}
-void rtc_free(void) {
+void rtc_free(void)
+{
// Disable RTC, LSE and LSI clocks
PWR_BackupAccessCmd(ENABLE); // Allow access to Backup Domain
RCC_RTCCLKCmd(DISABLE);
@@ -96,15 +98,18 @@
rtc_inited = 0;
}
-int rtc_isenabled(void) {
+int rtc_isenabled(void)
+{
return rtc_inited;
}
-time_t rtc_read(void) {
+time_t rtc_read(void)
+{
return (time_t)RTC_GetCounter();
}
-void rtc_write(time_t t) {
+void rtc_write(time_t t)
+{
RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished
RTC_SetCounter(t); // Change the current time
RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -63,7 +63,8 @@
int stdio_uart_inited = 0;
serial_t stdio_uart;
-static void init_usart(serial_t *obj) {
+static void init_usart(serial_t *obj)
+{
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
USART_InitTypeDef USART_InitStructure;
@@ -88,7 +89,8 @@
USART_Cmd(usart, ENABLE);
}
-void serial_init(serial_t *obj, PinName tx, PinName rx) {
+void serial_init(serial_t *obj, PinName tx, PinName rx)
+{
// Determine the UART to use (UART_1, UART_2, ...)
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
@@ -133,7 +135,8 @@
}
}
-void serial_free(serial_t *obj) {
+void serial_free(serial_t *obj)
+{
// Reset UART and disable clock
if (obj->uart == UART_1) {
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
@@ -158,12 +161,14 @@
serial_irq_ids[obj->index] = 0;
}
-void serial_baud(serial_t *obj, int baudrate) {
+void serial_baud(serial_t *obj, int baudrate)
+{
obj->baudrate = baudrate;
init_usart(obj);
}
-void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
+void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
+{
if (data_bits == 9) {
obj->databits = USART_WordLength_9b;
} else {
@@ -198,7 +203,8 @@
******************************************************************************/
// not api
-static void uart_irq(USART_TypeDef* usart, int id) {
+static void uart_irq(USART_TypeDef* usart, int id)
+{
if (serial_irq_ids[id] != 0) {
if (USART_GetITStatus(usart, USART_IT_TC) != RESET) {
irq_handler(serial_irq_ids[id], TxIrq);
@@ -211,22 +217,27 @@
}
}
-static void uart1_irq(void) {
+static void uart1_irq(void)
+{
uart_irq((USART_TypeDef*)UART_1, 0);
}
-static void uart2_irq(void) {
+static void uart2_irq(void)
+{
uart_irq((USART_TypeDef*)UART_2, 1);
}
-static void uart3_irq(void) {
+static void uart3_irq(void)
+{
uart_irq((USART_TypeDef*)UART_3, 2);
}
-void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
+void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
+{
irq_handler = handler;
serial_irq_ids[obj->index] = id;
}
-void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
+void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
@@ -280,19 +291,22 @@
* READ/WRITE
******************************************************************************/
-int serial_getc(serial_t *obj) {
+int serial_getc(serial_t *obj)
+{
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
while (!serial_readable(obj));
return (int)(USART_ReceiveData(usart));
}
-void serial_putc(serial_t *obj, int c) {
+void serial_putc(serial_t *obj, int c)
+{
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
while (!serial_writable(obj));
USART_SendData(usart, (uint16_t)c);
}
-int serial_readable(serial_t *obj) {
+int serial_readable(serial_t *obj)
+{
int status;
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
// Check if data is received
@@ -300,7 +314,8 @@
return status;
}
-int serial_writable(serial_t *obj) {
+int serial_writable(serial_t *obj)
+{
int status;
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
// Check if data is transmitted
@@ -308,22 +323,26 @@
return status;
}
-void serial_clear(serial_t *obj) {
+void serial_clear(serial_t *obj)
+{
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
USART_ClearFlag(usart, USART_FLAG_TXE);
USART_ClearFlag(usart, USART_FLAG_RXNE);
}
-void serial_pinout_tx(PinName tx) {
+void serial_pinout_tx(PinName tx)
+{
pinmap_pinout(tx, PinMap_UART_TX);
}
-void serial_break_set(serial_t *obj) {
+void serial_break_set(serial_t *obj)
+{
USART_TypeDef *usart = (USART_TypeDef *)(obj->uart);
USART_SendBreak(usart);
}
-void serial_break_clear(serial_t *obj) {
+void serial_break_clear(serial_t *obj)
+{
}
#endif
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/sleep.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/sleep.c Fri Nov 14 09:00:07 2014 +0000
@@ -33,7 +33,8 @@
#include "cmsis.h"
-void sleep(void) {
+void sleep(void)
+{
// Disable us_ticker update interrupt
TIM_ITConfig(TIM1, TIM_IT_Update, DISABLE);
@@ -44,7 +45,8 @@
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
}
-void deepsleep(void) {
+void deepsleep(void)
+{
// Disable us_ticker update interrupt
TIM_ITConfig(TIM1, TIM_IT_Update, DISABLE);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/spi_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/spi_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -64,7 +64,8 @@
{NC, NC, 0}
};
-static void init_spi(spi_t *obj) {
+static void init_spi(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
SPI_InitTypeDef SPI_InitStructure;
@@ -84,7 +85,8 @@
SPI_Cmd(spi, ENABLE);
}
-void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
+void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
+{
// Determine the SPI to use
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
@@ -133,7 +135,8 @@
init_spi(obj);
}
-void spi_free(spi_t *obj) {
+void spi_free(spi_t *obj)
+{
// Reset SPI and disable clock
if (obj->spi == SPI_1) {
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
@@ -154,7 +157,8 @@
pin_function(obj->pin_ssel, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
}
-void spi_format(spi_t *obj, int bits, int mode, int slave) {
+void spi_format(spi_t *obj, int bits, int mode, int slave)
+{
// Save new values
if (bits == 16) {
obj->bits = SPI_DataSize_16b;
@@ -192,7 +196,8 @@
init_spi(obj);
}
-void spi_frequency(spi_t *obj, int hz) {
+void spi_frequency(spi_t *obj, int hz)
+{
if (obj->spi == SPI_1) {
// Values depend of PCLK2: 64 MHz if HSI is used, 72 MHz if HSE is used
if (hz < 500000) {
@@ -238,7 +243,8 @@
init_spi(obj);
}
-static inline int ssp_readable(spi_t *obj) {
+static inline int ssp_readable(spi_t *obj)
+{
int status;
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
// Check if data is received
@@ -246,7 +252,8 @@
return status;
}
-static inline int ssp_writeable(spi_t *obj) {
+static inline int ssp_writeable(spi_t *obj)
+{
int status;
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
// Check if data is transmitted
@@ -254,46 +261,54 @@
return status;
}
-static inline void ssp_write(spi_t *obj, int value) {
+static inline void ssp_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
SPI_I2S_SendData(spi, (uint16_t)value);
}
-static inline int ssp_read(spi_t *obj) {
+static inline int ssp_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
return (int)SPI_I2S_ReceiveData(spi);
}
-static inline int ssp_busy(spi_t *obj) {
+static inline int ssp_busy(spi_t *obj)
+{
int status;
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
status = ((SPI_I2S_GetFlagStatus(spi, SPI_I2S_FLAG_BSY) != RESET) ? 1 : 0);
return status;
}
-int spi_master_write(spi_t *obj, int value) {
+int spi_master_write(spi_t *obj, int value)
+{
ssp_write(obj, value);
return ssp_read(obj);
}
-int spi_slave_receive(spi_t *obj) {
+int spi_slave_receive(spi_t *obj)
+{
return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);
};
-int spi_slave_read(spi_t *obj) {
+int spi_slave_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
return (int)SPI_I2S_ReceiveData(spi);
}
-void spi_slave_write(spi_t *obj, int value) {
+void spi_slave_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
SPI_I2S_SendData(spi, (uint16_t)value);
}
-int spi_busy(spi_t *obj) {
+int spi_busy(spi_t *obj)
+{
return ssp_busy(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -39,14 +39,16 @@
static volatile uint32_t oc_int_part = 0;
static volatile uint16_t oc_rem_part = 0;
-void set_compare(uint16_t count) {
+void set_compare(uint16_t count)
+{
// Set new output compare value
TIM_SetCompare1(TIM_MST, count);
// Enable IT
TIM_ITConfig(TIM_MST, TIM_IT_CC1, ENABLE);
}
-static void tim_irq_handler(void) {
+static void tim_irq_handler(void)
+{
uint16_t cval = TIM_MST->CNT;
if (TIM_GetITStatus(TIM_MST, TIM_IT_Update) == SET) {
@@ -71,7 +73,8 @@
}
}
-void us_ticker_init(void) {
+void us_ticker_init(void)
+{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
if (us_ticker_inited) return;
@@ -100,7 +103,8 @@
TIM_Cmd(TIM_MST, ENABLE);
}
-uint32_t us_ticker_read() {
+uint32_t us_ticker_read()
+{
uint32_t counter, counter2;
if (!us_ticker_inited) us_ticker_init();
// A situation might appear when Master overflows right after Slave is read and before the
@@ -121,7 +125,8 @@
return counter2;
}
-void us_ticker_set_interrupt(timestamp_t timestamp) {
+void us_ticker_set_interrupt(timestamp_t timestamp)
+{
int delta = (int)((uint32_t)timestamp - us_ticker_read());
uint16_t cval = TIM_MST->CNT;
@@ -140,10 +145,12 @@
}
}
-void us_ticker_disable_interrupt(void) {
+void us_ticker_disable_interrupt(void)
+{
TIM_ITConfig(TIM_MST, TIM_IT_CC1, DISABLE);
}
-void us_ticker_clear_interrupt(void) {
+void us_ticker_clear_interrupt(void)
+{
TIM_ClearITPendingBit(TIM_MST, TIM_IT_CC1);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -127,7 +127,7 @@
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
@@ -359,10 +359,10 @@
void i2c_reset(i2c_t *obj)
{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
__I2C1_FORCE_RESET();
__I2C1_RELEASE_RESET();
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/pwmout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/pwmout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -187,7 +187,7 @@
channel = TIM_CHANNEL_2;
complementary_channel = 1;
break;
-
+
// Channels 3
case PA_10:
case PC_2:
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -94,7 +94,7 @@
// Disable the reception overrun detection
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
UartHandle.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
-
+
HAL_UART_Init(&UartHandle);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F302R8/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -42,7 +42,7 @@
TimMasterHandle.Instance = TIM_MST;
- HAL_InitTick(0); // The passed value is not used
+ HAL_InitTick(0); // The passed value is not used
}
uint32_t us_ticker_read()
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -59,7 +59,8 @@
int i2c1_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -68,7 +69,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C1 clock and pinout if not done
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
__HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
__I2C1_CLK_ENABLE();
@@ -97,7 +98,7 @@
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
@@ -320,10 +321,10 @@
void i2c_reset(i2c_t *obj)
{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
__I2C1_FORCE_RESET();
__I2C1_RELEASE_RESET();
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -94,7 +94,7 @@
// Disable the reception overrun detection
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
UartHandle.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
-
+
HAL_UART_Init(&UartHandle);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -42,7 +42,7 @@
TimMasterHandle.Instance = TIM_MST;
- HAL_InitTick(0); // The passed value is not used
+ HAL_InitTick(0); // The passed value is not used
}
uint32_t us_ticker_read()
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/analogin_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/analogin_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -58,7 +58,8 @@
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
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);
@@ -94,7 +95,8 @@
}
}
-static inline uint16_t adc_read(analogin_t *obj) {
+static inline uint16_t adc_read(analogin_t *obj)
+{
ADC_ChannelConfTypeDef sConfig;
AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
@@ -169,14 +171,16 @@
}
}
-uint16_t analogin_read_u16(analogin_t *obj) {
+uint16_t analogin_read_u16(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
// 12-bit to 16-bit conversion
value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F);
return value;
}
-float analogin_read(analogin_t *obj) {
+float analogin_read(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -34,14 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-uint32_t gpio_set(PinName pin) {
+uint32_t gpio_set(PinName pin)
+{
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
-void gpio_init(gpio_t *obj, PinName pin) {
+void gpio_init(gpio_t *obj, PinName pin)
+{
obj->pin = pin;
if (pin == (PinName)NC)
return;
@@ -59,11 +61,13 @@
obj->reg_clr = &gpio->BSRRH;
}
-void gpio_mode(gpio_t *obj, PinMode mode) {
+void gpio_mode(gpio_t *obj, PinMode mode)
+{
pin_mode(obj->pin, 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) {
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_irq_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_irq_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -46,7 +46,8 @@
static gpio_irq_handler irq_handler;
-static void handle_interrupt_in(uint32_t irq_index) {
+static void handle_interrupt_in(uint32_t irq_index)
+{
// Retrieve the gpio and pin that generate the irq
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
@@ -68,37 +69,45 @@
// The irq_index is passed to the function
// EXTI line 0
-static void gpio_irq0(void) {
+static void gpio_irq0(void)
+{
handle_interrupt_in(0);
}
// EXTI line 1
-static void gpio_irq1(void) {
+static void gpio_irq1(void)
+{
handle_interrupt_in(1);
}
// EXTI line 2
-static void gpio_irq2(void) {
+static void gpio_irq2(void)
+{
handle_interrupt_in(2);
}
// EXTI line 3
-static void gpio_irq3(void) {
+static void gpio_irq3(void)
+{
handle_interrupt_in(3);
}
// EXTI line 4
-static void gpio_irq4(void) {
+static void gpio_irq4(void)
+{
handle_interrupt_in(4);
}
// EXTI lines 5 to 9
-static void gpio_irq5(void) {
+static void gpio_irq5(void)
+{
handle_interrupt_in(5);
}
// EXTI lines 10 to 15
-static void gpio_irq6(void) {
+static void gpio_irq6(void)
+{
handle_interrupt_in(6);
}
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
uint32_t irq_index;
@@ -183,7 +192,8 @@
return 0;
}
-void gpio_irq_free(gpio_irq_t *obj) {
+void gpio_irq_free(gpio_irq_t *obj)
+{
channel_ids[obj->irq_index] = 0;
channel_gpio[obj->irq_index] = 0;
channel_pin[obj->irq_index] = 0;
@@ -192,7 +202,8 @@
obj->event = EDGE_NONE;
}
-void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) {
+void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
+{
uint32_t mode = STM_MODE_INPUT;
uint32_t pull = GPIO_NOPULL;
@@ -230,8 +241,7 @@
mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
- }
- else if (event == IRQ_FALL) {
+ } else if (event == IRQ_FALL) {
if ((obj->event == EDGE_RISE) || (obj->event == EDGE_BOTH)) {
mode = STM_MODE_IT_RISING;
obj->event = EDGE_RISE;
@@ -239,22 +249,23 @@
mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
- }
- else {
- mode = STM_MODE_IT_EVT_RESET;
+ } else {
+ mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
-
+
}
pin_function(obj->pin, STM_PIN_DATA(mode, pull, 0));
}
-void gpio_irq_enable(gpio_irq_t *obj) {
+void gpio_irq_enable(gpio_irq_t *obj)
+{
NVIC_EnableIRQ(obj->irq_n);
}
-void gpio_irq_disable(gpio_irq_t *obj) {
+void gpio_irq_disable(gpio_irq_t *obj)
+{
NVIC_DisableIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_object.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_object.h Fri Nov 14 09:00:07 2014 +0000
@@ -48,7 +48,8 @@
__IO uint16_t *reg_clr;
} 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) {
*obj->reg_set = obj->mask;
@@ -57,7 +58,8 @@
}
}
-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);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -64,7 +64,8 @@
int i2c2_inited = 0;
int i2c3_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -73,7 +74,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C1 clock and pinout if not done
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
__I2C1_CLK_ENABLE();
// Configure I2C pins
@@ -83,7 +84,7 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C2 clock and pinout if not done
- if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+ if ((obj->i2c == I2C_2) && !i2c2_inited) {
i2c2_inited = 1;
__I2C2_CLK_ENABLE();
// Configure I2C pins
@@ -93,7 +94,7 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C3 clock and pinout if not done
- if ((obj->i2c == I2C_3)&& !i2c3_inited) {
+ if ((obj->i2c == I2C_3) && !i2c3_inited) {
i2c3_inited = 1;
__I2C3_CLK_ENABLE();
// Configure I2C pins
@@ -113,14 +114,15 @@
obj->slave = 0;
}
-void i2c_frequency(i2c_t *obj, int hz) {
+void i2c_frequency(i2c_t *obj, int hz)
+{
MBED_ASSERT((hz != 0) && (hz <= 400000));
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
-
+
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// I2C configuration
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
@@ -139,7 +141,8 @@
}
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -162,7 +165,8 @@
return 0;
}
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
// Generate the STOP condition
@@ -171,7 +175,8 @@
return 0;
}
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -221,7 +226,8 @@
return length;
}
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -266,7 +272,8 @@
return count;
}
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -289,7 +296,8 @@
return (int)i2c->DR;
}
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -307,12 +315,13 @@
return 1;
}
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
if (obj->i2c == I2C_1) {
__I2C1_FORCE_RESET();
@@ -330,7 +339,8 @@
#if DEVICE_I2CSLAVE
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg = 0;
@@ -344,7 +354,8 @@
i2c->OAR1 = tmpreg;
}
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
if (enable_slave) {
obj->slave = 1;
@@ -359,7 +370,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
int retValue = NoData;
if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY) == 1) {
@@ -376,7 +388,8 @@
return (retValue);
}
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
uint32_t Timeout;
int size = 0;
@@ -430,7 +443,8 @@
return size;
}
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
uint32_t Timeout;
int size = 0;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/mbed_overrides.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/mbed_overrides.c Fri Nov 14 09:00:07 2014 +0000
@@ -28,7 +28,8 @@
#include "cmsis.h"
// This function is called after RAM initialization and before main.
-void mbed_sdk_init() {
+void mbed_sdk_init()
+{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
// Need to restart HAL driver after the RAM is initialized
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/pinmap.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/pinmap.c Fri Nov 14 09:00:07 2014 +0000
@@ -50,7 +50,8 @@
};
// Enable GPIO clock and return GPIO base address
-uint32_t Set_GPIO_Clock(uint32_t port_idx) {
+uint32_t Set_GPIO_Clock(uint32_t port_idx)
+{
uint32_t gpio_add = 0;
switch (port_idx) {
case PortA:
@@ -83,7 +84,8 @@
/**
* 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)
+{
MBED_ASSERT(pin != (PinName)NC);
// Get the pin informations
uint32_t mode = STM_PIN_MODE(data);
@@ -119,7 +121,8 @@
/**
* Configure pin pull-up/pull-down
*/
-void pin_mode(PinName pin, PinMode mode) {
+void pin_mode(PinName pin, PinMode mode)
+{
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_F401RE/port_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/port_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -38,11 +38,13 @@
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, ...)
// low nibble = pin number
-PinName port_pin(PortName port, int pin_n) {
+PinName port_pin(PortName port, int pin_n)
+{
return (PinName)(pin_n + (port << 4));
}
-void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
+void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
+{
uint32_t port_index = (uint32_t)port;
// Enable GPIO clock
@@ -59,7 +61,8 @@
port_dir(obj, dir);
}
-void port_dir(port_t *obj, PinDirection dir) {
+void port_dir(port_t *obj, PinDirection dir)
+{
uint32_t i;
obj->direction = dir;
for (i = 0; i < 16; i++) { // Process all pins
@@ -73,7 +76,8 @@
}
}
-void port_mode(port_t *obj, PinMode mode) {
+void port_mode(port_t *obj, PinMode mode)
+{
uint32_t i;
for (i = 0; i < 16; i++) { // Process all pins
if (obj->mask & (1 << i)) { // If the pin is used
@@ -82,11 +86,13 @@
}
}
-void port_write(port_t *obj, int value) {
+void port_write(port_t *obj, int value)
+{
*obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask);
}
-int port_read(port_t *obj) {
+int port_read(port_t *obj)
+{
if (obj->direction == PIN_OUTPUT) {
return (*obj->reg_out & obj->mask);
} else { // PIN_INPUT
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/pwmout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/pwmout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -85,7 +85,8 @@
static TIM_HandleTypeDef TimHandle;
-void pwmout_init(pwmout_t* obj, PinName pin) {
+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);
@@ -112,12 +113,14 @@
pwmout_period_us(obj, 20000); // 20 ms per default
}
-void pwmout_free(pwmout_t* obj) {
+void pwmout_free(pwmout_t* obj)
+{
// Configure GPIO
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void pwmout_write(pwmout_t* obj, float value) {
+void pwmout_write(pwmout_t* obj, float value)
+{
TIM_OC_InitTypeDef sConfig;
int channel = 0;
int complementary_channel = 0;
@@ -215,7 +218,8 @@
}
}
-float pwmout_read(pwmout_t* obj) {
+float pwmout_read(pwmout_t* obj)
+{
float value = 0;
if (obj->period > 0) {
value = (float)(obj->pulse) / (float)(obj->period);
@@ -223,15 +227,18 @@
return ((value > (float)1.0) ? (float)(1.0) : (value));
}
-void pwmout_period(pwmout_t* obj, float seconds) {
+void pwmout_period(pwmout_t* obj, float seconds)
+{
pwmout_period_us(obj, seconds * 1000000.0f);
}
-void pwmout_period_ms(pwmout_t* obj, int ms) {
+void pwmout_period_ms(pwmout_t* obj, int ms)
+{
pwmout_period_us(obj, ms * 1000);
}
-void pwmout_period_us(pwmout_t* obj, int us) {
+void pwmout_period_us(pwmout_t* obj, int us)
+{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
@@ -256,15 +263,18 @@
__HAL_TIM_ENABLE(&TimHandle);
}
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
+void pwmout_pulsewidth(pwmout_t* obj, float seconds)
+{
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
}
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
+void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
+{
pwmout_pulsewidth_us(obj, ms * 1000);
}
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
+void pwmout_pulsewidth_us(pwmout_t* obj, int us)
+{
float value = (float)us / (float)obj->period;
pwmout_write(obj, value);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/rtc_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/rtc_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -37,7 +37,8 @@
static RTC_HandleTypeDef RtcHandle;
-void rtc_init(void) {
+void rtc_init(void)
+{
RCC_OscInitTypeDef RCC_OscInitStruct;
uint32_t rtc_freq = 0;
@@ -96,7 +97,8 @@
}
}
-void rtc_free(void) {
+void rtc_free(void)
+{
// Enable Power clock
__PWR_CLK_ENABLE();
@@ -121,7 +123,8 @@
rtc_inited = 0;
}
-int rtc_isenabled(void) {
+int rtc_isenabled(void)
+{
return rtc_inited;
}
@@ -142,7 +145,8 @@
tm_yday days since January 1 0-365
tm_isdst Daylight Saving Time flag
*/
-time_t rtc_read(void) {
+time_t rtc_read(void)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
struct tm timeinfo;
@@ -169,7 +173,8 @@
return t;
}
-void rtc_write(time_t t) {
+void rtc_write(time_t t)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -65,7 +65,8 @@
int stdio_uart_inited = 0;
serial_t stdio_uart;
-static void init_uart(serial_t *obj) {
+static void init_uart(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
UartHandle.Init.BaudRate = obj->baudrate;
@@ -85,7 +86,8 @@
HAL_UART_Init(&UartHandle);
}
-void serial_init(serial_t *obj, PinName tx, PinName rx) {
+void serial_init(serial_t *obj, PinName tx, PinName rx)
+{
// Determine the UART to use (UART_1, UART_2, ...)
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
@@ -137,7 +139,8 @@
}
-void serial_free(serial_t *obj) {
+void serial_free(serial_t *obj)
+{
// Reset UART and disable clock
if (obj->uart == UART_1) {
__USART1_FORCE_RESET();
@@ -162,12 +165,14 @@
serial_irq_ids[obj->index] = 0;
}
-void serial_baud(serial_t *obj, int baudrate) {
+void serial_baud(serial_t *obj, int baudrate)
+{
obj->baudrate = baudrate;
init_uart(obj);
}
-void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
+void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
+{
if (data_bits == 9) {
obj->databits = UART_WORDLENGTH_9B;
} else {
@@ -201,7 +206,8 @@
* INTERRUPTS HANDLING
******************************************************************************/
-static void uart_irq(UARTName name, int id) {
+static void uart_irq(UARTName name, int id)
+{
UartHandle.Instance = (USART_TypeDef *)name;
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TC) != RESET) {
@@ -215,22 +221,27 @@
}
}
-static void uart1_irq(void) {
+static void uart1_irq(void)
+{
uart_irq(UART_1, 0);
}
-static void uart2_irq(void) {
+static void uart2_irq(void)
+{
uart_irq(UART_2, 1);
}
-static void uart6_irq(void) {
+static void uart6_irq(void)
+{
uart_irq(UART_6, 2);
}
-void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
+void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
+{
irq_handler = handler;
serial_irq_ids[obj->index] = id;
}
-void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
+void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
@@ -285,19 +296,22 @@
* READ/WRITE
******************************************************************************/
-int serial_getc(serial_t *obj) {
+int serial_getc(serial_t *obj)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_readable(obj));
return (int)(uart->DR & 0x1FF);
}
-void serial_putc(serial_t *obj, int c) {
+void serial_putc(serial_t *obj, int c)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_writable(obj));
uart->DR = (uint32_t)(c & 0x1FF);
}
-int serial_readable(serial_t *obj) {
+int serial_readable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is received
@@ -305,7 +319,8 @@
return status;
}
-int serial_writable(serial_t *obj) {
+int serial_writable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is transmitted
@@ -313,22 +328,26 @@
return status;
}
-void serial_clear(serial_t *obj) {
+void serial_clear(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
__HAL_UART_CLEAR_FLAG(&UartHandle, UART_FLAG_TXE);
__HAL_UART_CLEAR_FLAG(&UartHandle, UART_FLAG_RXNE);
}
-void serial_pinout_tx(PinName tx) {
+void serial_pinout_tx(PinName tx)
+{
pinmap_pinout(tx, PinMap_UART_TX);
}
-void serial_break_set(serial_t *obj) {
+void serial_break_set(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
HAL_LIN_SendBreak(&UartHandle);
}
-void serial_break_clear(serial_t *obj) {
+void serial_break_clear(serial_t *obj)
+{
}
#endif
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/sleep.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/sleep.c Fri Nov 14 09:00:07 2014 +0000
@@ -35,7 +35,8 @@
static TIM_HandleTypeDef TimMasterHandle;
-void sleep(void) {
+void sleep(void)
+{
TimMasterHandle.Instance = TIM5;
// Disable HAL tick interrupt
@@ -48,7 +49,8 @@
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
}
-void deepsleep(void) {
+void deepsleep(void)
+{
// Request to enter STOP mode with regulator in low power mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/spi_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/spi_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -78,7 +78,8 @@
static SPI_HandleTypeDef SpiHandle;
-static void init_spi(spi_t *obj) {
+static void init_spi(spi_t *obj)
+{
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
__HAL_SPI_DISABLE(&SpiHandle);
@@ -100,7 +101,8 @@
__HAL_SPI_ENABLE(&SpiHandle);
}
-void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
+void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
+{
// Determine the SPI to use
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
@@ -152,7 +154,8 @@
init_spi(obj);
}
-void spi_free(spi_t *obj) {
+void spi_free(spi_t *obj)
+{
// Reset SPI and disable clock
if (obj->spi == SPI_1) {
__SPI1_FORCE_RESET();
@@ -179,7 +182,8 @@
pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void spi_format(spi_t *obj, int bits, int mode, int slave) {
+void spi_format(spi_t *obj, int bits, int mode, int slave)
+{
// Save new values
if (bits == 16) {
obj->bits = SPI_DATASIZE_16BIT;
@@ -217,7 +221,8 @@
init_spi(obj);
}
-void spi_frequency(spi_t *obj, int hz) {
+void spi_frequency(spi_t *obj, int hz)
+{
// Note: The frequencies are obtained with SPI1 clock = 84 MHz (APB2 clock)
if (hz < 600000) {
obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 330 kHz
@@ -239,7 +244,8 @@
init_spi(obj);
}
-static inline int ssp_readable(spi_t *obj) {
+static inline int ssp_readable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is received
@@ -247,7 +253,8 @@
return status;
}
-static inline int ssp_writeable(spi_t *obj) {
+static inline int ssp_writeable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is transmitted
@@ -255,47 +262,55 @@
return status;
}
-static inline void ssp_write(spi_t *obj, int value) {
+static inline void ssp_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
spi->DR = (uint16_t)value;
}
-static inline int ssp_read(spi_t *obj) {
+static inline int ssp_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
return (int)spi->DR;
}
-static inline int ssp_busy(spi_t *obj) {
+static inline int ssp_busy(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
return status;
}
-int spi_master_write(spi_t *obj, int value) {
+int spi_master_write(spi_t *obj, int value)
+{
ssp_write(obj, value);
return ssp_read(obj);
}
-int spi_slave_receive(spi_t *obj) {
+int spi_slave_receive(spi_t *obj)
+{
return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);
};
-int spi_slave_read(spi_t *obj) {
+int spi_slave_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
return (int)spi->DR;
}
-void spi_slave_write(spi_t *obj, int value) {
+void spi_slave_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
spi->DR = (uint16_t)value;
}
-int spi_busy(spi_t *obj) {
+int spi_busy(spi_t *obj)
+{
return ssp_busy(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -34,31 +34,36 @@
static TIM_HandleTypeDef TimMasterHandle;
static int us_ticker_inited = 0;
-void us_ticker_init(void) {
+void us_ticker_init(void)
+{
if (us_ticker_inited) return;
us_ticker_inited = 1;
TimMasterHandle.Instance = TIM_MST;
- HAL_InitTick(0); // The passed value is not used
+ HAL_InitTick(0); // The passed value is not used
}
-uint32_t us_ticker_read() {
+uint32_t us_ticker_read()
+{
if (!us_ticker_inited) us_ticker_init();
return TIM_MST->CNT;
}
-void us_ticker_set_interrupt(timestamp_t timestamp) {
+void us_ticker_set_interrupt(timestamp_t timestamp)
+{
// Set new output compare value
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-void us_ticker_disable_interrupt(void) {
+void us_ticker_disable_interrupt(void)
+{
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-void us_ticker_clear_interrupt(void) {
+void us_ticker_clear_interrupt(void)
+{
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F411RE/gpio_irq_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F411RE/gpio_irq_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -241,8 +241,7 @@
mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
- }
- else if (event == IRQ_FALL) {
+ } else if (event == IRQ_FALL) {
if ((obj->event == EDGE_RISE) || (obj->event == EDGE_BOTH)) {
mode = STM_MODE_IT_RISING;
obj->event = EDGE_RISE;
@@ -250,9 +249,8 @@
mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
- }
- else {
- mode = STM_MODE_IT_EVT_RESET;
+ } else {
+ mode = STM_MODE_IT_EVT_RESET;
obj->event = EDGE_NONE;
}
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F411RE/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F411RE/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -66,7 +66,8 @@
int i2c2_inited = 0;
int i2c3_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -75,7 +76,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C1 clock and pinout if not done
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
__I2C1_CLK_ENABLE();
// Configure I2C pins
@@ -85,7 +86,7 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C2 clock and pinout if not done
- if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+ if ((obj->i2c == I2C_2) && !i2c2_inited) {
i2c2_inited = 1;
__I2C2_CLK_ENABLE();
// Configure I2C pins
@@ -95,7 +96,7 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C3 clock and pinout if not done
- if ((obj->i2c == I2C_3)&& !i2c3_inited) {
+ if ((obj->i2c == I2C_3) && !i2c3_inited) {
i2c3_inited = 1;
__I2C3_CLK_ENABLE();
// Configure I2C pins
@@ -115,14 +116,15 @@
obj->slave = 0;
}
-void i2c_frequency(i2c_t *obj, int hz) {
+void i2c_frequency(i2c_t *obj, int hz)
+{
MBED_ASSERT((hz != 0) && (hz <= 400000));
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
-
+
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// I2C configuration
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
@@ -141,7 +143,8 @@
}
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -164,7 +167,8 @@
return 0;
}
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
// Generate the STOP condition
@@ -173,7 +177,8 @@
return 0;
}
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -223,7 +228,8 @@
return length;
}
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -268,7 +274,8 @@
return count;
}
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -291,7 +298,8 @@
return (int)i2c->DR;
}
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -309,12 +317,13 @@
return 1;
}
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
if (obj->i2c == I2C_1) {
__I2C1_FORCE_RESET();
@@ -332,7 +341,8 @@
#if DEVICE_I2CSLAVE
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg = 0;
@@ -346,7 +356,8 @@
i2c->OAR1 = tmpreg;
}
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
if (enable_slave) {
obj->slave = 1;
@@ -361,7 +372,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
int retValue = NoData;
if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY) == 1) {
@@ -378,7 +390,8 @@
return (retValue);
}
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
uint32_t Timeout;
int size = 0;
@@ -432,7 +445,8 @@
return size;
}
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
uint32_t Timeout;
int size = 0;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/analogin_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/analogin_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -58,7 +58,8 @@
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
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);
@@ -96,15 +97,16 @@
AdcHandle.Init.LowPowerFrequencyMode = DISABLE; // To be enabled only if ADC clock < 2.8 MHz
AdcHandle.Init.LowPowerAutoOff = DISABLE;
HAL_ADC_Init(&AdcHandle);
-
+
// Calibration
HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED);
-
+
__HAL_ADC_ENABLE(&AdcHandle);
}
}
-static inline uint16_t adc_read(analogin_t *obj) {
+static inline uint16_t adc_read(analogin_t *obj)
+{
ADC_ChannelConfTypeDef sConfig;
AdcHandle.Instance = (ADC_TypeDef *)(obj->adc);
@@ -176,14 +178,16 @@
}
}
-uint16_t analogin_read_u16(analogin_t *obj) {
+uint16_t analogin_read_u16(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
// 12-bit to 16-bit conversion
value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F);
return value;
}
-float analogin_read(analogin_t *obj) {
+float analogin_read(analogin_t *obj)
+{
uint16_t value = adc_read(obj);
return (float)value * (1.0f / (float)0xFFF); // 12 bits range
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/analogout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/analogout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -43,7 +43,8 @@
static DAC_HandleTypeDef DacHandle;
-void analogout_init(dac_t *obj, PinName pin) {
+void analogout_init(dac_t *obj, PinName pin)
+{
DAC_ChannelConfTypeDef sConfig;
DacHandle.Instance = DAC;
@@ -70,7 +71,8 @@
analogout_write_u16(obj, 0);
}
-void analogout_free(dac_t *obj) {
+void analogout_free(dac_t *obj)
+{
// Reset DAC and disable clock
__DAC_FORCE_RESET();
__DAC_RELEASE_RESET();
@@ -80,16 +82,19 @@
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-static inline void dac_write(dac_t *obj, uint16_t value) {
+static inline void dac_write(dac_t *obj, uint16_t value)
+{
HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, value);
HAL_DAC_Start(&DacHandle, DAC_CHANNEL_1);
}
-static inline int dac_read(dac_t *obj) {
+static inline int dac_read(dac_t *obj)
+{
return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_1);
}
-void analogout_write(dac_t *obj, float value) {
+void analogout_write(dac_t *obj, float value)
+{
if (value < 0.0f) {
dac_write(obj, 0); // Min value
} else if (value > 1.0f) {
@@ -99,7 +104,8 @@
}
}
-void analogout_write_u16(dac_t *obj, uint16_t value) {
+void analogout_write_u16(dac_t *obj, uint16_t value)
+{
if (value > (uint16_t)DAC_RANGE) {
dac_write(obj, (uint16_t)DAC_RANGE); // Max value
} else {
@@ -107,12 +113,14 @@
}
}
-float analogout_read(dac_t *obj) {
+float analogout_read(dac_t *obj)
+{
uint32_t value = dac_read(obj);
return (float)((float)value * (1.0f / (float)DAC_RANGE));
}
-uint16_t analogout_read_u16(dac_t *obj) {
+uint16_t analogout_read_u16(dac_t *obj)
+{
return (uint16_t)dac_read(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/gpio_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/gpio_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -34,14 +34,16 @@
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-uint32_t gpio_set(PinName pin) {
+uint32_t gpio_set(PinName pin)
+{
MBED_ASSERT(pin != (PinName)NC);
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
-void gpio_init(gpio_t *obj, PinName pin) {
+void gpio_init(gpio_t *obj, PinName pin)
+{
obj->pin = pin;
if (pin == (PinName)NC)
return;
@@ -59,11 +61,13 @@
obj->reg_clr = &gpio->BRR;
}
-void gpio_mode(gpio_t *obj, PinMode mode) {
+void gpio_mode(gpio_t *obj, PinMode mode)
+{
pin_mode(obj->pin, 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) {
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/gpio_irq_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/gpio_irq_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -46,7 +46,8 @@
static gpio_irq_handler irq_handler;
-static void handle_interrupt_in(uint32_t irq_index) {
+static void handle_interrupt_in(uint32_t irq_index)
+{
// Retrieve the gpio and pin that generate the irq
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
@@ -68,21 +69,25 @@
// The irq_index is passed to the function
// EXTI lines 0 to 1
-static void gpio_irq0(void) {
+static void gpio_irq0(void)
+{
handle_interrupt_in(0);
}
// EXTI lines 2 to 3
-static void gpio_irq1(void) {
+static void gpio_irq1(void)
+{
handle_interrupt_in(1);
}
// EXTI lines 4 to 15
-static void gpio_irq2(void) {
+static void gpio_irq2(void)
+{
handle_interrupt_in(2);
}
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
-int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
+int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
uint32_t irq_index;
@@ -134,7 +139,8 @@
return 0;
}
-void gpio_irq_free(gpio_irq_t *obj) {
+void gpio_irq_free(gpio_irq_t *obj)
+{
channel_ids[obj->irq_index] = 0;
channel_gpio[obj->irq_index] = 0;
channel_pin[obj->irq_index] = 0;
@@ -191,11 +197,13 @@
pin_function(obj->pin, STM_PIN_DATA(mode, pull, 0));
}
-void gpio_irq_enable(gpio_irq_t *obj) {
+void gpio_irq_enable(gpio_irq_t *obj)
+{
NVIC_EnableIRQ(obj->irq_n);
}
-void gpio_irq_disable(gpio_irq_t *obj) {
+void gpio_irq_disable(gpio_irq_t *obj)
+{
NVIC_DisableIRQ(obj->irq_n);
obj->event = EDGE_NONE;
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/gpio_object.h Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/gpio_object.h Fri Nov 14 09:00:07 2014 +0000
@@ -48,7 +48,8 @@
__IO uint32_t *reg_clr;
} 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) {
*obj->reg_set = obj->mask;
@@ -57,7 +58,8 @@
}
}
-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);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/i2c_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/i2c_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -63,7 +63,8 @@
int i2c1_inited = 0;
int i2c2_inited = 0;
-void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
+void i2c_init(i2c_t *obj, PinName sda, PinName scl)
+{
// Determine the I2C to use
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
@@ -72,7 +73,7 @@
MBED_ASSERT(obj->i2c != (I2CName)NC);
// Enable I2C1 clock and pinout if not done
- if ((obj->i2c == I2C_1)&& !i2c1_inited) {
+ if ((obj->i2c == I2C_1) && !i2c1_inited) {
i2c1_inited = 1;
__HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
__I2C1_CLK_ENABLE();
@@ -83,7 +84,7 @@
pin_mode(scl, OpenDrain);
}
// Enable I2C2 clock and pinout if not done
- if ((obj->i2c == I2C_2)&& !i2c2_inited) {
+ if ((obj->i2c == I2C_2) && !i2c2_inited) {
i2c2_inited = 1;
__I2C2_CLK_ENABLE();
// Configure I2C pins
@@ -100,14 +101,15 @@
i2c_frequency(obj, 100000); // 100 kHz per default
}
-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);
int timeout;
// wait before init
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
// Common settings: I2C clock = 32 MHz, Analog filter = ON, Digital filter coefficient = 0
switch (hz) {
@@ -135,7 +137,8 @@
HAL_I2C_Init(&I2cHandle);
}
-inline int i2c_start(i2c_t *obj) {
+inline int i2c_start(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -158,7 +161,8 @@
return 0;
}
-inline int i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
// Generate the STOP condition
@@ -167,7 +171,8 @@
return 0;
}
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
+int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -213,7 +218,8 @@
return length;
}
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
+int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -256,7 +262,8 @@
return count;
}
-int i2c_byte_read(i2c_t *obj, int last) {
+int i2c_byte_read(i2c_t *obj, int last)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -271,7 +278,8 @@
return (int)i2c->RXDR;
}
-int i2c_byte_write(i2c_t *obj, int data) {
+int i2c_byte_write(i2c_t *obj, int data)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
@@ -288,12 +296,13 @@
return 1;
}
-void i2c_reset(i2c_t *obj) {
+void i2c_reset(i2c_t *obj)
+{
int timeout;
-
+
// wait before reset
timeout = LONG_TIMEOUT;
- while((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
+ while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
if (obj->i2c == I2C_1) {
__I2C1_FORCE_RESET();
@@ -307,7 +316,8 @@
#if DEVICE_I2CSLAVE
-void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
+void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg;
@@ -325,7 +335,8 @@
i2c->OAR1 |= I2C_OAR1_OA1EN;
}
-void i2c_slave_mode(i2c_t *obj, int enable_slave) {
+void i2c_slave_mode(i2c_t *obj, int enable_slave)
+{
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
uint16_t tmpreg;
@@ -351,7 +362,8 @@
#define WriteGeneral 2 // the master is writing to all slave
#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
-int i2c_slave_receive(i2c_t *obj) {
+int i2c_slave_receive(i2c_t *obj)
+{
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
int retValue = NoData;
@@ -368,7 +380,8 @@
return (retValue);
}
-int i2c_slave_read(i2c_t *obj, char *data, int length) {
+int i2c_slave_read(i2c_t *obj, char *data, int length)
+{
char size = 0;
while (size < length) data[size++] = (char)i2c_byte_read(obj, 0);
@@ -376,7 +389,8 @@
return size;
}
-int i2c_slave_write(i2c_t *obj, const char *data, int length) {
+int i2c_slave_write(i2c_t *obj, const char *data, int length)
+{
char size = 0;
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/mbed_overrides.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/mbed_overrides.c Fri Nov 14 09:00:07 2014 +0000
@@ -28,7 +28,8 @@
#include "cmsis.h"
// This function is called after RAM initialization and before main.
-void mbed_sdk_init() {
+void mbed_sdk_init()
+{
// Update the SystemCoreClock variable.
SystemCoreClockUpdate();
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/pinmap.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/pinmap.c Fri Nov 14 09:00:07 2014 +0000
@@ -50,7 +50,8 @@
};
// Enable GPIO clock and return GPIO base address
-uint32_t Set_GPIO_Clock(uint32_t port_idx) {
+uint32_t Set_GPIO_Clock(uint32_t port_idx)
+{
uint32_t gpio_add = 0;
switch (port_idx) {
case PortA:
@@ -83,7 +84,8 @@
/**
* 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)
+{
MBED_ASSERT(pin != (PinName)NC);
// Get the pin informations
uint32_t mode = STM_PIN_MODE(data);
@@ -119,7 +121,8 @@
/**
* Configure pin pull-up/pull-down
*/
-void pin_mode(PinName pin, PinMode mode) {
+void pin_mode(PinName pin, PinMode mode)
+{
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_L053R8/port_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/port_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -38,11 +38,13 @@
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, ...)
// low nibble = pin number
-PinName port_pin(PortName port, int pin_n) {
+PinName port_pin(PortName port, int pin_n)
+{
return (PinName)(pin_n + (port << 4));
}
-void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
+void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
+{
uint32_t port_index = (uint32_t)port;
// Enable GPIO clock
@@ -59,7 +61,8 @@
port_dir(obj, dir);
}
-void port_dir(port_t *obj, PinDirection dir) {
+void port_dir(port_t *obj, PinDirection dir)
+{
uint32_t i;
obj->direction = dir;
for (i = 0; i < 16; i++) { // Process all pins
@@ -73,7 +76,8 @@
}
}
-void port_mode(port_t *obj, PinMode mode) {
+void port_mode(port_t *obj, PinMode mode)
+{
uint32_t i;
for (i = 0; i < 16; i++) { // Process all pins
if (obj->mask & (1 << i)) { // If the pin is used
@@ -82,11 +86,13 @@
}
}
-void port_write(port_t *obj, int value) {
+void port_write(port_t *obj, int value)
+{
*obj->reg_out = (*obj->reg_out & ~obj->mask) | (value & obj->mask);
}
-int port_read(port_t *obj) {
+int port_read(port_t *obj)
+{
if (obj->direction == PIN_OUTPUT) {
return (*obj->reg_out & obj->mask);
} else { // PIN_INPUT
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/pwmout_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/pwmout_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -61,7 +61,8 @@
static TIM_HandleTypeDef TimHandle;
-void pwmout_init(pwmout_t* obj, PinName pin) {
+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);
@@ -84,12 +85,14 @@
pwmout_period_us(obj, 20000); // 20 ms per default
}
-void pwmout_free(pwmout_t* obj) {
+void pwmout_free(pwmout_t* obj)
+{
// Configure GPIO
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void pwmout_write(pwmout_t* obj, float value) {
+void pwmout_write(pwmout_t* obj, float value)
+{
TIM_OC_InitTypeDef sConfig;
int channel = 0;
@@ -149,7 +152,8 @@
HAL_TIM_PWM_Start(&TimHandle, channel);
}
-float pwmout_read(pwmout_t* obj) {
+float pwmout_read(pwmout_t* obj)
+{
float value = 0;
if (obj->period > 0) {
value = (float)(obj->pulse) / (float)(obj->period);
@@ -157,15 +161,18 @@
return ((value > (float)1.0) ? (float)(1.0) : (value));
}
-void pwmout_period(pwmout_t* obj, float seconds) {
+void pwmout_period(pwmout_t* obj, float seconds)
+{
pwmout_period_us(obj, seconds * 1000000.0f);
}
-void pwmout_period_ms(pwmout_t* obj, int ms) {
+void pwmout_period_ms(pwmout_t* obj, int ms)
+{
pwmout_period_us(obj, ms * 1000);
}
-void pwmout_period_us(pwmout_t* obj, int us) {
+void pwmout_period_us(pwmout_t* obj, int us)
+{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
@@ -187,15 +194,18 @@
__HAL_TIM_ENABLE(&TimHandle);
}
-void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
+void pwmout_pulsewidth(pwmout_t* obj, float seconds)
+{
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
}
-void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
+void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
+{
pwmout_pulsewidth_us(obj, ms * 1000);
}
-void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
+void pwmout_pulsewidth_us(pwmout_t* obj, int us)
+{
float value = (float)us / (float)obj->period;
pwmout_write(obj, value);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/rtc_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/rtc_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -37,7 +37,8 @@
static RTC_HandleTypeDef RtcHandle;
-void rtc_init(void) {
+void rtc_init(void)
+{
RCC_OscInitTypeDef RCC_OscInitStruct;
uint32_t rtc_freq = 0;
@@ -96,7 +97,8 @@
}
}
-void rtc_free(void) {
+void rtc_free(void)
+{
// Enable Power clock
__PWR_CLK_ENABLE();
@@ -121,7 +123,8 @@
rtc_inited = 0;
}
-int rtc_isenabled(void) {
+int rtc_isenabled(void)
+{
return rtc_inited;
}
@@ -142,7 +145,8 @@
tm_yday days since January 1 0-365
tm_isdst Daylight Saving Time flag
*/
-time_t rtc_read(void) {
+time_t rtc_read(void)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
struct tm timeinfo;
@@ -169,7 +173,8 @@
return t;
}
-void rtc_write(time_t t) {
+void rtc_write(time_t t)
+{
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/serial_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/serial_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -69,7 +69,8 @@
int stdio_uart_inited = 0;
serial_t stdio_uart;
-static void init_uart(serial_t *obj) {
+static void init_uart(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// [TODO] Workaround to be removed after HAL driver is corrected
@@ -94,11 +95,12 @@
// Disable the reception overrun detection
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
UartHandle.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
-
+
HAL_UART_Init(&UartHandle);
}
-void serial_init(serial_t *obj, PinName tx, PinName rx) {
+void serial_init(serial_t *obj, PinName tx, PinName rx)
+{
// Determine the UART to use (UART_1, UART_2, ...)
UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
@@ -150,7 +152,8 @@
}
}
-void serial_free(serial_t *obj) {
+void serial_free(serial_t *obj)
+{
// Reset UART and disable clock
if (obj->uart == UART_1) {
__USART1_FORCE_RESET();
@@ -177,12 +180,14 @@
serial_irq_ids[obj->index] = 0;
}
-void serial_baud(serial_t *obj, int baudrate) {
+void serial_baud(serial_t *obj, int baudrate)
+{
obj->baudrate = baudrate;
init_uart(obj);
}
-void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
+void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
+{
if (data_bits == 9) {
obj->databits = UART_WORDLENGTH_9B;
} else {
@@ -216,7 +221,8 @@
* INTERRUPTS HANDLING
******************************************************************************/
-static void uart_irq(UARTName name, int id) {
+static void uart_irq(UARTName name, int id)
+{
UartHandle.Instance = (USART_TypeDef *)name;
if (serial_irq_ids[id] != 0) {
if (__HAL_UART_GET_FLAG(&UartHandle, UART_FLAG_TC) != RESET) {
@@ -230,24 +236,29 @@
}
}
-static void uart1_irq(void) {
+static void uart1_irq(void)
+{
uart_irq(UART_1, 0);
}
-static void uart2_irq(void) {
+static void uart2_irq(void)
+{
uart_irq(UART_2, 1);
}
-static void lpuart1_irq(void) {
+static void lpuart1_irq(void)
+{
uart_irq(LPUART_1, 2);
}
-void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
+void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
+{
irq_handler = handler;
serial_irq_ids[obj->index] = id;
}
-void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
+void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
+{
IRQn_Type irq_n = (IRQn_Type)0;
uint32_t vector = 0;
@@ -302,19 +313,22 @@
* READ/WRITE
******************************************************************************/
-int serial_getc(serial_t *obj) {
+int serial_getc(serial_t *obj)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_readable(obj));
return (int)(uart->RDR & (uint32_t)0xFF);
}
-void serial_putc(serial_t *obj, int c) {
+void serial_putc(serial_t *obj, int c)
+{
USART_TypeDef *uart = (USART_TypeDef *)(obj->uart);
while (!serial_writable(obj));
uart->TDR = (uint32_t)(c & (uint32_t)0xFF);
}
-int serial_readable(serial_t *obj) {
+int serial_readable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is received
@@ -322,7 +336,8 @@
return status;
}
-int serial_writable(serial_t *obj) {
+int serial_writable(serial_t *obj)
+{
int status;
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
// Check if data is transmitted
@@ -330,22 +345,26 @@
return status;
}
-void serial_clear(serial_t *obj) {
+void serial_clear(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
__HAL_UART_CLEAR_IT(&UartHandle, UART_CLEAR_TCF);
__HAL_UART_SEND_REQ(&UartHandle, UART_RXDATA_FLUSH_REQUEST);
}
-void serial_pinout_tx(PinName tx) {
+void serial_pinout_tx(PinName tx)
+{
pinmap_pinout(tx, PinMap_UART_TX);
}
-void serial_break_set(serial_t *obj) {
+void serial_break_set(serial_t *obj)
+{
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
__HAL_UART_SEND_REQ(&UartHandle, UART_SENDBREAK_REQUEST);
}
-void serial_break_clear(serial_t *obj) {
+void serial_break_clear(serial_t *obj)
+{
}
#endif
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/sleep.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/sleep.c Fri Nov 14 09:00:07 2014 +0000
@@ -35,7 +35,8 @@
static TIM_HandleTypeDef TimMasterHandle;
-void sleep(void) {
+void sleep(void)
+{
// Disable us_ticker update interrupt
TimMasterHandle.Instance = TIM21;
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_UPDATE);
@@ -47,7 +48,8 @@
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE);
}
-void deepsleep(void) {
+void deepsleep(void)
+{
// Disable us_ticker update interrupt
TimMasterHandle.Instance = TIM21;
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_UPDATE);
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/spi_api.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/spi_api.c Fri Nov 14 09:00:07 2014 +0000
@@ -72,7 +72,8 @@
static SPI_HandleTypeDef SpiHandle;
-static void init_spi(spi_t *obj) {
+static void init_spi(spi_t *obj)
+{
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
__HAL_SPI_DISABLE(&SpiHandle);
@@ -94,7 +95,8 @@
__HAL_SPI_ENABLE(&SpiHandle);
}
-void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
+void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
+{
// Determine the SPI to use
SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
@@ -143,7 +145,8 @@
init_spi(obj);
}
-void spi_free(spi_t *obj) {
+void spi_free(spi_t *obj)
+{
// Reset SPI and disable clock
if (obj->spi == SPI_1) {
__SPI1_FORCE_RESET();
@@ -164,7 +167,8 @@
pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
-void spi_format(spi_t *obj, int bits, int mode, int slave) {
+void spi_format(spi_t *obj, int bits, int mode, int slave)
+{
// Save new values
if (bits == 16) {
obj->bits = SPI_DATASIZE_16BIT;
@@ -202,7 +206,8 @@
init_spi(obj);
}
-void spi_frequency(spi_t *obj, int hz) {
+void spi_frequency(spi_t *obj, int hz)
+{
// Note: The frequencies are obtained with SPI1 clock = 32 MHz (APB2 clock)
if (hz < 250000) {
obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 125 kHz
@@ -224,7 +229,8 @@
init_spi(obj);
}
-static inline int ssp_readable(spi_t *obj) {
+static inline int ssp_readable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is received
@@ -232,7 +238,8 @@
return status;
}
-static inline int ssp_writeable(spi_t *obj) {
+static inline int ssp_writeable(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
// Check if data is transmitted
@@ -240,47 +247,55 @@
return status;
}
-static inline void ssp_write(spi_t *obj, int value) {
+static inline void ssp_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
spi->DR = (uint16_t)value;
}
-static inline int ssp_read(spi_t *obj) {
+static inline int ssp_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
return (int)spi->DR;
}
-static inline int ssp_busy(spi_t *obj) {
+static inline int ssp_busy(spi_t *obj)
+{
int status;
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
return status;
}
-int spi_master_write(spi_t *obj, int value) {
+int spi_master_write(spi_t *obj, int value)
+{
ssp_write(obj, value);
return ssp_read(obj);
}
-int spi_slave_receive(spi_t *obj) {
+int spi_slave_receive(spi_t *obj)
+{
return (ssp_readable(obj) ? 1 : 0);
};
-int spi_slave_read(spi_t *obj) {
+int spi_slave_read(spi_t *obj)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_readable(obj));
return (int)spi->DR;
}
-void spi_slave_write(spi_t *obj, int value) {
+void spi_slave_write(spi_t *obj, int value)
+{
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
while (!ssp_writeable(obj));
spi->DR = (uint16_t)value;
}
-int spi_busy(spi_t *obj) {
+int spi_busy(spi_t *obj)
+{
return ssp_busy(obj);
}
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/us_ticker.c Fri Nov 14 08:45:06 2014 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L053R8/us_ticker.c Fri Nov 14 09:00:07 2014 +0000
@@ -41,14 +41,16 @@
static volatile uint32_t oc_int_part = 0;
static volatile uint16_t oc_rem_part = 0;
-void set_compare(uint16_t count) {
+void set_compare(uint16_t count)
+{
// Set new output compare value
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-static void tim_irq_handler(void) {
+static void tim_irq_handler(void)
+{
uint16_t cval = TIM_MST->CNT;
// Clear Update interrupt flag
@@ -75,7 +77,8 @@
}
}
-void us_ticker_init(void) {
+void us_ticker_init(void)
+{
if (us_ticker_inited) return;
us_ticker_inited = 1;
@@ -102,7 +105,8 @@
HAL_TIM_Base_Start(&TimMasterHandle);
}
-uint32_t us_ticker_read() {
+uint32_t us_ticker_read()
+{
uint32_t counter, counter2;
if (!us_ticker_inited) us_ticker_init();
// A situation might appear when Master overflows right after Slave is read and before the
@@ -123,7 +127,8 @@
return counter2;
}
-void us_ticker_set_interrupt(timestamp_t timestamp) {
+void us_ticker_set_interrupt(timestamp_t timestamp)
+{
int delta = (int)((uint32_t)timestamp - us_ticker_read());
uint16_t cval = TIM_MST->CNT;
@@ -142,10 +147,12 @@
}
}
-void us_ticker_disable_interrupt(void) {
+void us_ticker_disable_interrupt(void)
+{
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
-void us_ticker_clear_interrupt(void) {
+void us_ticker_clear_interrupt(void)
+{
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
}
