[NUCLEO_L432KC] Update HAL API

pull/1971/head
svastm 2016-06-06 14:59:47 +02:00
parent 2198dccd6e
commit b91c65ee2d
6 changed files with 73 additions and 11 deletions

View File

@ -48,7 +48,9 @@ I2C_HandleTypeDef I2cHandle;
void i2c_init(i2c_t *obj, PinName sda, PinName scl) void i2c_init(i2c_t *obj, PinName sda, PinName scl)
{ {
static int i2c1_inited = 0; static int i2c1_inited = 0;
#if defined(I2C2_BASE)
static int i2c2_inited = 0; static int i2c2_inited = 0;
#endif
#if defined(I2C3_BASE) #if defined(I2C3_BASE)
static int i2c3_inited = 0; static int i2c3_inited = 0;
#endif #endif
@ -72,6 +74,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
pin_mode(scl, OpenDrain); pin_mode(scl, OpenDrain);
} }
#if defined(I2C2_BASE)
// Enable I2C2 clock and pinout if not done // 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_inited = 1;
@ -82,6 +85,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
pin_mode(sda, OpenDrain); pin_mode(sda, OpenDrain);
pin_mode(scl, OpenDrain); pin_mode(scl, OpenDrain);
} }
#endif
#if defined(I2C3_BASE) #if defined(I2C3_BASE)
// Enable I2C3 clock and pinout if not done // Enable I2C3 clock and pinout if not done
@ -321,10 +325,12 @@ void i2c_reset(i2c_t *obj)
__HAL_RCC_I2C1_FORCE_RESET(); __HAL_RCC_I2C1_FORCE_RESET();
__HAL_RCC_I2C1_RELEASE_RESET(); __HAL_RCC_I2C1_RELEASE_RESET();
} }
#if defined(I2C2_BASE)
if (obj->i2c == I2C_2) { if (obj->i2c == I2C_2) {
__HAL_RCC_I2C2_FORCE_RESET(); __HAL_RCC_I2C2_FORCE_RESET();
__HAL_RCC_I2C2_RELEASE_RESET(); __HAL_RCC_I2C2_RELEASE_RESET();
} }
#endif
} }
#if DEVICE_I2CSLAVE #if DEVICE_I2CSLAVE

View File

@ -68,14 +68,18 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx)
gpio_add = GPIOC_BASE; gpio_add = GPIOC_BASE;
__HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE();
break; break;
#if defined(GPIOD_BASE)
case PortD: case PortD:
gpio_add = GPIOD_BASE; gpio_add = GPIOD_BASE;
__HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE();
break; break;
#endif
#if defined(GPIOE_BASE)
case PortE: case PortE:
gpio_add = GPIOE_BASE; gpio_add = GPIOE_BASE;
__HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE();
break; break;
#endif
case PortH: case PortH:
gpio_add = GPIOH_BASE; gpio_add = GPIOH_BASE;
__HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE();

View File

@ -53,13 +53,23 @@ void pwmout_init(pwmout_t* obj, PinName pin)
// Enable TIM clock // Enable TIM clock
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE(); if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE();
if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE(); if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE();
#if defined(TIM3_BASE)
if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE(); if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE();
#endif
#if defined(TIM4_BASE)
if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE(); if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE();
#endif
#if defined(TIM5_BASE)
if (obj->pwm == PWM_5) __HAL_RCC_TIM5_CLK_ENABLE(); if (obj->pwm == PWM_5) __HAL_RCC_TIM5_CLK_ENABLE();
#endif
#if defined(TIM8_BASE)
if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE(); if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE();
#endif
if (obj->pwm == PWM_15) __HAL_RCC_TIM15_CLK_ENABLE(); if (obj->pwm == PWM_15) __HAL_RCC_TIM15_CLK_ENABLE();
if (obj->pwm == PWM_16) __HAL_RCC_TIM16_CLK_ENABLE(); if (obj->pwm == PWM_16) __HAL_RCC_TIM16_CLK_ENABLE();
#if defined(TIM17_BASE)
if (obj->pwm == PWM_17) __HAL_RCC_TIM17_CLK_ENABLE(); if (obj->pwm == PWM_17) __HAL_RCC_TIM17_CLK_ENABLE();
#endif
// Configure GPIO // Configure GPIO
pinmap_pinout(pin, PinMap_PWM); pinmap_pinout(pin, PinMap_PWM);

View File

