Skip to content

Commit c58275b

Browse files
committed
Add NUCLEO-L053R8 variant
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent dc39c39 commit c58275b

File tree

24 files changed

+1505
-107
lines changed

24 files changed

+1505
-107
lines changed

boards.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ Nucleo_64.menu.Nucleo_64_board.NUCLEO_F303RE.build.cmsis_lib_gcc=arm_cortexM4l_m
9191
#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE'
9292
Nucleo_64.menu.Nucleo_64_board.NUCLEO_F303RE.build.extra_flags=-DSTM32F303xE {build.usb_flags}
9393

94+
# NUCLEO_L053R8 board
95+
96+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8=Nucleo L053R8
97+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.node=NODE_L053R8
98+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.upload.maximum_size=65536
99+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.upload.maximum_data_size=8192
100+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.mcu=cortex-m0
101+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.f_cpu=2000000L
102+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.usb_product="NUCLEO-L053R8"
103+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.board=NUCLEO_L053R8
104+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.series=STM32L0xx
105+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.variant=NUCLEO_L053R8
106+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.cmsis_lib_gcc=arm_cortexM0l_math
107+
#To enable USB add '-DUSBCON'
108+
#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE'
109+
Nucleo_64.menu.Nucleo_64_board.NUCLEO_L053R8.build.extra_flags=-DSTM32L053xx -D__CORTEX_SC=0 {build.usb_flags}
110+
111+
94112
Nucleo_64.menu.upload_method.MassStorageMethod=Mass Storage
95113
Nucleo_64.menu.upload_method.MassStorageMethod.upload.protocol=
96114
Nucleo_64.menu.upload_method.MassStorageMethod.upload.tool=nucleoFlasher

cores/arduino/stm32/HAL/stm32yyxx_ll_lprng.c

Lines changed: 0 additions & 25 deletions
This file was deleted.

cores/arduino/stm32/HAL/stm32yyxx_ll_rng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "stm32f7xx_ll_rng.c"
2020
#endif
2121
#ifdef STM32L0xx
22-
// none
22+
#include "stm32l0xx_ll_rng.c"
2323
#endif
2424
#ifdef STM32L1xx
2525
// none

