Skip to content

Commit 6c06fd7

Browse files
committed
Add Phoque1 and Phoque2 brushless driver variants
1 parent 36a8f85 commit 6c06fd7

6 files changed

Lines changed: 873 additions & 0 deletions

File tree

‎variants/STM32G4xx/G431C(6-8-B)U_G441CBU/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_library(variant_bin STATIC EXCLUDE_FROM_ALL
2323
PeripheralPins.c
2424
PeripheralPins_B_G431B_ESC1.c
2525
variant_B_G431B_ESC1.cpp
26+
variant_PHOQUE2.cpp
2627
variant_generic.cpp
2728
)
2829
target_link_libraries(variant_bin PUBLIC variant_usage)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2020, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#if defined(ARDUINO_PHOQUE2)
14+
#include "pins_arduino.h"
15+
#include "pinmap.h"
16+
#include <stm32g4xx_hal.h>
17+
18+
// Digital PinName array
19+
extern "C" const PinName digitalPin[] = {
20+
PA_0, // D0/A0
21+
PA_1, // D1/A1
22+
PA_2, // D2/A2
23+
PA_3, // D3/A3
24+
PA_4, // D4/A4
25+
PA_5, // D5/A5
26+
PA_6, // D6/A6
27+
PA_7, // D7/A7
28+
PA_8, // D8
29+
PA_9, // D9
30+
PA_10, // D10
31+
PA_11, // D11
32+
PA_12, // D12
33+
PA_13, // D13
34+
PA_14, // D14
35+
PA_15, // D15
36+
PB_0, // D16/A8
37+
PB_1, // D17/A9
38+
PB_2, // D18/A10
39+
PB_3, // D19
40+
PB_4, // D20
41+
PB_5, // D21
42+
PB_6, // D22
43+
PB_7, // D23
44+
PB_8, // D24
45+
PB_9, // D25
46+
PB_10, // D26
47+
PB_11, // D27/A11
48+
PB_12, // D28/A12
49+
PB_13, // D29
50+
PB_14, // D30/A13
51+
PB_15, // D31/A14
52+
PC_4, // D32/A15
53+
PC_6, // D33
54+
PC_10, // D34
55+
PC_11, // D35
56+
PC_13, // D36
57+
PC_14, // D37
58+
PC_15, // D38
59+
PF_0, // D39/A16
60+
PF_1, // D40/A17
61+
PG_10 // D41
62+
};
63+
64+
// Analog (Ax) pin number array
65+
extern "C" const uint32_t analogInputPin[] = {
66+
0, // A0, PA0
67+
1, // A1, PA1
68+
2, // A2, PA2
69+
3, // A3, PA3
70+
4, // A4, PA4
71+
5, // A5, PA5
72+
6, // A6, PA6
73+
7, // A7, PA7
74+
16, // A8, PB0
75+
17, // A9, PB1
76+
18, // A10, PB2
77+
27, // A11, PB11
78+
28, // A12, PB12
79+
30, // A13, PB14
80+
31, // A14, PB15
81+
32, // A15, PC4
82+
39, // A16, PF0
83+
40 // A17, PF1
84+
};
85+
86+
__weak void SystemClock_Config(void)
87+
{
88+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
89+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
90+
91+
/** Configure the main internal regulator output voltage
92+
*/
93+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST);
94+
95+
/** Initializes the RCC Oscillators according to the specified parameters
96+
* in the RCC_OscInitTypeDef structure.
97+
*/
98+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
99+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
100+
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
101+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
102+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
103+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
104+
#if 0
105+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
106+
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4;
107+
#else
108+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
109+
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2;
110+
#endif
111+
RCC_OscInitStruct.PLL.PLLN = 85;
112+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
113+
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
114+
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
115+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
116+
{
117+
Error_Handler();
118+
}
119+
120+
/** Initializes the CPU, AHB and APB buses clocks
121+
*/
122+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
123+
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
124+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
125+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
126+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
127+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
128+
129+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
130+
{
131+
Error_Handler();
132+
}
133+
134+
#if 1
135+
RCC_PeriphCLKInitTypeDef PeriphClkInit;
136+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN | RCC_PERIPHCLK_USB | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1;
137+
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
138+
PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL; //CAN will run at 170MHz (PLLQ)
139+
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; //I2C1 at 170MHz
140+
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
141+
PeriphClkInit.RngClockSelection = RCC_RNGCLKSOURCE_HSI48;
142+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
143+
{
144+
Error_Handler();
145+
}
146+
//__HAL_RCC_RNG_CLK_ENABLE();
147+
#endif
148+
HAL_SYSCFG_EnableVREFBUF();
149+
}
150+
151+
#endif /* ARDUINO_GENERIC_* */
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
#pragma once
2+
3+
/*----------------------------------------------------------------------------
4+
* STM32 pins number
5+
*----------------------------------------------------------------------------*/
6+
#define PA0 PIN_A0
7+
#define PA1 PIN_A1
8+
#define PA2 PIN_A2
9+
#define PA3 PIN_A3
10+
#define PA4 PIN_A4
11+
#define PA5 PIN_A5
12+
#define PA6 PIN_A6
13+
#define PA7 PIN_A7
14+
#define PA8 8
15+
#define PA9 9
16+
#define PA10 10
17+
#define PA11 11
18+
#define PA12 12
19+
#define PA13 13
20+
#define PA14 14
21+
#define PA15 15
22+
#define PB0 PIN_A8
23+
#define PB1 PIN_A9
24+
#define PB2 PIN_A10
25+
#define PB3 19
26+
#define PB4 20
27+
#define PB5 21
28+
#define PB6 22
29+
#define PB7 23
30+
#define PB8 24
31+
#define PB9 25
32+
#define PB10 26
33+
#define PB11 PIN_A11
34+
#define PB12 PIN_A12
35+
#define PB13 29
36+
#define PB14 PIN_A13
37+
#define PB15 PIN_A14
38+
#define PC4 PIN_A15
39+
#define PC6 33
40+
#define PC10 34
41+
#define PC11 35
42+
#define PC13 36
43+
#define PC14 37
44+
#define PC15 38
45+
#define PF0 PIN_A16
46+
#define PF1 PIN_A17
47+
#define PG10 41
48+
49+
// Alternate pins number
50+
#define PA0_ALT1 (PA0 | ALT1)
51+
#define PA1_ALT1 (PA1 | ALT1)
52+
#define PA2_ALT1 (PA2 | ALT1)
53+
#define PA3_ALT1 (PA3 | ALT1)
54+
#define PA4_ALT1 (PA4 | ALT1)
55+
#define PA6_ALT1 (PA6 | ALT1)
56+
#define PA7_ALT1 (PA7 | ALT1)
57+
#define PA7_ALT2 (PA7 | ALT2)
58+
#define PA7_ALT3 (PA7 | ALT3)
59+
#define PA9_ALT1 (PA9 | ALT1)
60+
#define PA10_ALT1 (PA10 | ALT1)
61+
#define PA11_ALT1 (PA11 | ALT1)
62+
#define PA11_ALT2 (PA11 | ALT2)
63+
#define PA12_ALT1 (PA12 | ALT1)
64+
#define PA12_ALT2 (PA12 | ALT2)
65+
#define PA13_ALT1 (PA13 | ALT1)
66+
#define PA15_ALT1 (PA15 | ALT1)
67+
#define PB0_ALT1 (PB0 | ALT1)
68+
#define PB0_ALT2 (PB0 | ALT2)
69+
#define PB1_ALT1 (PB1 | ALT1)
70+
#define PB1_ALT2 (PB1 | ALT2)
71+
#define PB3_ALT1 (PB3 | ALT1)
72+
#define PB4_ALT1 (PB4 | ALT1)
73+
#define PB4_ALT2 (PB4 | ALT2)
74+
#define PB5_ALT1 (PB5 | ALT1)
75+
#define PB5_ALT2 (PB5 | ALT2)
76+
#define PB6_ALT1 (PB6 | ALT1)
77+
#define PB6_ALT2 (PB6 | ALT2)
78+
#define PB7_ALT1 (PB7 | ALT1)
79+
#define PB7_ALT2 (PB7 | ALT2)
80+
#define PB8_ALT1 (PB8 | ALT1)
81+
#define PB8_ALT2 (PB8 | ALT2)
82+
#define PB9_ALT1 (PB9 | ALT1)
83+
#define PB9_ALT2 (PB9 | ALT2)
84+
#define PB9_ALT3 (PB9 | ALT3)
85+
#define PB11_ALT1 (PB11 | ALT1)
86+
#define PB13_ALT1 (PB13 | ALT1)
87+
#define PB14_ALT1 (PB14 | ALT1)
88+
#define PB15_ALT1 (PB15 | ALT1)
89+
#define PB15_ALT2 (PB15 | ALT2)
90+
#define PC6_ALT1 (PC6 | ALT1)
91+
#define PC10_ALT1 (PC10 | ALT1)
92+
#define PC11_ALT1 (PC11 | ALT1)
93+
#define PC13_ALT1 (PC13 | ALT1)
94+
95+
#define NUM_DIGITAL_PINS 42
96+
#define NUM_ANALOG_INPUTS 18
97+
98+
99+
100+
/* Alias */
101+
#define A_PHASE_UL PB15
102+
#define A_PHASE_UH PA10
103+
#define A_PHASE_VL PB14
104+
#define A_PHASE_VH PA9
105+
#define A_PHASE_WL PB13
106+
#define A_PHASE_WH PA8
107+
108+
#define PIN_SS_DRIVER PC14 //Gate driver chip select
109+
#define PIN_NFAULT PC15 //Gate driver fault pin
110+
111+
#define A_VBUS PB0 //Pin to sense supply voltage, connected to COMP4
112+
#define BRAKE_RESISTOR PB1 //Brake resistor control, also connected to output of COMP4
113+
#define BRAKE_AF 3 //Alternate function 8
114+
#define BRAKE_DAC DAC3 //DAC3
115+
#define BRAKE_DAC_CHAN DAC_CHANNEL_2 //Channel 2
116+
#define BRAKE_COMP COMP4 //Comparator 4
117+
#define BRAKE_COMP_PLUS COMP_INPUT_PLUS_IO1
118+
#define BRAKE_COMP_MINUS COMP_INPUT_MINUS_DAC1_CH2
119+
120+
#define VBUS_MUL_FACTOR 23 //Multiply the adc voltage read by this value to get the supply voltage
121+
122+
//BEMF inputs are connected to comparators with a 10k resistor to phase, 1k to 3.3v and 1k to gnd, so it's offset slightly above ground
123+
124+
#define A_CURRU PA2 //Current sense connected to phase U
125+
#define A_BEMFU PA0 //BEMF connected to comparator 3 for phase U
126+
127+
#define A_CURRV PA7 //Current sense connected to phase V
128+
#define A_BEMFV PA1 //BEMF connected to comparator 4 for phase V
129+
130+
#define A_CURRW PC4 //Current sense connected to phase W
131+
#define A_BEMFW PA3 //BEMF connected to comparator 1 for phase W
132+
133+
#define A_POTENTIOMETER PB2
134+
#define A_TEMPERATURE PB12
135+
136+
//Voltage divider based on CMFA104J4250HANT and 100k resistor
137+
#define NTC_B_CONSTANT 4250 //B = ln(R/R0)/(1/T-1/T0)
138+
#define NTC_T0 (273.15f+25)//Kelvin
139+
#ifndef NTC_DIVIDER_BALANCE
140+
#define NTC_DIVIDER_BALANCE (22.f/100.f) //R1 (value of the other resistance in the voltage divider) over R0 (resistance of NTC at T0)
141+
#endif
142+
143+
#define CAN_RX PB8
144+
#define CAN_TX PB9
145+
#define CAN_PWR PC13 //Pin must be high to turn on CAN transceiver
146+
147+
#define SWDIO PA13
148+
#define SWCLK PA14
149+
150+
#define ENCODER_A PA6 //TIM3_CH1 @ J5
151+
#define ENCODER_B PA4 //TIM3_CH2 @ J5
152+
#define ENCODER_Z PB3 //TIM3_ETR @ J5
153+
154+
// On-board LED pin number
155+
#ifndef LED_BUILTIN
156+
#define LED_BUILTIN PB6 //Drive low to turn on
157+
#endif
158+
159+
//Magnetic angle sensor gets dedicated SPI
160+
#define PIN_MISO_MAG_ANGLE PC11 //SPI3_MISO
161+
#define PIN_CLK_MAG_ANGLE PC10 //SPI3_CLK
162+
#define PIN_SS_MAG_ANGLE PC6 //GPIO
163+
/**
164+
* Not actually connected to MOSI, but Arduino needs this since it doesn't expect RX-only SPI
165+
* Call pinmap_pinout(digitalPinToPinName(PIN_SPI_MOSI), PinMap_SPI_MOSI); to reset the pin to the other SPI if needed
166+
*/
167+
168+
#define PIN_MOSI_MAG_ANGLE PB5_ALT1
169+
170+
// SPI definitions
171+
#ifndef PIN_SPI_SS
172+
#define PIN_SPI_SS PNUM_NOT_DEFINED
173+
#endif
174+
#ifndef PIN_SPI_SS1
175+
#define PIN_SPI_SS1 PNUM_NOT_DEFINED
176+
#endif
177+
#ifndef PIN_SPI_SS2
178+
#define PIN_SPI_SS2 PNUM_NOT_DEFINED
179+
#endif
180+
#ifndef PIN_SPI_SS3
181+
#define PIN_SPI_SS3 PNUM_NOT_DEFINED
182+
#endif
183+
#ifndef PIN_SPI_MOSI
184+
#define PIN_SPI_MOSI PB5 //SPI1_MOSI @ J6
185+
#endif
186+
#ifndef PIN_SPI_MISO
187+
#define PIN_SPI_MISO PB4 //SPI1_MISO @ J6
188+
#endif
189+
#ifndef PIN_SPI_SCK
190+
#define PIN_SPI_SCK PA5 //SPI1_SCK @ J6
191+
#endif
192+
193+
//Qwiic-standard I2C on J1
194+
// I2C definitions
195+
#ifndef PIN_WIRE_SDA
196+
#define PIN_WIRE_SDA PB7
197+
#endif
198+
#ifndef PIN_WIRE_SCL
199+
#define PIN_WIRE_SCL PA15
200+
#endif
201+
202+
// Timer Definitions
203+
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
204+
#ifndef TIMER_TONE
205+
#define TIMER_TONE TIM6
206+
#endif
207+
#ifndef TIMER_SERVO
208+
#define TIMER_SERVO TIM7
209+
#endif
210+
211+
// UART Definitions
212+
#define SERIAL_UART_INSTANCE 0
213+
214+
//LPUART1 on J7
215+
// Default pin used for 'Serial' instance (ex: ST-Link)
216+
// Mandatory for Firmata
217+
#ifndef PIN_SERIAL_RX
218+
#define PIN_SERIAL_RX PB10
219+
#endif
220+
#ifndef PIN_SERIAL_TX
221+
#define PIN_SERIAL_TX PB11
222+
#endif
223+
224+
/* HAL configuration */
225+
#define HSE_VALUE (8000000UL)
226+
227+
/* Extra HAL modules */
228+
#if !defined(HAL_DAC_MODULE_DISABLED)
229+
#define HAL_DAC_MODULE_ENABLED
230+
#endif
231+
#if !defined(HAL_FDCAN_MODULE_DISABLED)
232+
#define HAL_FDCAN_MODULE_ENABLED
233+
#endif

0 commit comments

Comments
 (0)