mirror of https://github.com/ARMmbed/mbed-os.git
STM32F0 : update hal api files
parent
ae0891878a
commit
f7caf72009
|
@ -1,5 +1,5 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -34,6 +34,7 @@
|
|||
#include "cmsis.h"
|
||||
#include "pinmap.h"
|
||||
#include "PeripheralPins.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
ADC_HandleTypeDef AdcHandle;
|
||||
|
||||
|
@ -73,10 +74,13 @@ void analogin_init(analogin_t *obj, PinName pin)
|
|||
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
AdcHandle.Init.DMAContinuousRequests = DISABLE;
|
||||
AdcHandle.Init.Overrun = OVR_DATA_OVERWRITTEN;
|
||||
HAL_ADC_Init(&AdcHandle);
|
||||
|
||||
if (HAL_ADC_Init(&AdcHandle) != HAL_OK) {
|
||||
error("Cannot initialize ADC");
|
||||
}
|
||||
// Run the ADC calibration
|
||||
HAL_ADCEx_Calibration_Start(&AdcHandle);
|
||||
if (HAL_ADCEx_Calibration_Start(&AdcHandle) != HAL_OK) {
|
||||
error("Cannot Start ADC_Calibration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +129,7 @@ static inline uint16_t adc_read(analogin_t *obj)
|
|||
case PB_1:
|
||||
sConfig.Channel = ADC_CHANNEL_9;
|
||||
break;
|
||||
#if !defined (TARGET_STM32F031K6)
|
||||
case PC_0:
|
||||
sConfig.Channel = ADC_CHANNEL_10;
|
||||
break;
|
||||
|
@ -143,6 +148,7 @@ static inline uint16_t adc_read(analogin_t *obj)
|
|||
case PC_5:
|
||||
sConfig.Channel = ADC_CHANNEL_15;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -45,7 +45,9 @@
|
|||
I2C_HandleTypeDef I2cHandle;
|
||||
|
||||
int i2c1_inited = 0;
|
||||
#if defined(I2C2_BASE)
|
||||
int i2c2_inited = 0;
|
||||
#endif
|
||||
|
||||
void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
||||
{
|
||||
|
@ -68,6 +70,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
|||
pin_mode(scl, OpenDrain);
|
||||
}
|
||||
|
||||
#if defined(I2C2_BASE)
|
||||
// Enable I2C2 clock and pinout if not done
|
||||
if ((obj->i2c == I2C_2) && !i2c2_inited) {
|
||||
i2c2_inited = 1;
|
||||
|
@ -78,6 +81,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
|||
pin_mode(sda, OpenDrain);
|
||||
pin_mode(scl, OpenDrain);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Reset to clear pending flags if any
|
||||
i2c_reset(obj);
|
||||
|
@ -291,10 +295,12 @@ void i2c_reset(i2c_t *obj)
|
|||
__I2C1_FORCE_RESET();
|
||||
__I2C1_RELEASE_RESET();
|
||||
}
|
||||
#if defined(I2C2_BASE)
|
||||
if (obj->i2c == I2C_2) {
|
||||
__I2C2_FORCE_RESET();
|
||||
__I2C2_RELEASE_RESET();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEVICE_I2CSLAVE
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -27,14 +27,24 @@
|
|||
*/
|
||||
#include "cmsis.h"
|
||||
|
||||
extern int stdio_uart_inited;
|
||||
|
||||
// This function is called after RAM initialization and before main.
|
||||
void mbed_sdk_init()
|
||||
{
|
||||
/* Configure the Cube driver */
|
||||
SystemCoreClock = 8000000; // At this stage the HSI is used as system clock
|
||||
|
||||
HAL_Init();
|
||||
|
||||
/* Configure the System clock source, PLL Multiplier and Divider factors,
|
||||
AHB/APBx prescalers and Flash settings */
|
||||
SetSysClock();
|
||||
|
||||
// Update the SystemCoreClock variable.
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
// reset serial next time it is called, now that system clock is set
|
||||
stdio_uart_inited = 0;
|
||||
|
||||
#if defined(TARGET_STM32F070RB) || defined(TARGET_STM32F072RB) || defined(TARGET_STM32F091RC)
|
||||
// Need to restart HAL driver after the RAM is initialized
|
||||
HAL_Init();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -62,18 +62,24 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
|||
gpio_add = GPIOB_BASE;
|
||||
__GPIOB_CLK_ENABLE();
|
||||
break;
|
||||
#if defined(GPIOC_BASE)
|
||||
case PortC:
|
||||
gpio_add = GPIOC_BASE;
|
||||
__GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOD_BASE)
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOF_BASE)
|
||||
case PortF:
|
||||
gpio_add = GPIOF_BASE;
|
||||
__GPIOF_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -54,11 +54,21 @@ void pwmout_init(pwmout_t* obj, PinName pin)
|
|||
#if defined(TIM2_BASE)
|
||||
if (obj->pwm == PWM_2) __TIM2_CLK_ENABLE();
|
||||
#endif
|
||||
#if defined(TIM3_BASE)
|
||||
if (obj->pwm == PWM_3) __TIM3_CLK_ENABLE();
|
||||
#endif
|
||||
#if defined(TIM14_BASE)
|
||||
if (obj->pwm == PWM_14) __TIM14_CLK_ENABLE();
|
||||
#endif
|
||||
#if defined(TIM15_BASE)
|
||||
if (obj->pwm == PWM_15) __TIM15_CLK_ENABLE();
|
||||
#endif
|
||||
#if defined(TIM16_BASE)
|
||||
if (obj->pwm == PWM_16) __TIM16_CLK_ENABLE();
|
||||
#endif
|
||||
#if defined(TIM17_BASE)
|
||||
if (obj->pwm == PWM_17) __TIM17_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// Configure GPIO
|
||||
pinmap_pinout(pin, PinMap_PWM);
|
||||
|
@ -101,7 +111,41 @@ void pwmout_write(pwmout_t* obj, float value)
|
|||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
|
||||
#if defined (TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
|
||||
#if defined (TARGET_STM32F031K6)
|
||||
switch (obj->pin) {
|
||||
// Channels 1
|
||||
case PA_4:
|
||||
case PA_6:
|
||||
case PA_8:
|
||||
case PB_4:
|
||||
channel = TIM_CHANNEL_1;
|
||||
break;
|
||||
// Channels 1N
|
||||
case PB_6:
|
||||
case PB_7:
|
||||
channel = TIM_CHANNEL_1;
|
||||
complementary_channel = 1;
|
||||
break;
|
||||
// Channels 2
|
||||
case PA_7:
|
||||
case PA_9:
|
||||
case PB_5:
|
||||
channel = TIM_CHANNEL_2;
|
||||
break;
|
||||
// Channels 3
|
||||
case PA_10:
|
||||
case PB_0:
|
||||
channel = TIM_CHANNEL_3;
|
||||
break;
|
||||
// Channels 4
|
||||
case PA_11:
|
||||
case PB_1:
|
||||
channel = TIM_CHANNEL_4;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
#elif defined (TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
|
||||
switch (obj->pin) {
|
||||
// Channels 1
|
||||
case PA_4:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -47,6 +47,11 @@ static uint32_t serial_irq_ids[UART_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
|
|||
|
||||
static uint32_t serial_irq_ids[UART_NUM] = {0, 0};
|
||||
|
||||
#elif defined (TARGET_STM32F031K6)
|
||||
#define UART_NUM (1)
|
||||
|
||||
static uint32_t serial_irq_ids[UART_NUM] = {0};
|
||||
|
||||
#else
|
||||
#define UART_NUM (4)
|
||||
|
||||
|
@ -102,10 +107,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
|||
obj->index = 0;
|
||||
}
|
||||
|
||||
#if defined USART2_BASE
|
||||
if (obj->uart == UART_2) {
|
||||
__USART2_CLK_ENABLE();
|
||||
obj->index = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined USART3_BASE
|
||||
if (obj->uart == UART_3) {
|
||||
|
@ -186,11 +193,13 @@ void serial_free(serial_t *obj)
|
|||
__USART1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
#if defined(USART2_BASE)
|
||||
if (obj->uart == UART_2) {
|
||||
__USART2_FORCE_RESET();
|
||||
__USART2_RELEASE_RESET();
|
||||
__USART2_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined USART3_BASE
|
||||
if (obj->uart == UART_3) {
|
||||
|
@ -309,10 +318,12 @@ static void uart1_irq(void)
|
|||
uart_irq(UART_1, 0);
|
||||
}
|
||||
|
||||
#if defined(USART2_BASE)
|
||||
static void uart2_irq(void)
|
||||
{
|
||||
uart_irq(UART_2, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined USART3_BASE
|
||||
static void uart3_irq(void)
|
||||
|
@ -374,10 +385,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
|||
vector = (uint32_t)&uart1_irq;
|
||||
}
|
||||
|
||||
#if defined(USART2_BASE)
|
||||
if (obj->uart == UART_2) {
|
||||
irq_n = USART2_IRQn;
|
||||
vector = (uint32_t)&uart2_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (TARGET_STM32F091RC)
|
||||
if (obj->uart == UART_3) {
|
||||
|
@ -413,15 +426,19 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
|||
#elif defined (TARGET_STM32F030R8) || defined (TARGET_STM32F051R8)
|
||||
|
||||
#else
|
||||
#if defined(USART3_BASE)
|
||||
if (obj->uart == UART_3) {
|
||||
irq_n = USART3_4_IRQn;
|
||||
vector = (uint32_t)&uart3_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USART4_BASE)
|
||||
if (obj->uart == UART_4) {
|
||||
irq_n = USART3_4_IRQn;
|
||||
vector = (uint32_t)&uart4_irq;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (enable) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* mbed Microcontroller Library
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2014, STMicroelectronics
|
||||
* Copyright (c) 2015, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -80,9 +80,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
if (obj->spi == SPI_1) {
|
||||
__SPI1_CLK_ENABLE();
|
||||
}
|
||||
#if defined(SPI2_BASE)
|
||||
if (obj->spi == SPI_2) {
|
||||
__SPI2_CLK_ENABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Configure the SPI pins
|
||||
pinmap_pinout(mosi, PinMap_SPI_MOSI);
|
||||
|
@ -118,11 +120,13 @@ void spi_free(spi_t *obj)
|
|||
__SPI1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
#if defined(SPI2_BASE)
|
||||
if (obj->spi == SPI_2) {
|
||||
__SPI2_FORCE_RESET();
|
||||
__SPI2_RELEASE_RESET();
|
||||
__SPI2_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
|
|
Loading…
Reference in New Issue