@ -114,27 +114,34 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->index = 1; obj->index = 1;
} }
#if defined(USART3_BASE)
if (obj->uart == UART_3) { if (obj->uart == UART_3) {
__HAL_RCC_USART3_FORCE_RESET(); __HAL_RCC_USART3_FORCE_RESET();
__HAL_RCC_USART3_RELEASE_RESET(); __HAL_RCC_USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_ENABLE(); __HAL_RCC_USART3_CLK_ENABLE();
obj->index = 2; obj->index = 2;
} }
#endif
#if defined(UART4_BASE)
if (obj->uart == UART_4) { if (obj->uart == UART_4) {
__HAL_RCC_UART4_FORCE_RESET(); __HAL_RCC_UART4_FORCE_RESET();
__HAL_RCC_UART4_RELEASE_RESET(); __HAL_RCC_UART4_RELEASE_RESET();
__HAL_RCC_UART4_CLK_ENABLE(); __HAL_RCC_UART4_CLK_ENABLE();
obj->index = 3; obj->index = 3;
} }
#endif
#if defined(UART5_BASE)
if (obj->uart == UART_5) { if (obj->uart == UART_5) {
__HAL_RCC_UART5_FORCE_RESET(); __HAL_RCC_UART5_FORCE_RESET();
__HAL_RCC_UART5_RELEASE_RESET(); __HAL_RCC_UART5_RELEASE_RESET();
__HAL_RCC_UART5_CLK_ENABLE(); __HAL_RCC_UART5_CLK_ENABLE();
obj->index = 4; obj->index = 4;
} }
#endif
#if defined(LPUART1_BASE)
if (obj->uart == LPUART_1) { if (obj->uart == LPUART_1) {
__HAL_RCC_LPUART1_FORCE_RESET(); __HAL_RCC_LPUART1_FORCE_RESET();
__HAL_RCC_LPUART1_RELEASE_RESET(); __HAL_RCC_LPUART1_RELEASE_RESET();
@ -142,6 +149,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
obj->baudrate = 38400; // Maximum peripheral clock is 4096 x BR -> This is the minimum BR with 80 MHz peripheral clock. obj->baudrate = 38400; // Maximum peripheral clock is 4096 x BR -> This is the minimum BR with 80 MHz peripheral clock.
obj->index = 5; obj->index = 5;
} }
#endif
// Configure the UART pins // Configure the UART pins
pinmap_pinout(tx, PinMap_UART_TX); pinmap_pinout(tx, PinMap_UART_TX);
@ -184,29 +192,37 @@ void serial_free(serial_t *obj)
__HAL_RCC_USART2_CLK_DISABLE(); __HAL_RCC_USART2_CLK_DISABLE();
} }
#if defined(USART3_BASE)
if (obj->uart == UART_3) { if (obj->uart == UART_3) {
__HAL_RCC_USART3_FORCE_RESET(); __HAL_RCC_USART3_FORCE_RESET();
__HAL_RCC_USART3_RELEASE_RESET(); __HAL_RCC_USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_DISABLE(); __HAL_RCC_USART3_CLK_DISABLE();
} }
#endif
#if defined(UART4_BASE)
if (obj->uart == UART_4) { if (obj->uart == UART_4) {
__HAL_RCC_UART4_FORCE_RESET(); __HAL_RCC_UART4_FORCE_RESET();
__HAL_RCC_UART4_RELEASE_RESET(); __HAL_RCC_UART4_RELEASE_RESET();
__HAL_RCC_UART4_CLK_DISABLE(); __HAL_RCC_UART4_CLK_DISABLE();
} }
#endif
#if defined(UART5_BASE)
if (obj->uart == UART_5) { if (obj->uart == UART_5) {
__HAL_RCC_UART5_FORCE_RESET(); __HAL_RCC_UART5_FORCE_RESET();
__HAL_RCC_UART5_RELEASE_RESET(); __HAL_RCC_UART5_RELEASE_RESET();
__HAL_RCC_UART5_CLK_DISABLE(); __HAL_RCC_UART5_CLK_DISABLE();
} }
#endif
#if defined(LPUART1_BASE)
if (obj->uart == LPUART_1) { if (obj->uart == LPUART_1) {
__HAL_RCC_LPUART1_FORCE_RESET(); __HAL_RCC_LPUART1_FORCE_RESET();
__HAL_RCC_LPUART1_RELEASE_RESET(); __HAL_RCC_LPUART1_RELEASE_RESET();
__HAL_RCC_LPUART1_CLK_DISABLE(); __HAL_RCC_LPUART1_CLK_DISABLE();
} }
#endif
// Configure GPIOs // Configure GPIOs
pin_function(obj->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); pin_function(obj->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@ -341,25 +357,33 @@ static void uart2_irq(void)
uart_irq(UART_2, 1); uart_irq(UART_2, 1);
} }
#if defined(USART3_BASE)
static void uart3_irq(void) static void uart3_irq(void)
{ {
uart_irq(UART_3, 2); uart_irq(UART_3, 2);
} }
#endif
#if defined(UART4_BASE)
static void uart4_irq(void) static void uart4_irq(void)
{ {
uart_irq(UART_4, 3); uart_irq(UART_4, 3);
} }
#endif
#if defined(UART5_BASE)
static void uart5_irq(void) static void uart5_irq(void)
{ {
uart_irq(UART_5, 4); uart_irq(UART_5, 4);
} }
#endif
#if defined(LPUART1_BASE)
static void lpuart1_irq(void) static void lpuart1_irq(void)
{ {
uart_irq(LPUART_1, 5); uart_irq(LPUART_1, 5);
} }
#endif
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)
{ {
@ -384,25 +408,33 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
vector = (uint32_t)&uart2_irq; vector = (uint32_t)&uart2_irq;
} }
#if defined(USART3_BASE)
if (obj->uart == UART_3) { if (obj->uart == UART_3) {
irq_n = USART3_IRQn; irq_n = USART3_IRQn;
vector = (uint32_t)&uart3_irq; vector = (uint32_t)&uart3_irq;
} }
#endif
#if defined(UART4_BASE)
if (obj->uart == UART_4) { if (obj->uart == UART_4) {
irq_n = UART4_IRQn; irq_n = UART4_IRQn;
vector = (uint32_t)&uart4_irq; vector = (uint32_t)&uart4_irq;
} }
#endif
#if defined(UART5_BASE)
if (obj->uart == UART_5) { if (obj->uart == UART_5) {
irq_n = UART5_IRQn; irq_n = UART5_IRQn;
vector = (uint32_t)&uart5_irq; vector = (uint32_t)&uart5_irq;
} }
#endif
#if defined(LPUART1_BASE)
if (obj->uart == LPUART_1) { if (obj->uart == LPUART_1) {
irq_n = LPUART1_IRQn; irq_n = LPUART1_IRQn;
vector = (uint32_t)&lpuart1_irq; vector = (uint32_t)&lpuart1_irq;
} }
#endif
if (enable) { if (enable) {

View File

@ -85,9 +85,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
if (obj->spi == SPI_1) { if (obj->spi == SPI_1) {
__HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_SPI1_CLK_ENABLE();
} }
#if defined(SPI2_BASE)
if (obj->spi == SPI_2) { if (obj->spi == SPI_2) {
__HAL_RCC_SPI2_CLK_ENABLE(); __HAL_RCC_SPI2_CLK_ENABLE();
} }
#endif
if (obj->spi == SPI_3) { if (obj->spi == SPI_3) {
__HAL_RCC_SPI3_CLK_ENABLE(); __HAL_RCC_SPI3_CLK_ENABLE();
} }
@ -129,11 +131,13 @@ void spi_free(spi_t *obj)
__HAL_RCC_SPI1_CLK_DISABLE(); __HAL_RCC_SPI1_CLK_DISABLE();
} }
#if defined(SPI2_BASE)
if (obj->spi == SPI_2) { if (obj->spi == SPI_2) {
__HAL_RCC_SPI2_FORCE_RESET(); __HAL_RCC_SPI2_FORCE_RESET();
__HAL_RCC_SPI2_RELEASE_RESET(); __HAL_RCC_SPI2_RELEASE_RESET();
__HAL_RCC_SPI2_CLK_DISABLE(); __HAL_RCC_SPI2_CLK_DISABLE();
} }
#endif
if (obj->spi == SPI_3) { if (obj->spi == SPI_3) {
__HAL_RCC_SPI3_FORCE_RESET(); __HAL_RCC_SPI3_FORCE_RESET();
@ -204,16 +208,18 @@ void spi_frequency(spi_t *obj, int hz)
/* Get source clock depending on SPI instance */ /* Get source clock depending on SPI instance */
switch ((int)obj->spi) { switch ((int)obj->spi) {
case SPI_1: case SPI_1:
/* SPI_1. Source CLK is PCKL2 */ /* SPI_1. Source CLK is PCKL2 */
spi_hz = HAL_RCC_GetPCLK2Freq(); spi_hz = HAL_RCC_GetPCLK2Freq();
break; break;
case SPI_2: #if defined(SPI2_BASE)
case SPI_3: case SPI_2:
/* SPI_2, SPI_3. Source CLK is PCKL1 */ #endif
spi_hz = HAL_RCC_GetPCLK1Freq(); case SPI_3:
break; /* SPI_2, SPI_3. Source CLK is PCKL1 */
default: spi_hz = HAL_RCC_GetPCLK1Freq();
error("SPI instance not set"); break;
default:
error("SPI instance not set");
} }
/* Define pre-scaler in order to get highest available frequency below requested frequency */ /* Define pre-scaler in order to get highest available frequency below requested frequency */

View File

@ -29,7 +29,11 @@
#include "us_ticker_api.h" #include "us_ticker_api.h"
#include "PeripheralNames.h" #include "PeripheralNames.h"
#define TIM_MST TIM5 #if defined(TIM5_BASE)
#define TIM_MST TIM5
#else
#define TIM_MST TIM2
#endif
static TIM_HandleTypeDef TimMasterHandle; static TIM_HandleTypeDef TimMasterHandle;
static int us_ticker_inited = 0; static int us_ticker_inited = 0;