Skip to content

Commit dd30f2c

Browse files
authored
Merge pull request #1243 from hathach/g4-nucleo
Add G4 support
2 parents bfb5e32 + d097178 commit dd30f2c

File tree

6 files changed

+61
-47
lines changed

6 files changed

+61
-47
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The stack supports the following MCUs:
5050
- **Renesas:** RX63N, RX65N, RX72N
5151
- **Silabs:** EFM32GG
5252
- **Sony:** CXD56
53-
- **ST:** STM32 series: F0, F1, F2, F3, F4, F7, H7, L0, L1, L4, L4+
53+
- **ST:** STM32 series: F0, F1, F2, F3, F4, F7, H7, G4, L0, L1, L4, L4+
5454
- **TI:** MSP430, MSP432E4, TM4C123
5555
- **ValentyUSB:** eptri
5656

docs/reference/supported.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Supported MCUs
8282
| +-----------------------+--------+------+-----------+-------------------+--------------+
8383
| | H7 || || dwc2 | |
8484
| +-----------------------+--------+------+-----------+-------------------+--------------+
85+
| | G4 |||| stm32_fsdev | |
86+
| +-----------------------+--------+------+-----------+-------------------+--------------+
8587
| | L0, L1 |||| stm32_fsdev | |
8688
| +----+------------------+--------+------+-----------+-------------------+--------------+
8789
| | L4 | 4x2, 4x3 |||| stm32_fsdev | |
@@ -352,6 +354,17 @@ F7
352354
- `STM32 F767zi Nucleo <https://www.st.com/en/evaluation-tools/nucleo-f767zi.html>`__
353355
- `STM32 F769i Discovery <https://www.st.com/en/evaluation-tools/32f769idiscovery.html>`__
354356

357+
H7
358+
^^
359+
- `STM32 H743zi Nucleo <https://www.st.com/en/evaluation-tools/nucleo-h743zi.html>`__
360+
- `STM32 H743i Evaluation <https://www.st.com/en/evaluation-tools/stm32h743i-eval.html>`__
361+
- `STM32 H745i Discovery <https://www.st.com/en/evaluation-tools/stm32h745i-disco.html>`__
362+
- `Waveshare OpenH743I-C <https://www.waveshare.com/openh743i-c-standard.htm>`__
363+
364+
G4
365+
^^
366+
- `STM32 G474RE Nucleo <https://www.st.com/en/evaluation-tools/nucleo-g474re.html>`__
367+
355368
L0
356369
^^
357370
- `STM32 L035c8 Discovery <https://www.st.com/en/evaluation-tools/32l0538discovery.html>`__
@@ -362,13 +375,6 @@ L4
362375
- `STM32 L4P5zg Nucleo <https://www.st.com/en/evaluation-tools/nucleo-l4p5zg.html>`__
363376
- `STM32 L4R5zi Nucleo <https://www.st.com/en/evaluation-tools/nucleo-l4r5zi.html>`__
364377

365-
H7
366-
^^
367-
- `STM32 H743zi Nucleo <https://www.st.com/en/evaluation-tools/nucleo-h743zi.html>`__
368-
- `STM32 H743i Evaluation <https://www.st.com/en/evaluation-tools/stm32h743i-eval.html>`__
369-
- `STM32 H745i Discovery <https://www.st.com/en/evaluation-tools/stm32h745i-disco.html>`__
370-
- `Waveshare OpenH743I-C <https://www.waveshare.com/openh743i-c-standard.htm>`__
371-
372378
TI
373379
--
374380

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# Install python3 HID package https://pypi.org/project/hid/
22
import hid
33

4-
USB_VID = 0xcafe
4+
# default is TinyUSB (0xcafe), Adafruit (0x239a), RaspberryPi (0x2e8a), Espressif (0x303a) VID
5+
USB_VID = (0xcafe, 0x239a, 0x2e8a, 0x303a)
56

6-
print("Openning HID device with VID = 0x%X" % USB_VID)
7+
print("VID list: " + ", ".join('%02x' % v for v in USB_VID))
78

