Skip to content

Commit ab0da3c

Browse files
committed
group stm32l0
1 parent 3944f1c commit ab0da3c

File tree

10 files changed

+129
-555
lines changed

10 files changed

+129
-555
lines changed

.github/workflows/build_arm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- 'stm32f7'
5151
- 'stm32g4 stm32wb'
5252
- 'stm32h7'
53-
- 'stm32l4'
53+
- 'stm32l0 stm32l4'
5454
- 'tm4c123 xmc4000'
5555
steps:
5656
- name: Setup Python

hw/bsp/stm32l0/boards/stm32l052dap52/board.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS += -DSTM32L052xx -DCFG_EXAMPLE_VIDEO_READONLY
1+
CFLAGS += \
2+
-DSTM32L052xx
23

34
LD_FILE = $(BOARD_PATH)/STM32L052K8Ux_FLASH.ld
45

Lines changed: 24 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2019 Ha Thach (tinyusb.org)
4+
* Copyright (c) 2020, Ha Thach (tinyusb.org)
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -24,45 +24,35 @@
2424
* This file is part of the TinyUSB stack.
2525
*/
2626

27-
#include "../board.h"
28-
#include "stm32l0xx_hal.h"
27+
#ifndef BOARD_H_
28+
#define BOARD_H_
2929

30-
//--------------------------------------------------------------------+
31-
// Forward USB interrupt events to TinyUSB IRQ Handler
32-
//--------------------------------------------------------------------+
33-
void USB_IRQHandler(void)
34-
{
35-
tud_int_handler(0);
36-
}
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
3733

38-
//--------------------------------------------------------------------+
39-
// MACRO TYPEDEF CONSTANT ENUM
40-
//--------------------------------------------------------------------+
34+
// LED
4135
#define LED_PORT GPIOA
4236
#define LED_PIN GPIO_PIN_5
4337
#define LED_STATE_ON 1
4438

39+
// Button
4540
#define BUTTON_PORT GPIOA
4641
#define BUTTON_PIN GPIO_PIN_0
4742
#define BUTTON_STATE_ACTIVE 1
4843

49-
/**
50-
* @brief System Clock Configuration
51-
* The system Clock is configured as follow:
52-
* HSI48 used as USB clock source
53-
* - System Clock source = HSI
54-
* - HSI Frequency(Hz) = 16000000
55-
* - SYSCLK(Hz) = 16000000
56-
* - HCLK(Hz) = 16000000
57-
* - AHB Prescaler = 1
58-
* - APB1 Prescaler = 1
59-
* - APB2 Prescaler = 1
60-
* - Flash Latency(WS) = 0
61-
* - Main regulator output voltage = Scale1 mode
62-
* @param None
63-
* @retval None
64-
*/
65-
static void SystemClock_Config(void)
44+
// UART
45+
//#define UART_DEV USART2
46+
//#define UART_CLK_EN __HAL_RCC_USART2_CLK_ENABLE
47+
//#define UART_GPIO_PORT GPIOA
48+
//#define UART_GPIO_AF GPIO_AF4_USART2
49+
//#define UART_TX_PIN GPIO_PIN_2
50+
//#define UART_RX_PIN GPIO_PIN_3
51+
52+
//--------------------------------------------------------------------+
53+
// RCC Clock
54+
//--------------------------------------------------------------------+
55+
static inline void board_stm32l0_clock_init(void)
6656
{
6757
RCC_ClkInitTypeDef RCC_ClkInitStruct;
6858
RCC_OscInitTypeDef RCC_OscInitStruct;
@@ -108,99 +98,12 @@ static void SystemClock_Config(void)
10898
HAL_RCCEx_CRSConfig (&RCC_CRSInitStruct);
10999
}
110100

111-
void board_init(void)
112-
{
113-
SystemClock_Config();
114-
115-
#if CFG_TUSB_OS == OPT_OS_NONE
116-
// 1ms tick timer
117-
SysTick_Config(SystemCoreClock / 1000);
118-
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
119-
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
120-
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
121-
#endif
122-
123-
GPIO_InitTypeDef GPIO_InitStruct;
124-
125-
// LED
126-
__HAL_RCC_GPIOA_CLK_ENABLE();
127-
GPIO_InitStruct.Pin = LED_PIN;
128-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
129-
GPIO_InitStruct.Pull = GPIO_PULLUP;
130-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
131-
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
132-
133-
board_led_write(false);
134-
135-
// Button
136-
//__HAL_RCC_GPIOA_CLK_ENABLE();
137-
GPIO_InitStruct.Pin = BUTTON_PIN;
138-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
139-
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
140-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
141-
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
142-
143-
// USB
144-
/* Configure DM DP Pins */
145-
__HAL_RCC_GPIOA_CLK_ENABLE();
146-
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
147-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
148-
GPIO_InitStruct.Pull = GPIO_NOPULL;
149-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
150-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
151-
152-
/* Enable USB FS Clock */
153-
__HAL_RCC_USB_CLK_ENABLE();
154-
}
155-
156-
//--------------------------------------------------------------------+
157-
// Board porting API
158-
//--------------------------------------------------------------------+
159-
160-
void board_led_write(bool state)
161-
{
162-
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
163-
}
164-
165-
uint32_t board_button_read(void)
166-
{
167-
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
168-
}
169-
170-
int board_uart_read(uint8_t* buf, int len)
171-
{
172-
(void) buf; (void) len;
173-
return 0;
174-
}
175-
176-
int board_uart_write(void const * buf, int len)
101+
static inline void board_vbus_sense_init(void)
177102
{
178-
(void) buf; (void) len;
179-
return 0;
180103
}
181104

