Skip to content

[New variant] STM32MP157_DK #717

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

Merged
merged 10 commits into from
Nov 15, 2019
Next Next commit
[MP1] Update core to support MP1
  • Loading branch information
kbumsik committed Nov 8, 2019
commit 99da9acf9adab17c4c2f20de847aee90546036af
6 changes: 6 additions & 0 deletions cores/arduino/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ timer_index_t get_timer_index(TIM_TypeDef *instance)
*/
uint32_t HardwareTimer::getTimerClkFreq()
{
#if defined(STM32MP1xx)
uint8_t timerClkSrc = getTimerClkSrc(_timerObj.handle.Instance);
uint64_t clkSelection = timerClkSrc == 1 ? RCC_PERIPHCLK_TIMG1 : RCC_PERIPHCLK_TIMG2;
return HAL_RCCEx_GetPeriphCLKFreq(clkSelection);
#else
RCC_ClkInitTypeDef clkconfig = {};
uint32_t pFLatency = 0U;
uint32_t uwTimclock = 0U, uwAPBxPrescaler = 0U;
Expand Down Expand Up @@ -1028,6 +1033,7 @@ uint32_t HardwareTimer::getTimerClkFreq()
}
#endif /* STM32H7xx */
return uwTimclock;
#endif /* STM32MP1xx */
}

/**
Expand Down
12 changes: 7 additions & 5 deletions cores/arduino/stm32/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,10 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc)
#ifdef __HAL_RCC_ADC_CLK_ENABLE
__HAL_RCC_ADC_CLK_ENABLE();
#endif
/* For STM32F1xx and STM32H7xx, ADC prescaler is configured in
/* For STM32F1xx, STM32H7xx, and STM32MP1xx ADC prescaler is configured in
SystemClock_Config (variant.cpp) */
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx) && !defined(STM32H7xx)
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx) && \
!defined(STM32H7xx) && !defined(STM32MP1xx)
/* ADC Periph interface clock configuration */
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
#endif
Expand Down Expand Up @@ -766,7 +767,7 @@ uint16_t adc_read_value(PinName pin)
uint32_t samplingTime = ADC_SAMPLINGTIME;
uint32_t channel = 0;