8-
for dict in hid.enumerate(USB_VID):
9-
print(dict)
10-
dev = hid.Device(dict['vendor_id'], dict['product_id'])
11-
if dev:
12-
while True:
13-
# Get input from console and encode to UTF8 for array of chars.
14-
# hid generic inout is single report therefore by HIDAPI requirement
15-
# it must be preceeded with 0x00 as dummy reportID
16-
str_out = b'\x00'
17-
str_out += input("Send text to HID Device : ").encode('utf-8')
18-
dev.write(str_out)
19-
str_in = dev.read(64)
20-
print("Received from HID Device:", str_in, '\n')
9+
for vid in USB_VID:
10+
for dict in hid.enumerate(vid):
11+
print(dict)
12+
dev = hid.Device(dict['vendor_id'], dict['product_id'])
13+
if dev:
14+
while True:
15+
# Get input from console and encode to UTF8 for array of chars.
16+
# hid generic inout is single report therefore by HIDAPI requirement
17+
# it must be preceeded with 0x00 as dummy reportID
18+
str_out = b'\x00'
19+
str_out += input("Send text to HID Device : ").encode('utf-8')
20+
dev.write(str_out)
21+
str_in = dev.read(64)
22+
print("Received from HID Device:", str_in, '\n')

hw/bsp/stm32g4/boards/stm32g474nucleo/board.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#endif
3333

3434
// G474RE Nucleo does not has usb connection. We need to manually connect
35-
// - PA11 for D+, CN10.14
36-
// - PA12 for D-, CN10.12
35+
// - PA12 for D+, CN10.12
36+
// - PA11 for D-, CN10.14
3737

3838
// LED
3939
#define LED_PORT GPIOA
@@ -61,32 +61,36 @@ static inline void board_clock_init(void)
6161
{
6262
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
6363
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
64+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
6465

6566
// Configure the main internal regulator output voltage
6667
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
6768

6869
// Initializes the CPU, AHB and APB busses clocks
69-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
70-
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
71-
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
72-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
73-
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
74-
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
75-
RCC_OscInitStruct.PLL.PLLN = 85;
76-
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
77-
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
78-
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
70+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSE;
71+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
72+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
73+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
74+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
75+
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
76+
RCC_OscInitStruct.PLL.PLLN = 50;
77+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
78+
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
79+
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
7980
HAL_RCC_OscConfig(&RCC_OscInitStruct);
8081

8182
// Initializes the CPU, AHB and APB busses clocks
82-
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
83-
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
84-
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
83+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
84+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
85+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
8586
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
8687
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
87-
8888
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8);
8989

90+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
91+
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
92+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) ;
93+
9094
#if 0 // TODO need to check if USB clock is enabled
9195
/* Enable HSI48 */
9296
memset(&RCC_OscInitStruct, 0, sizeof(RCC_OscInitStruct));

hw/bsp/stm32g4/boards/stm32g474nucleo/board.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
CFLAGS += -DSTM32G474xx
1+
CFLAGS += \
2+
-DSTM32G474xx \
3+
-DHSE_VALUE=24000000
24

35
LD_FILE = $(BOARD_PATH)/STM32G474RETx_FLASH.ld
46

hw/bsp/stm32g4/family.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ void board_init(void)
118118

119119
// USB Pins TODO double check USB clock and pin setup
120120
// Configure USB DM and DP pins. This is optional, and maintained only for user guidance.
121-
// GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
122-
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
123-
// GPIO_InitStruct.Pull = GPIO_NOPULL;
124-
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
125-
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
126-
//
127-
// __HAL_RCC_USB_CLK_ENABLE();
121+
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
122+
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
123+
GPIO_InitStruct.Pull = GPIO_NOPULL;
124+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
125+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
126+
127+
__HAL_RCC_USB_CLK_ENABLE();
128128

129129
board_vbus_sense_init();
130130
}

0 commit comments

Comments
 (0)