mirror of https://github.com/ARMmbed/mbed-os.git
[NUCLEO_L432KC] Update HAL API
parent
2198dccd6e
commit
b91c65ee2d
|
@ -48,7 +48,9 @@ I2C_HandleTypeDef I2cHandle;
|
|||
void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
||||
{
|
||||
static int i2c1_inited = 0;
|
||||
#if defined(I2C2_BASE)
|
||||
static int i2c2_inited = 0;
|
||||
#endif
|
||||
#if defined(I2C3_BASE)
|
||||
static int i2c3_inited = 0;
|
||||
#endif
|
||||
|
@ -72,6 +74,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;
|
||||
|
@ -82,6 +85,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
|||
pin_mode(sda, OpenDrain);
|
||||
pin_mode(scl, OpenDrain);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(I2C3_BASE)
|
||||
// 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_RELEASE_RESET();
|
||||
}
|
||||
#if defined(I2C2_BASE)
|
||||
if (obj->i2c == I2C_2) {
|
||||
__HAL_RCC_I2C2_FORCE_RESET();
|
||||
__HAL_RCC_I2C2_RELEASE_RESET();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEVICE_I2CSLAVE
|
||||
|
|
|
@ -68,14 +68,18 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx)
|
|||
gpio_add = GPIOC_BASE;
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
break;
|
||||
#if defined(GPIOD_BASE)
|
||||
case PortD:
|
||||
gpio_add = GPIOD_BASE;
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOE_BASE)
|
||||
case PortE:
|
||||
gpio_add = GPIOE_BASE;
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
break;
|
||||
#endif
|
||||
case PortH:
|
||||
gpio_add = GPIOH_BASE;
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
|
|
|
@ -53,13 +53,23 @@ void pwmout_init(pwmout_t* obj, PinName pin)
|
|||
// Enable TIM clock
|
||||
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_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();
|
||||
#endif
|
||||
#if defined(TIM4_BASE)
|
||||
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();
|
||||
#endif
|
||||
#if defined(TIM8_BASE)
|
||||
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_16) __HAL_RCC_TIM16_CLK_ENABLE();
|
||||
#if defined(TIM17_BASE)
|
||||
if (obj->pwm == PWM_17) __HAL_RCC_TIM17_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
// Configure GPIO
|
||||
pinmap_pinout(pin, PinMap_PWM);
|
||||
|
|
|
@ -114,27 +114,34 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
|||
obj->index = 1;
|
||||
}
|
||||
|
||||
#if defined(USART3_BASE)
|
||||
if (obj->uart == UART_3) {
|
||||
__HAL_RCC_USART3_FORCE_RESET();
|
||||
__HAL_RCC_USART3_RELEASE_RESET();
|
||||
__HAL_RCC_USART3_CLK_ENABLE();
|
||||
obj->index = 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART4_BASE)
|
||||
if (obj->uart == UART_4) {
|
||||
__HAL_RCC_UART4_FORCE_RESET();
|
||||
__HAL_RCC_UART4_RELEASE_RESET();
|
||||
__HAL_RCC_UART4_CLK_ENABLE();
|
||||
obj->index = 3;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART5_BASE)
|
||||
if (obj->uart == UART_5) {
|
||||
__HAL_RCC_UART5_FORCE_RESET();
|
||||
__HAL_RCC_UART5_RELEASE_RESET();
|
||||
__HAL_RCC_UART5_CLK_ENABLE();
|
||||
obj->index = 4;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LPUART1_BASE)
|
||||
if (obj->uart == LPUART_1) {
|
||||
__HAL_RCC_LPUART1_FORCE_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->index = 5;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Configure the UART pins
|
||||
pinmap_pinout(tx, PinMap_UART_TX);
|
||||
|
@ -184,29 +192,37 @@ void serial_free(serial_t *obj)
|
|||
__HAL_RCC_USART2_CLK_DISABLE();
|
||||
}
|
||||
|
||||
#if defined(USART3_BASE)
|
||||
if (obj->uart == UART_3) {
|
||||
__HAL_RCC_USART3_FORCE_RESET();
|
||||
__HAL_RCC_USART3_RELEASE_RESET();
|
||||
__HAL_RCC_USART3_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART4_BASE)
|
||||
if (obj->uart == UART_4) {
|
||||
__HAL_RCC_UART4_FORCE_RESET();
|
||||
__HAL_RCC_UART4_RELEASE_RESET();
|
||||
__HAL_RCC_UART4_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART5_BASE)
|
||||
if (obj->uart == UART_5) {
|
||||
__HAL_RCC_UART5_FORCE_RESET();
|
||||
__HAL_RCC_UART5_RELEASE_RESET();
|
||||
__HAL_RCC_UART5_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LPUART1_BASE)
|
||||
if (obj->uart == LPUART_1) {
|
||||
__HAL_RCC_LPUART1_FORCE_RESET();
|
||||
__HAL_RCC_LPUART1_RELEASE_RESET();
|
||||
__HAL_RCC_LPUART1_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Configure GPIOs
|
||||
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);
|
||||
}
|
||||
|
||||
#if defined(USART3_BASE)
|
||||
static void uart3_irq(void)
|
||||
{
|
||||
uart_irq(UART_3, 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART4_BASE)
|
||||
static void uart4_irq(void)
|
||||
{
|
||||
uart_irq(UART_4, 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART5_BASE)
|
||||
static void uart5_irq(void)
|
||||
{
|
||||
uart_irq(UART_5, 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LPUART1_BASE)
|
||||
static void lpuart1_irq(void)
|
||||
{
|
||||
uart_irq(LPUART_1, 5);
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#if defined(USART3_BASE)
|
||||
if (obj->uart == UART_3) {
|
||||
irq_n = USART3_IRQn;
|
||||
vector = (uint32_t)&uart3_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART4_BASE)
|
||||
if (obj->uart == UART_4) {
|
||||
irq_n = UART4_IRQn;
|
||||
vector = (uint32_t)&uart4_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(UART5_BASE)
|
||||
if (obj->uart == UART_5) {
|
||||
irq_n = UART5_IRQn;
|
||||
vector = (uint32_t)&uart5_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LPUART1_BASE)
|
||||
if (obj->uart == LPUART_1) {
|
||||
irq_n = LPUART1_IRQn;
|
||||
vector = (uint32_t)&lpuart1_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (enable) {
|
||||
|
||||
|
|
|
@ -85,9 +85,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
if (obj->spi == SPI_1) {
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
}
|
||||
#if defined(SPI2_BASE)
|
||||
if (obj->spi == SPI_2) {
|
||||
__HAL_RCC_SPI2_CLK_ENABLE();
|
||||
}
|
||||
#endif
|
||||
if (obj->spi == SPI_3) {
|
||||
__HAL_RCC_SPI3_CLK_ENABLE();
|
||||
}
|
||||
|
@ -129,11 +131,13 @@ void spi_free(spi_t *obj)
|
|||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
#if defined(SPI2_BASE)
|
||||
if (obj->spi == SPI_2) {
|
||||
__HAL_RCC_SPI2_FORCE_RESET();
|
||||
__HAL_RCC_SPI2_RELEASE_RESET();
|
||||
__HAL_RCC_SPI2_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (obj->spi == SPI_3) {
|
||||
__HAL_RCC_SPI3_FORCE_RESET();
|
||||
|
@ -204,16 +208,18 @@ void spi_frequency(spi_t *obj, int hz)
|
|||
/* Get source clock depending on SPI instance */
|
||||
switch ((int)obj->spi) {
|
||||
case SPI_1:
|
||||
/* SPI_1. Source CLK is PCKL2 */
|
||||
spi_hz = HAL_RCC_GetPCLK2Freq();
|
||||
break;
|
||||
case SPI_2:
|
||||
case SPI_3:
|
||||
/* SPI_2, SPI_3. Source CLK is PCKL1 */
|
||||
spi_hz = HAL_RCC_GetPCLK1Freq();
|
||||
break;
|
||||
default:
|
||||
error("SPI instance not set");
|
||||
/* SPI_1. Source CLK is PCKL2 */
|
||||
spi_hz = HAL_RCC_GetPCLK2Freq();
|
||||
break;
|
||||
#if defined(SPI2_BASE)
|
||||
case SPI_2:
|
||||
#endif
|
||||
case SPI_3:
|
||||
/* SPI_2, SPI_3. Source CLK is PCKL1 */
|
||||
spi_hz = HAL_RCC_GetPCLK1Freq();
|
||||
break;
|
||||
default:
|
||||
error("SPI instance not set");
|
||||
}
|
||||
|
||||
/* Define pre-scaler in order to get highest available frequency below requested frequency */
|
||||
|
|
|
@ -29,7 +29,11 @@
|
|||
#include "us_ticker_api.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 int us_ticker_inited = 0;
|
||||
|
|
Loading…
Reference in New Issue