Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PwmOut API support for STM32H5 #299

Merged
merged 4 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions targets/TARGET_STM/TARGET_STM32H5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ add_library(mbed-stm32h5 INTERFACE)

target_sources(mbed-stm32h5
INTERFACE
gpio_irq_device.c
serial_device.c
clock_cfg/system_clock.c
gpio_irq_device.c
serial_device.c
pwmout_device.c
)

target_include_directories(mbed-stm32h5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ MBED_WEAK const PinMap PinMap_PWM[] = {
{PA_3, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_TIM1, 1, 1)}, // TIM1_CH1N // Connected to STDIO_UART_RX
//{PA_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 // Connected to STDIO_UART_RX
{PA_4, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N // Connected to STDIO_UART_TX
{PA_5, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 // Connected to USER_LED
//{PA_5, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 // Connected to USER_LED
JohnK1987 marked this conversation as resolved.
Show resolved Hide resolved
{PA_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
{PA_7, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N
//{PA_7, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_TIM2, 3, 0)}, // TIM2_CH3
Expand All @@ -130,7 +130,7 @@ MBED_WEAK const PinMap PinMap_PWM[] = {
{PA_11, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 // Connected to USB_FS_DN
//{PA_12, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_TIM2, 4, 0)}, // TIM2_CH4 // Connected to USB_FS_DP
{PA_12, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 // Connected to USB_FS_DP
{PA_13, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_LPTIM1, 1, 0)}, // TIM1_CH1 // Connected to T_SWDIO
//{PA_13, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_LPTIM1, 1, 0)}, // TIM1_CH1 // Connected to T_SWDIO
{PA_14, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 // Connected to T_SWCLK
{PA_14, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_TIM1, 4, 1)}, // TIM1_CH4N // Connected to T_SWCLK
{PA_14, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 // Connected to T_SWCLK
Expand All @@ -143,7 +143,7 @@ MBED_WEAK const PinMap PinMap_PWM[] = {
{PB_2, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N
//{PB_2, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF14_TIM2, 1, 0)}, // TIM2_CH1
//{PB_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 // Connected to T_SWO
{PB_4, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_LPTIM1, 2, 0)}, // TIM1_CH2
//{PB_4, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_LPTIM1, 2, 0)}, // TIM1_CH2
JohnK1987 marked this conversation as resolved.
Show resolved Hide resolved
{PB_4, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM1, 4, 1)}, // TIM1_CH4N
{PB_4, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
{PB_5, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3
Expand Down
10 changes: 0 additions & 10 deletions targets/TARGET_STM/TARGET_STM32H5/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ struct trng_s {
RNG_HandleTypeDef handle;
};

struct pwmout_s {
PWMName pwm;
PinName pin;
uint32_t prescaler;
uint32_t period;
uint32_t pulse;
uint8_t channel;
uint8_t inverted;
};

struct spi_s {
SPI_HandleTypeDef handle;
IRQn_Type spiIRQ;
Expand Down
56 changes: 56 additions & 0 deletions targets/TARGET_STM/TARGET_STM32H5/pwmout_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* mbed Microcontroller Library
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************
*
* Copyright (c) 2015-2024 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

#include "cmsis.h"
#include "pwmout_api.h"
#include "pwmout_device.h"

#if DEVICE_PWMOUT

const pwm_apb_map_t pwm_apb_map_table[] = {
{PWM_1, PWMOUT_ON_APB1},
{PWM_2, PWMOUT_ON_APB1},
{PWM_3, PWMOUT_ON_APB2},
#if defined(TIM4_BASE)
{PWM_4, PWMOUT_ON_APB2},
#endif
#if defined(TIM5_BASE)
{PWM_5, PWMOUT_ON_APB1},
#endif
#if defined(TIM8_BASE)
{PWM_8, PWMOUT_ON_APB2},
#endif
#if defined(TIM12_BASE)
{PWM_12, PWMOUT_ON_APB1},
#endif
#if defined(TIM13_BASE)
{PWM_13, PWMOUT_ON_APB2},
#endif
#if defined(TIM14_BASE)
{PWM_14, PWMOUT_ON_APB1},
#endif
#if defined(TIM15_BASE)
{PWM_15, PWMOUT_ON_APB2},
#endif
#if defined(TIM16_BASE)
{PWM_16, PWMOUT_ON_APB1},
#endif
#if defined(TIM17_BASE)
{PWM_17, PWMOUT_ON_APB2},
#endif
{(PWMName) 0, PWMOUT_UNKNOWN}
};

#endif // DEVICE_PWMOUT
47 changes: 47 additions & 0 deletions targets/TARGET_STM/TARGET_STM32H5/pwmout_device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* mbed Microcontroller Library
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************
*
* Copyright (c) 2015-2024 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

#ifndef MBED_PWMOUT_DEVICE_H
#define MBED_PWMOUT_DEVICE_H

#include "cmsis.h"

#ifdef __cplusplus
extern "C" {
#endif

#if DEVICE_PWMOUT

typedef enum {
PWMOUT_ON_APB1 = 0,
PWMOUT_ON_APB2 = 1,
PWMOUT_UNKNOWN = 2
} PwmoutApb;

/* Structure to describe Timers to APB */
typedef struct pwm_apb_map {
PWMName pwm; // an index entry for each EXIT line
PwmoutApb pwmoutApb;
} pwm_apb_map_t;

extern const pwm_apb_map_t pwm_apb_map_table[];

#endif // DEVICE_PWMOUT

#ifdef __cplusplus
}
#endif

#endif
19 changes: 19 additions & 0 deletions targets/TARGET_STM/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,25 @@ uint32_t i2c_get_timing(I2CName i2c, uint32_t current_timing, int current_hz,
break;
}
break;
#endif
#if defined (I2C_PCLK_250M)
JohnK1987 marked this conversation as resolved.
Show resolved Hide resolved
case I2C_PCLK_250M:
switch (hz) {
case 100000:
tim = TIMING_VAL_250M_CLK_100KHZ;
break;
case 400000:
tim = TIMING_VAL_250M_CLK_400KHZ;
break;
case 1000000:
tim = TIMING_VAL_250M_CLK_1MHZ;
break;
default:
MBED_ASSERT((hz == 100000) || (hz == 400000) || \
(hz == 1000000));
break;
}
break;
#endif
default:
/* If MBED_CONF_TARGET_I2C_TIMING_VALUE_ALGO assert is triggered.
Expand Down
1 change: 0 additions & 1 deletion targets/targets.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,6 @@
"ANALOGOUT",
"ANALOGIN",
"FLASH",
"PWMOUT",
"LPTICKER",
"CAN",
"SERIAL_FC",
Expand Down
Loading