cores/arduino/stm32/analog.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@
6969
/** @addtogroup STM32F4xx_System_Private_Defines
7070
* @{
7171
*/
72-
#if STM32L0xx
73-
// Contained by handle
74-
#elif defined(ADC_SAMPLETIME_15CYCLES)
72+
#if defined(ADC_SAMPLETIME_15CYCLES)
7573
#define SAMPLINGTIME ADC_SAMPLETIME_15CYCLES;
7674
#elif defined(ADC_SAMPLETIME_13CYCLES_5)
7775
#define SAMPLINGTIME ADC_SAMPLETIME_13CYCLES_5;
@@ -181,9 +179,11 @@ static uint32_t get_adc_channel(PinName pin)
181179
case 17:
182180
channel = ADC_CHANNEL_VREFINT;
183181
break;
184-
case 18:
182+
#ifdef ADC_CHANNEL_VBAT
183+
case 18:
185184
channel = ADC_CHANNEL_VBAT;
186185
break;
186+
#endif
187187
default:
188188
channel = 0;
189189
break;
@@ -204,9 +204,11 @@ static uint32_t get_dac_channel(PinName pin)
204204
case 1:
205205
channel = DAC_CHANNEL_1;
206206
break;
207+
#ifdef DAC_CHANNEL_2
207208
case 2:
208209
channel = DAC_CHANNEL_2;
209210
break;
211+
#endif
210212
default:
211213
channel = 0;
212214
break;
@@ -546,11 +548,16 @@ uint16_t adc_read_value(PinName pin)
546548
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */
547549
AdcHandle.Init.DMAContinuousRequests = DISABLE; /* DMA one-shot mode selected (not applied to this example) */
548550
AdcHandle.State = HAL_ADC_STATE_RESET;
549-
#ifdef STM32F0xx
551+
#if defined (STM32F0xx) || defined (STM32L0xx)
550552
AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
551553
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; /* ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered */
552554
AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN; /* DR register is overwritten with the last conversion result in case of overrun */
555+
#ifdef STM32F0xx
553556
AdcHandle.Init.SamplingTimeCommon = SAMPLINGTIME;
557+
#else // STM32L0
558+
//LowPowerFrequencyMode to enable if clk freq < 2.8Mhz
559+
AdcHandle.Init.SamplingTime = SAMPLINGTIME;
560+
#endif
554561
#else
555562
#ifdef STM32F3xx
556563
AdcHandle.Init.LowPowerAutoWait = DISABLE; /* Auto-delayed conversion feature disabled */
@@ -568,7 +575,9 @@ uint16_t adc_read_value(PinName pin)
568575
AdcChannelConf.Channel = get_adc_channel(pin); /* Specifies the channel to configure into ADC */
569576
if (!IS_ADC_CHANNEL(AdcChannelConf.Channel)) return 0;
570577
AdcChannelConf.Rank = ADC_REGULAR_RANK_1; /* Specifies the rank in the regular group sequencer */
578+
#ifndef STM32L0xx
571579
AdcChannelConf.SamplingTime = SAMPLINGTIME; /* Sampling time value to be set for the selected channel */
580+
#endif
572581
/*##-2- Configure ADC regular channel ######################################*/
573582
if (HAL_ADC_ConfigChannel(&AdcHandle, &AdcChannelConf) != HAL_OK)
574583
{
@@ -679,8 +688,8 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
679688
void pwm_start(PinName pin, uint32_t clock_freq,
680689
uint32_t period, uint32_t value, uint8_t do_init)
681690
{
682-
TIM_HandleTypeDef timHandle;
683-
TIM_OC_InitTypeDef timConfig;
691+
TIM_HandleTypeDef timHandle = {};
692+
TIM_OC_InitTypeDef timConfig = {};
684693
uint32_t timChannel;
685694

686695
/* Compute the prescaler value to have TIM counter clock equal to clock_freq Hz */
@@ -690,7 +699,9 @@ void pwm_start(PinName pin, uint32_t clock_freq,
690699
timHandle.Init.Period = period;
691700
timHandle.Init.ClockDivision = 0;
692701
timHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
702+
#ifndef STM32L0xx
693703
timHandle.Init.RepetitionCounter = 0;
704+
#endif
694705
timHandle.State= HAL_TIM_STATE_RESET;
695706
// TBC: is timHandle.State field should be saved ?
696707

@@ -709,9 +720,11 @@ void pwm_start(PinName pin, uint32_t clock_freq,
709720
timConfig.OCMode = TIM_OCMODE_PWM1;
710721
timConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
711722
timConfig.OCFastMode = TIM_OCFAST_DISABLE;
723+
#ifndef STM32L0xx
712724
timConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
713725
timConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
714726
timConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
727+
#endif
715728
timConfig.Pulse = value;
716729

717730
if (HAL_TIM_PWM_ConfigChannel(&timHandle, &timConfig, timChannel) != HAL_OK)
@@ -720,9 +733,12 @@ void pwm_start(PinName pin, uint32_t clock_freq,
720733
return;
721734
}
722735

736+
#ifndef STM32L0xx
723737
if(STM_PIN_INVERTED(pinmap_function(pin, PinMap_PWM))) {
724738
HAL_TIMEx_PWMN_Start(&timHandle, timChannel);
725-
} else {
739+
} else
740+
#endif
741+
{
726742
HAL_TIM_PWM_Start(&timHandle, timChannel);
727743
}
728744
}
@@ -743,9 +759,12 @@ void pwm_stop(PinName pin)
743759
timChannel = get_pwm_channel(pin);
744760
if (!IS_TIM_CHANNELS(timChannel)) return 0;
745761

762+
#ifndef STM32L0xx
746763
if (STM_PIN_INVERTED(pinmap_function(pin, PinMap_PWM))) {
747764
HAL_TIMEx_PWMN_Stop(&timHandle, timChannel);
748-
} else {
765+
} else
766+
#endif
767+
{
749768
HAL_TIM_PWM_Stop(&timHandle, timChannel);
750769
}
751770

cores/arduino/stm32/clock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void SysTick_Handler(void)
136136
void delayInsideIT(uint32_t delay_us)
137137
{
138138
uint32_t nb_loop;
139-
#ifdef STM32F0xx
139+
#if defined (STM32F0xx) || defined (STM32L0xx)
140140
nb_loop = (((HAL_RCC_GetHCLKFreq() / 1000000)/5)*delay_us)+1; /* uS (divide by 4 because each loop take about 4 cycles including nop +1 is here to avoid delay of 0 */
141141
__asm__ volatile(
142142
"1: " "\n\t"

cores/arduino/stm32/interrupt.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ typedef struct {
9494
* @{
9595
*/
9696
static gpio_irq_conf_str gpio_irq_conf[NB_EXTI] = {
97-
#ifdef STM32F0xx
97+
#if defined (STM32F0xx) || defined (STM32L0xx)
9898
{.pin = GPIO_PIN_0, .irqnb = EXTI0_1_IRQn, .callback = NULL, .mode = GPIO_MODE_IT_RISING, .configured = 0 },
9999
{.pin = GPIO_PIN_1, .irqnb = EXTI0_1_IRQn, .callback = NULL, .mode = GPIO_MODE_IT_RISING, .configured = 0 },
100100
{.pin = GPIO_PIN_2, .irqnb = EXTI2_3_IRQn, .callback = NULL, .mode = GPIO_MODE_IT_RISING, .configured = 0 },
@@ -181,9 +181,13 @@ void stm32_interrupt_enable(GPIO_TypeDef *port, uint16_t pin, void (*callback)(v
181181
//Do it in case the user already defines the IO through the digital io
182182
//interface
183183
pull = port->PUPDR;
184+
#ifdef GPIO_PUPDR_PUPD0
185+
pull &=(GPIO_PUPDR_PUPD0<<(id*2));
186+
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPD0 & (pull>>(id*2)));
187+
#else
184188
pull &=(GPIO_PUPDR_PUPDR0<<(id*2));
185189
GPIO_InitStruct.Pull = (GPIO_PUPDR_PUPDR0 & (pull>>(id*2)));
186-
190+
#endif
187191
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
188192

189193
HAL_GPIO_Init(port, &GPIO_InitStruct);
@@ -229,7 +233,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
229233
}
230234
}
231235

232-
#ifdef STM32F0xx
236+
#if defined (STM32F0xx) || defined (STM32L0xx)
233237
/**
234238
* @brief This function handles external line 0 to 1 interrupt request.
235239
* @param None

cores/arduino/stm32/stm32_def.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@
5050
#ifdef STM32F0xx
5151
#define USART3_IRQn USART3_8_IRQn
5252
#define USART6_IRQn USART3_8_IRQn
53+
#define I2C1_EV_IRQn I2C1_IRQn
5354

5455
#elif defined(STM32F1xx)
5556

5657
#elif defined(STM32F2xx)
5758

5859
#elif defined(STM32F3xx)
5960
#define EXTI2_IRQn EXTI2_TSC_IRQn
60-
6161
#elif defined(STM32F4xx)
6262

6363
#elif defined(STM32F7xx)
6464

6565
#elif defined(STM32L0xx)
66-
66+
#define I2C1_EV_IRQn I2C1_IRQn
67+
#define I2C2_EV_IRQn I2C2_IRQn
6768
#elif defined(STM32L1xx)
6869

6970
#elif defined(STM32L4xx)

cores/arduino/stm32/stm32_def_build.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define CMSIS_STARTUP_FILE "startup_stm32f407xx.s"
3131
#elif defined(STM32F429xx)
3232
#define CMSIS_STARTUP_FILE "startup_stm32f429xx.s"
33+
#elif defined(STM32L053xx)
34+
#define CMSIS_STARTUP_FILE "startup_stm32l053xx.s"
3335
#else
3436
#error UNKNOWN CHIP
3537
#endif

cores/arduino/stm32/stm32_eeprom.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@
7272
#ifdef STM32F0xx
7373
// Flash base address (Bank2, page 256)
7474
#define FLASH_BASE_ADDRESS 0x0803F800
75-
#define FLASH_PAGE_NUMBER 127
7675
#elif defined (STM32F3xx)
7776
#define FLASH_BASE_ADDRESS ((uint32_t)((0x0807FFFF + 1) - FLASH_PAGE_SIZE)) //0x0807F800
78-
#define FLASH_PAGE_NUMBER 255
79-
#else
77+
#elif defined (STM32F4xx)
8078
// Use the last 16 page of the second bank (sector 15)
8179
#define FLASH_BASE_ADDRESS ((uint32_t)(0x0810C000))
8280
#define FLASH_DATA_SECTOR 15
81+
#elif defined (STM32L0xx)
82+
#define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE)) /* 0x08080000 */
8383
#endif
8484

8585
/**
@@ -162,7 +162,7 @@ void set_data_to_flash(void)
162162
uint32_t offset = 0;
163163
uint32_t address = FLASH_BASE_ADDRESS;
164164
uint32_t address_end = FLASH_BASE_ADDRESS + E2END;
165-
#if defined (STM32F0xx) || defined (STM32F3xx)
165+
#if defined (STM32F0xx) || defined (STM32F3xx) || defined (STM32L0xx)
166166
uint32_t pageError = 0;
167167
uint64_t data = 0;
168168

@@ -172,15 +172,27 @@ void set_data_to_flash(void)
172172
EraseInitStruct.NbPages = 1;
173173

174174
if(HAL_FLASH_Unlock() == HAL_OK) {
175+
#ifdef STM32L0xx
176+
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGAERR|\
177+
FLASH_FLAG_SIZERR|FLASH_FLAG_OPTVERR|FLASH_FLAG_RDERR|\
178+
FLASH_FLAG_FWWERR|FLASH_FLAG_NOTZEROERR);
179+
#else
175180
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGERR);
176-
181+
#endif
177182
if(HAL_FLASHEx_Erase(&EraseInitStruct, &pageError) == HAL_OK) {
178183
while(address < address_end) {
184+
#ifdef STM32L0xx
185+
memcpy(&data, tmpEE + offset, sizeof(uint32_t));
186+
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK) {
187+
address += 4;
188+
offset += 4;
189+
#else
179190
data = *((uint64_t*)(((uint8_t*)tmpEE + offset)));
180191

181192
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data) == HAL_OK) {
182193
address += 8;
183194
offset += 8;
195+
#endif
184196
} else {
185197
address = address_end+1;
186198
}

cores/arduino/stm32/timer.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ void timer_enable_clock(TIM_HandleTypeDef *htim)
224224
timer_handles[19] = htim;
225225
}
226226
#endif
227+
#if defined(TIM21_BASE)
228+
if (htim->Instance == TIM21) {
229+
__HAL_RCC_TIM21_CLK_ENABLE();
230+
timer_handles[20] = htim;
231+
}
232+
#endif
233+
#if defined(TIM22_BASE)
234+
if (htim->Instance == TIM22) {
235+
__HAL_RCC_TIM22_CLK_ENABLE();
236+
timer_handles[21] = htim;
237+
}
238+
#endif
227239
}
228240

229241
/**
@@ -324,6 +336,16 @@ void timer_disable_clock(TIM_HandleTypeDef *htim)
324336
__HAL_RCC_TIM20_CLK_DISABLE();
325337
}
326338
#endif
339+
#if defined(TIM21_BASE)
340+
if (htim->Instance == TIM21) {
341+
__HAL_RCC_TIM21_CLK_DISABLE();
342+
}
343+
#endif
344+
#if defined(TIM22_BASE)
345+
if (htim->Instance == TIM22) {
346+
__HAL_RCC_TIM22_CLK_DISABLE();
347+
}
348+
#endif
327349
}
328350

329351
/**
@@ -369,8 +391,9 @@ void TimerHandleInit(stimer_t *obj, uint16_t period, uint16_t prescaler)
369391
handle->Init.CounterMode = TIM_COUNTERMODE_UP;
370392
handle->Init.Period = period;
371393
handle->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
394+
#ifndef STM32L0xx
372395
handle->Init.RepetitionCounter = 0x0000;
373-
396+
#endif
374397
if(HAL_TIM_Base_Init(handle) != HAL_OK){
375398
return;
376399
}
@@ -418,7 +441,7 @@ uint32_t getTimerClkFreq(uint8_t clkSrc)
418441
*/
419442
void TimerPulseInit(stimer_t *obj, uint16_t period, uint16_t pulseWidth, void (*irqHandle)(stimer_t*, uint32_t))
420443
{
421-
TIM_OC_InitTypeDef sConfig;
444+
TIM_OC_InitTypeDef sConfig = {};
422445
TIM_HandleTypeDef *handle = &(obj->handle);
423446

424447
obj->timer = TIMER_SERVO;
@@ -429,18 +452,20 @@ void TimerPulseInit(stimer_t *obj, uint16_t period, uint16_t pulseWidth, void (*
429452
handle->Init.Prescaler = (uint32_t)(getTimerClkFreq(timermap_clkSrc(obj->timer, TimerMap_CONFIG)) / (1000000)) - 1;
430453
handle->Init.ClockDivision = 0;
431454
handle->Init.CounterMode = TIM_COUNTERMODE_UP;
455+
#ifndef STM32L0xx
432456
handle->Init.RepetitionCounter = 0;
433-
457+
#endif
434458
obj->irqHandleOC = irqHandle;
435459

436460
sConfig.OCMode = TIM_OCMODE_TIMING;
437461
sConfig.Pulse = pulseWidth;
438462
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
439-
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
440463
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
464+
#ifndef STM32L0xx
465+
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
441466
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
442467
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
443-
468+
#endif
444469
HAL_NVIC_SetPriority(timermap_irq(obj->timer, TimerMap_CONFIG), 14, 0);
445470
HAL_NVIC_EnableIRQ(timermap_irq(obj->timer, TimerMap_CONFIG));
446471

0 commit comments

Comments
 (0)