Skip to content

Commit 5deccb7

Browse files
kbumsikfpistm
authored andcommitted
[MP1] Update core to support MP1
1 parent f67652d commit 5deccb7

File tree

11 files changed

+200
-14
lines changed

11 files changed

+200
-14
lines changed

cores/arduino/HardwareTimer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,11 @@ timer_index_t get_timer_index(TIM_TypeDef *instance)
947947
*/
948948
uint32_t HardwareTimer::getTimerClkFreq()
949949
{
950+
#if defined(STM32MP1xx)
951+
uint8_t timerClkSrc = getTimerClkSrc(_timerObj.handle.Instance);
952+
uint64_t clkSelection = timerClkSrc == 1 ? RCC_PERIPHCLK_TIMG1 : RCC_PERIPHCLK_TIMG2;
953+
return HAL_RCCEx_GetPeriphCLKFreq(clkSelection);
954+
#else
950955
RCC_ClkInitTypeDef clkconfig = {};
951956
uint32_t pFLatency = 0U;
952957
uint32_t uwTimclock = 0U, uwAPBxPrescaler = 0U;
@@ -1062,6 +1067,7 @@ uint32_t HardwareTimer::getTimerClkFreq()
10621067
}
10631068
#endif /* STM32H7xx */
10641069
return uwTimclock;
1070+
#endif /* STM32MP1xx */
10651071
}
10661072

10671073
/**

cores/arduino/stm32/analog.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,10 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
623623
#ifdef __HAL_RCC_ADC_CLK_ENABLE
624624
__HAL_RCC_ADC_CLK_ENABLE();
625625
#endif
626-
/* For STM32F1xx and STM32H7xx, ADC prescaler is configured in
626+
/* For STM32F1xx, STM32H7xx, and STM32MP1xx ADC prescaler is configured in
627627
SystemClock_Config (variant.cpp) */
628-
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx) && !defined(STM32H7xx)
628+
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx) && \
629+
!defined(STM32H7xx) && !defined(STM32MP1xx)
629630
/* ADC Periph interface clock configuration */
630631
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
631632
#endif
@@ -766,7 +767,7 @@ uint16_t adc_read_value(PinName pin)
766767
uint32_t samplingTime = ADC_SAMPLINGTIME;
767768
uint32_t channel = 0;
768769

769-
if (pin & PADC_BASE) {
770+
if ((pin & PADC_BASE) && (pin < ANA_START)) {
770771
#if defined(STM32H7xx)
771772
AdcHandle.Instance = ADC3;
772773
#else
@@ -811,7 +812,8 @@ uint16_t adc_read_value(PinName pin)
811812
#endif
812813
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F3xx) && \
813814
!defined(STM32F4xx) && !defined(STM32F7xx) && !defined(STM32G4xx) && \
814-
!defined(STM32H7xx) && !defined(STM32L4xx) && !defined(STM32WBxx)
815+
!defined(STM32H7xx) && !defined(STM32L4xx) && !defined(STM32MP1xx) && \
816+
!defined(STM32WBxx)
815817
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
816818
#endif
817819
#ifdef ADC_CHANNELS_BANK_A
@@ -829,7 +831,7 @@ uint16_t adc_read_value(PinName pin)
829831
#if !defined(STM32F1xx) && !defined(STM32F373xC) && !defined(STM32F378xx)
830832
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
831833
#endif
832-
#if !defined(STM32F1xx) && !defined(STM32H7xx) && \
834+
#if !defined(STM32F1xx) && !defined(STM32H7xx) && !defined(STM32MP1xx) && \
833835
!defined(STM32F373xC) && !defined(STM32F378xx)
834836
AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
835837
#endif

cores/arduino/stm32/backup.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ extern "C" {
3131

3232
/* Exported macro ------------------------------------------------------------*/
3333
#if (!defined(STM32F0xx) && !defined(STM32F3xx) && !defined(STM32L0xx) &&\
34-
!defined(STM32L1xx) && !defined(STM32L4xx)) || defined(RTC_BACKUP_SUPPORT)
34+
!defined(STM32L1xx) && !defined(STM32L4xx) && !defined(STM32MP1xx)) || \
35+
defined(RTC_BACKUP_SUPPORT)
3536
#if !defined(STM32L412xx) && !defined(STM32L422xx)
3637
#define ENABLE_BACKUP_SUPPORT
3738
#endif

cores/arduino/stm32/clock.c