if (pin & PADC_BASE) {
if ((pin & PADC_BASE) && (pin < ANA_START)) {
#if defined(STM32H7xx)
AdcHandle.Instance = ADC3;
#else
Expand Down Expand Up @@ -811,7 +812,8 @@ uint16_t adc_read_value(PinName pin)
#endif
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F3xx) && \
!defined(STM32F4xx) && !defined(STM32F7xx) && !defined(STM32G4xx) && \
!defined(STM32H7xx) && !defined(STM32L4xx) && !defined(STM32WBxx)
!defined(STM32H7xx) && !defined(STM32L4xx) && !defined(STM32MP1xx) && \
!defined(STM32WBxx)
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
#endif
#ifdef ADC_CHANNELS_BANK_A
Expand All @@ -829,7 +831,7 @@ uint16_t adc_read_value(PinName pin)
#if !defined(STM32F1xx) && !defined(STM32F373xC) && !defined(STM32F378xx)
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
#endif
#if !defined(STM32F1xx) && !defined(STM32H7xx) && \
#if !defined(STM32F1xx) && !defined(STM32H7xx) && !defined(STM32MP1xx) && \
!defined(STM32F373xC) && !defined(STM32F378xx)
AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
#endif
Expand Down
3 changes: 2 additions & 1 deletion cores/arduino/stm32/backup.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extern "C" {

/* Exported macro ------------------------------------------------------------*/
#if (!defined(STM32F0xx) && !defined(STM32F3xx) && !defined(STM32L0xx) &&\
!defined(STM32L1xx) && !defined(STM32L4xx)) || defined(RTC_BACKUP_SUPPORT)
!defined(STM32L1xx) && !defined(STM32L4xx) && !defined(STM32MP1xx)) || \
defined(RTC_BACKUP_SUPPORT)
#if !defined(STM32L412xx) && !defined(STM32L422xx)
#define ENABLE_BACKUP_SUPPORT
#endif
Expand Down
23 changes: 23 additions & 0 deletions cores/arduino/stm32/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
extern "C" {
#endif

#if defined(STM32MP1xx)
#include "stm32mp1xx_hal.h"
/* STM32MP1xx does not have own stm32mp1xx_ll_cortex.h so define functions manually.
*/
__STATIC_INLINE uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
{
return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
}
#endif

/**
* @brief Function called to read the current micro second
* @param None
Expand Down Expand Up @@ -100,6 +110,15 @@ void enableClock(sourceClock_t source)
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

#if defined(STM32MP1xx)
/** Clock source selection is done by First Stage Boot Loader on Cortex A
* See variant.cpp for corresponding boards.
*/
if (!IS_ENGINEERING_BOOT_MODE()) {
return;
}
#endif /* STM32MP1xx */

enableBackupDomain();

switch (source) {
Expand All @@ -118,7 +137,11 @@ void enableClock(sourceClock_t source)
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
#if defined(STM32MP1xx)
RCC_OscInitStruct.HSICalibrationValue = 0x00;
#else
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
#endif
}
break;
case LSE_CLOCK:
Expand Down
17 changes: 17 additions & 0 deletions cores/arduino/stm32/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ static gpio_irq_conf_str gpio_irq_conf[NB_EXTI] = {
{.irqnb = EXTI4_15_IRQn, .callback = NULL}, //GPIO_PIN_13
{.irqnb = EXTI4_15_IRQn, .callback = NULL}, //GPIO_PIN_14
{.irqnb = EXTI4_15_IRQn, .callback = NULL} //GPIO_PIN_15
#elif defined (STM32MP1xx)
{.irqnb = EXTI0_IRQn, .callback = NULL}, //GPIO_PIN_0
{.irqnb = EXTI1_IRQn, .callback = NULL}, //GPIO_PIN_1
{.irqnb = EXTI2_IRQn, .callback = NULL}, //GPIO_PIN_2
{.irqnb = EXTI3_IRQn, .callback = NULL}, //GPIO_PIN_3
{.irqnb = EXTI4_IRQn, .callback = NULL}, //GPIO_PIN_4
{.irqnb = EXTI5_IRQn, .callback = NULL}, //GPIO_PIN_5
{.irqnb = EXTI6_IRQn, .callback = NULL}, //GPIO_PIN_6
{.irqnb = EXTI7_IRQn, .callback = NULL}, //GPIO_PIN_7
{.irqnb = EXTI8_IRQn, .callback = NULL}, //GPIO_PIN_8
{.irqnb = EXTI9_IRQn, .callback = NULL}, //GPIO_PIN_9
{.irqnb = EXTI10_IRQn, .callback = NULL}, //GPIO_PIN_10
{.irqnb = EXTI11_IRQn, .callback = NULL}, //GPIO_PIN_11
{.irqnb = EXTI12_IRQn, .callback = NULL}, //GPIO_PIN_12
{.irqnb = EXTI13_IRQn, .callback = NULL}, //GPIO_PIN_13
{.irqnb = EXTI14_IRQn, .callback = NULL}, //GPIO_PIN_14
{.irqnb = EXTI15_IRQn, .callback = NULL} //GPIO_PIN_15
#else
{.irqnb = EXTI0_IRQn, .callback = NULL}, //GPIO_PIN_0
{.irqnb = EXTI1_IRQn, .callback = NULL}, //GPIO_PIN_1
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/stm32/low_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void (*WakeUpUartCb)(void) = NULL;
*/
void LowPower_init()
{
#if !defined(STM32H7xx) && ! defined(STM32WBxx)
#if !defined(STM32H7xx) && !defined(STM32MP1xx) && !defined(STM32WBxx)
/* Enable Power Clock */
__HAL_RCC_PWR_CLK_ENABLE();
#endif
Expand Down
9 changes: 9 additions & 0 deletions cores/arduino/stm32/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
#include "rtc.h"

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

#ifdef __cplusplus
extern "C" {
Expand Down
25 changes: 24 additions & 1 deletion cores/arduino/stm32/spi_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ uint32_t spi_getClkFreqInst(SPI_TypeDef *spi_inst)
UNUSED(spi_inst);
/* SPIx source CLK is PCKL1 */
spi_freq = HAL_RCC_GetPCLK1Freq();
#elif defined(STM32MP1xx)
/* Get source clock depending on SPI instance */
if (spi_inst != NP) {
switch ((uint32_t)spi_inst) {
case (uint32_t)SPI1:
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI1);
break;
case (uint32_t)SPI2:
case (uint32_t)SPI3:
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI23);
break;
case (uint32_t)SPI4:
case (uint32_t)SPI5:
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI45);
break;
case (uint32_t)SPI6:
spi_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI6);
break;
default:
core_debug("CLK: SPI instance not set");
break;
}
}
#else
if (spi_inst != NP) {
/* Get source clock depending on SPI instance */
Expand Down Expand Up @@ -223,7 +246,7 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
handle->Init.TIMode = SPI_TIMODE_DISABLE;
#if defined(STM32F0xx) || defined(STM32F3xx) || defined(STM32F7xx) ||\
defined(STM32G0xx) || defined(STM32H7xx) || defined(STM32L4xx) ||\
defined(STM32WBxx)
defined(STM32WBxx) || defined(STM32MP1xx)
handle->Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
#endif

Expand Down
1 change: 1 addition & 0 deletions cores/arduino/stm32/stm32yyxx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
*/
/*#define HAL_UART_MODULE_ENABLED*/
/*#define HAL_PCD_MODULE_ENABLED*/
/*#define HAL_IPCC_MODULE_ENABLED*/

/*
* Unused HAL modules
Expand Down
6 changes: 3 additions & 3 deletions cores/arduino/stm32/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
#elif defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx)
#define TIM1_IRQn TIM1_UP_TIM10_IRQn
#define TIM1_IRQHandler TIM1_UP_TIM10_IRQHandler
#elif defined(STM32H7xx)
#elif defined(STM32H7xx) || defined(STM32MP1xx)
#define TIM1_IRQn TIM1_UP_IRQn
#define TIM1_IRQHandler TIM1_UP_IRQHandler
#endif
Expand All @@ -63,7 +63,7 @@ extern "C" {
#if defined(STM32G0xx)
#define TIM6_IRQn TIM6_DAC_LPTIM1_IRQn
#define TIM6_IRQHandler TIM6_DAC_LPTIM1_IRQHandler
#elif !defined(STM32F1xx) && !defined(STM32L1xx)
#elif !defined(STM32F1xx) && !defined(STM32L1xx) && !defined(STM32MP1xx)
#define TIM6_IRQn TIM6_DAC_IRQn
#define TIM6_IRQHandler TIM6_DAC_IRQHandler
#endif
Expand All @@ -84,7 +84,7 @@ extern "C" {
|| defined(STM32H7xx)
#define TIM8_IRQn TIM8_UP_TIM13_IRQn
#define TIM8_IRQHandler TIM8_UP_TIM13_IRQHandler
#elif defined(STM32F3xx) || defined(STM32G4xx) || defined(STM32L4xx)
#elif defined(STM32F3xx) || defined(STM32G4xx) || defined(STM32L4xx) || defined(STM32MP1xx)
#define TIM8_IRQn TIM8_UP_IRQn
#define TIM8_IRQHandler TIM8_UP_IRQHandler
#endif
Expand Down
Loading