182-
#if CFG_TUSB_OS == OPT_OS_NONE
183-
volatile uint32_t system_ticks = 0;
184-
void SysTick_Handler (void)
185-
{
186-
HAL_IncTick();
187-
system_ticks++;
188-
}
189-
190-
uint32_t board_millis(void)
191-
{
192-
return system_ticks;
193-
}
105+
#ifdef __cplusplus
106+
}
194107
#endif
195108

196-
void HardFault_Handler (void)
197-
{
198-
asm("bkpt");
199-
}
200-
201-
// Required by __libc_init_array in startup code if we are compiling using
202-
// -nostdlib/-nostartfiles.
203-
void _init(void)
204-
{
205-
206-
}
109+
#endif /* BOARD_H_ */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CFLAGS += \
2+
-DSTM32L053xx
3+
4+
# All source paths should be relative to the top level.
5+
LD_FILE = $(BOARD_PATH)/STM32L053C8Tx_FLASH.ld
6+
7+
SRC_S += \
8+
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32l053xx.s
9+
10+
# For flash-jlink target
11+
JLINK_DEVICE = STM32L053R8
12+
13+
# flash target using on-board stlink
14+
flash: flash-stlink

hw/bsp/stm32l0/family.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,14 @@ void USB_IRQHandler(void)
3939
//--------------------------------------------------------------------+
4040
// MACRO TYPEDEF CONSTANT ENUM
4141
//--------------------------------------------------------------------+
42+
#ifdef UART_DEV
4243
UART_HandleTypeDef UartHandle;
44+
#endif
4345

4446
void board_init(void)
4547
{
4648
board_stm32l0_clock_init();
4749

48-
// Enable All GPIOs clocks
49-
__HAL_RCC_GPIOA_CLK_ENABLE();
50-
__HAL_RCC_GPIOB_CLK_ENABLE();
51-
__HAL_RCC_GPIOC_CLK_ENABLE();
52-
__HAL_RCC_GPIOD_CLK_ENABLE();
53-
54-
// Enable UART Clock
55-
UART_CLK_EN();
56-
5750
#if CFG_TUSB_OS == OPT_OS_NONE
5851
// 1ms tick timer
5952
SysTick_Config(SystemCoreClock / 1000);
@@ -66,6 +59,12 @@ void board_init(void)
6659
NVIC_SetPriority(USB_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
6760
#endif
6861

62+
// Enable All GPIOs clocks
63+
__HAL_RCC_GPIOA_CLK_ENABLE();
64+
__HAL_RCC_GPIOB_CLK_ENABLE();
65+
__HAL_RCC_GPIOC_CLK_ENABLE();
66+
__HAL_RCC_GPIOD_CLK_ENABLE();
67+
6968
// LED
7069
GPIO_InitTypeDef GPIO_InitStruct;
7170
GPIO_InitStruct.Pin = LED_PIN;
@@ -74,14 +73,19 @@ void board_init(void)
7473
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
7574
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
7675

76+
board_led_write(false);
77+
7778
// Button
7879
GPIO_InitStruct.Pin = BUTTON_PIN;
7980
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
8081
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
8182
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
8283
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
8384

84-
// Uart
85+
#ifdef UART_DEV
86+
// Enable UART Clock
87+
UART_CLK_EN();
88+
8589
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
8690
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
8791
GPIO_InitStruct.Pull = GPIO_PULLUP;
@@ -98,13 +102,14 @@ void board_init(void)
98102
UartHandle.Init.Mode = UART_MODE_TX_RX;
99103
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
100104
HAL_UART_Init(&UartHandle);
105+
#endif
101106

102107
// USB Pins
103108
// Configure USB DM and DP pins. This is optional, and maintained only for user guidance.
104109
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
105110
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
106111
GPIO_InitStruct.Pull = GPIO_NOPULL;
107-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
112+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
108113
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
109114

110115
// USB Clock enable
@@ -133,8 +138,13 @@ int board_uart_read(uint8_t* buf, int len)
133138

134139
int board_uart_write(void const * buf, int len)
135140
{
141+
#ifdef UART_DEV
136142
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff);
137143
return len;
144+
#else
145+
(void) buf; (void) len;
146+
return 0;
147+
#endif
138148
}
139149

140150
#if CFG_TUSB_OS == OPT_OS_NONE

hw/bsp/stm32l0/family.mk

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
ST_FAMILY = l0
2-
DEPS_SUBMODULES += lib/CMSIS_5 hw/mcu/st/cmsis_device_$(ST_FAMILY) hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
2+
DEPS_SUBMODULES += \
3+
lib/CMSIS_5 \
4+
hw/mcu/st/cmsis_device_$(ST_FAMILY) \
5+
hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
36

47
ST_CMSIS = hw/mcu/st/cmsis_device_$(ST_FAMILY)
58
ST_HAL_DRIVER = hw/mcu/st/stm32$(ST_FAMILY)xx_hal_driver
@@ -17,8 +20,12 @@ CFLAGS += \
1720
-DCFG_EXAMPLE_VIDEO_READONLY \
1821
-DCFG_TUSB_MCU=OPT_MCU_STM32L0
1922

20-
# suppress warning caused by vendor mcu driver
21-
CFLAGS += -Wno-error=unused-parameter -Wno-error=redundant-decls -Wno-error=cast-align -Wno-error=maybe-uninitialized
23+
# mcu driver cause following warnings
24+
CFLAGS += \
25+
-Wno-error=unused-parameter \
26+
-Wno-error=redundant-decls \
27+
-Wno-error=cast-align \
28+
-Wno-error=maybe-uninitialized
2229

2330
SRC_C += \
2431
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c \

0 commit comments

Comments
 (0)