+23
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
extern "C" {
4444
#endif
4545

46+
#if defined(STM32MP1xx)
47+
#include "stm32mp1xx_hal.h"
48+
/* STM32MP1xx does not have own stm32mp1xx_ll_cortex.h so define functions manually.
49+
*/
50+
__STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
51+
{
52+
return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
53+
}
54+
#endif
55+
4656
/**
4757
* @brief Function called to read the current micro second
4858
* @param None
@@ -100,6 +110,15 @@ void enableClock(sourceClock_t source)
100110
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
101111
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
102112

113+
#if defined(STM32MP1xx)
114+
/** Clock source selection is done by First Stage Boot Loader on Cortex A
115+
* See variant.cpp for corresponding boards.
116+
*/
117+
if (!IS_ENGINEERING_BOOT_MODE()) {
118+
return;
119+
}
120+
#endif /* STM32MP1xx */
121+
103122
enableBackupDomain();
104123

105124
switch (source) {
@@ -118,7 +137,11 @@ void enableClock(sourceClock_t source)
118137
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
119138
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
120139
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
140+
#if defined(STM32MP1xx)
141+
RCC_OscInitStruct.HSICalibrationValue = 0x00;
142+
#else
121143
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
144+
#endif
122145
}
123146
break;
124147
case LSE_CLOCK:

cores/arduino/stm32/interrupt.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ static gpio_irq_conf_str gpio_irq_conf[NB_EXTI] = {
6969
{.irqnb = EXTI4_15_IRQn, .callback = NULL}, //GPIO_PIN_13
7070
{.irqnb = EXTI4_15_IRQn, .callback = NULL}, //GPIO_PIN_14
7171
{.irqnb = EXTI4_15_IRQn, .callback = NULL} //GPIO_PIN_15
72+
#elif defined (STM32MP1xx)
73+
{.irqnb = EXTI0_IRQn, .callback = NULL}, //GPIO_PIN_0
74+
{.irqnb = EXTI1_IRQn, .callback = NULL}, //GPIO_PIN_1
75+
{.irqnb = EXTI2_IRQn, .callback = NULL}, //GPIO_PIN_2
76+
{.irqnb = EXTI3_IRQn, .callback = NULL}, //GPIO_PIN_3
77+
{.irqnb = EXTI4_IRQn, .callback = NULL}, //GPIO_PIN_4
78+
{.irqnb = EXTI5_IRQn, .callback = NULL}, //GPIO_PIN_5
79+
{.irqnb = EXTI6_IRQn, .callback = NULL}, //GPIO_PIN_6
80+
{.irqnb = EXTI7_IRQn, .callback = NULL}, //GPIO_PIN_7
81+
{.irqnb = EXTI8_IRQn, .callback = NULL}, //GPIO_PIN_8
82+
{.irqnb = EXTI9_IRQn, .callback = NULL}, //GPIO_PIN_9
83+
{.irqnb = EXTI10_IRQn, .callback = NULL}, //GPIO_PIN_10
84+
{.irqnb = EXTI11_IRQn, .callback = NULL}, //GPIO_PIN_11
85+
{.irqnb = EXTI12_IRQn, .callback = NULL}, //GPIO_PIN_12
86+
{.irqnb = EXTI13_IRQn, .callback = NULL}, //GPIO_PIN_13
87+
{.irqnb = EXTI14_IRQn, .callback = NULL}, //GPIO_PIN_14
88+
{.irqnb = EXTI15_IRQn, .callback = NULL} //GPIO_PIN_15
7289
#else
7390
{.irqnb = EXTI0_IRQn, .callback = NULL}, //GPIO_PIN_0
7491
{.irqnb = EXTI1_IRQn, .callback = NULL}, //GPIO_PIN_1

cores/arduino/stm32/low_power.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void (*WakeUpUartCb)(void) = NULL;
6363
*/
6464
void LowPower_init()
6565
{
66-
#if !defined(STM32H7xx) && ! defined(STM32WBxx)
66+
#if !defined(STM32H7xx) && !defined(STM32MP1xx) && !defined(STM32WBxx)
6767
/* Enable Power Clock */
6868
__HAL_RCC_PWR_CLK_ENABLE();
6969
#endif

cores/arduino/stm32/rtc.c

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
#include "rtc.h"
4040

4141
#ifdef HAL_RTC_MODULE_ENABLED
42+
#if defined(STM32MP1xx)
43+
/**
44+
* Currently there is no RTC driver for STM32MP1xx. If RTC is used in the future
45+
* the function call HAL_RCCEx_PeriphCLKConfig() shall be done under
46+
* if(IS_ENGINEERING_BOOT_MODE()), since clock source selection is done by
47+
* First Stage Boot Loader on Cortex-A.
48+
*/
49+
#error "RTC shall not be handled by Arduino in STM32MP1xx."
50+
#endif /* STM32MP1xx */
4251

4352
#ifdef __cplusplus
4453
extern "C" {

cores/arduino/stm32/spi_com.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ uint32_t spi_getClkFreqInst(SPI_TypeDef *spi_inst)
6060
UNUSED(spi_inst);
6161
/* SPIx source CLK is PCKL1 */
6262
spi_freq = HAL_RCC_GetPCLK1Freq();
63+
#elif defined(STM32MP1xx)
64+
/* Get source clock depending on SPI instance */
65+
if (spi_inst != NP) {
66+
switch ((uint32_t)spi_inst) {
67+
case (uint32_t)SPI1:
68+
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI1);
69+
break;
70+
case (uint32_t)SPI2:
71+
case (uint32_t)SPI3:
72+
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI23);
73+
break;
74+
case (uint32_t)SPI4:
75+
case (uint32_t)SPI5:
76+
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI45);
77+
break;
78+
case (uint32_t)SPI6:
79+
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI6);
80+
break;
81+
default:
82+
core_debug("CLK: SPI instance not set");
83+
break;
84+
}
85+
}
6386
#else
6487
if (spi_inst != NP) {
6588
/* Get source clock depending on SPI instance */
@@ -223,7 +246,7 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
223246
handle->Init.TIMode = SPI_TIMODE_DISABLE;
224247
#if defined(STM32F0xx) || defined(STM32F3xx) || defined(STM32F7xx) ||\
225248
defined(STM32G0xx) || defined(STM32H7xx) || defined(STM32L4xx) ||\
226-
defined(STM32WBxx)
249+
defined(STM32WBxx) || defined(STM32MP1xx)
227250
handle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
228251
#endif
229252

cores/arduino/stm32/stm32yyxx_hal_conf.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
*/
9090
/*#define HAL_UART_MODULE_ENABLED*/
9191
/*#define HAL_PCD_MODULE_ENABLED*/
92+
/*#define HAL_IPCC_MODULE_ENABLED*/
9293

9394
/*
9495
* Unused HAL modules

cores/arduino/stm32/timer.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C" {
5353
#elif defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx)
5454
#define TIM1_IRQn TIM1_UP_TIM10_IRQn
5555
#define TIM1_IRQHandler TIM1_UP_TIM10_IRQHandler
56-
#elif defined(STM32H7xx)
56+
#elif defined(STM32H7xx) || defined(STM32MP1xx)
5757
#define TIM1_IRQn TIM1_UP_IRQn
5858
#define TIM1_IRQHandler TIM1_UP_IRQHandler
5959
#endif
@@ -63,7 +63,7 @@ extern "C" {
6363
#if defined(STM32G0xx)
6464
#define TIM6_IRQn TIM6_DAC_LPTIM1_IRQn
6565
#define TIM6_IRQHandler TIM6_DAC_LPTIM1_IRQHandler
66-
#elif !defined(STM32F1xx) && !defined(STM32L1xx)
66+
#elif !defined(STM32F1xx) && !defined(STM32L1xx) && !defined(STM32MP1xx)
6767
#define TIM6_IRQn TIM6_DAC_IRQn
6868
#define TIM6_IRQHandler TIM6_DAC_IRQHandler
6969
#endif
@@ -84,7 +84,7 @@ extern "C" {
8484
|| defined(STM32H7xx)
8585
#define TIM8_IRQn TIM8_UP_TIM13_IRQn
8686
#define TIM8_IRQHandler TIM8_UP_TIM13_IRQHandler
87-
#elif defined(STM32F3xx) || defined(STM32G4xx) || defined(STM32L4xx)
87+
#elif defined(STM32F3xx) || defined(STM32G4xx) || defined(STM32L4xx) || defined(STM32MP1xx)
8888
#define TIM8_IRQn TIM8_UP_IRQn
8989
#define TIM8_IRQHandler TIM8_UP_IRQHandler
9090
#endif

0 commit comments

Comments
 (0)