EFeru / hoverboard-firmware-hack-FOC

With Field Oriented Control (FOC)
GNU General Public License v3.0
1.05k stars 876 forks source link

A new Layout board with GD32F103rct6 #479

Closed hiliving closed 2 months ago

hiliving commented 2 months ago

Variant

USART

Control type

Commutation

Control mode

Speed

Description

This is a new Layout of Gen1, yet the pins are somewhat different.I have marked all the Pins, but I don't know how to modify the Gen1 source code to compile the firmware. Can you give me some guidance? Which codes need to be modified? Thx ,and Extremely grateful . gd32gen1

Candas1 commented 2 months ago

Hi,

What is the difference compared to the pins in this file? https://github.com/EFeru/hoverboard-firmware-hack-FOC/blob/main/Inc%2Fdefines.h

AILIFE4798 commented 2 months ago

@Candas1 the motor pins are same and that's about it(because the hardware timer have to use those) All the serial, adc are different as you can see in picture And those need pinmodeAF I assume and the adc need adc channel, which is not configureable This board uses uart2,uart3,uart4, which is different from the generic taotao technology gen1

Candas1 commented 2 months ago

This might help you understand what pins are used. Motor,Hall,latch,button,buzzer pins should be easy to remap. You could already get sinusoidal mode to work. Don't use any other mode if you are not sure or if you don't have a Power Supply with overcurrent protection.

ADC channels have to be changed here based on the datasheet.

AILIFE4798 commented 2 months ago
Name Pin
Board Variant 0
Alternate Mapping
Board Variant 1
new GD32 board Comment
SWCLK PA14 Used for programming
SWDIO PA13 Used for programming
TX/ADC1/PWM PA2 PB6 Left sensor cable
RX/ADC2/PWM/PPM/IBUS PA3 pb7 Left sensor cable
TX/SCL/PWM PB10 Right sensor cable
RX/SDA/PWM/PPM/IBUS PB11 Right sensor cable
LED PB2 Missing on some of the boards
BUZZER PA4 PC13 PB9 Used for diagnostic beeps
Missing on some of the boards
HALL LEFT U PB5 PA2
HALL LEFT V PB6 PA1
HALL LEFT W PB7 PA0
HALL RIGHT U PC10 PB5
HALL RIGHT V PC11 PB4
HALL RIGHT W PC12 PB3
PHASE LEFT U HIGH PC6
PHASE LEFT U LOW PA7
PHASE LEFT V HIGH PC7
PHASE LEFT V LOW PB0
PHASE LEFT W HIGH PC8
PHASE LEFT W LOW PB1
PHASE RIGHT U HIGH PA8
PHASE RIGHT U LOW PB13
PHASE RIGHT V HIGH PA9
PHASE RIGHT V LOW PB14
PHASE RIGHT W HIGH PA10
PHASE RIGHT W LOW PB15
LEFT_DC_CUR PC0 PC3 Used to measure Left motor DC current with a 3.5mΩ or 2x7mΩ shunts
Missing on some of the boards, so no dc current limitation
LEFT_U_CUR PA0 PA3 Used to measure phase current for FOC through low-side Mosfet RDSon as shunt resistor
LEFT_V_CUR PC3 PA4 Used to measure phase current for FOC through low-side Mosfet RDSon as shunt resistor
RIGHT_DC_CUR PC1 PA5 Used to measure Right motor DC current with a 3.5mΩ or 2x7mΩ shunts
Missing on some of the boards, so no dc current limitation
RIGHT_U_CUR PC4 PC5 Used to measure phase current for FOC through low-side Mosfet RDSon as shunt resistor
RIGHT_V_CUR PC5 PC4 Used to measure phase current for FOC through low-side Mosfet RDSon as shunt resistor
DCLINK PC2 PA1 PC2 Used to measure Battery voltage with adc through a voltage divider
OFF PA5 PC15 PA11 Used to maintain the latch on, released to power off
BUTTON PA1 PB9 PC9 To power on/off
To trigger auto-calibration
To set current and speed limits on the go
To change cable length on transpotter
CHARGER PA12 PA11 PC15 Not used in the firmware at the moment
Emergency shutdown left PA6 hardware short circuit protection pin for bldc timer
Emergency shutdown right PB12 hardware short circuit protection pin for bldc timer
remote tx PC10 used to connect bluetooth module
remote rx PC11 used to connect bluetooth module
AILIFE4798 commented 2 months ago

the problem is after changing config according to table it still does not work

Candas1 commented 2 months ago

What doesn't work?

AILIFE4798 commented 2 months ago

"When I connect this Hall cable(the left one with pa2~0), the motherboard will power off, unplug it, the motherboard is working properly, and the LED light will be on"

Candas1 commented 2 months ago

So what works? One motor and uart?

AILIFE4798 commented 2 months ago

i dont know you need to ask @hiliving

AILIFE4798 commented 2 months ago

do the sine wave mode in gen1 need phase current sensor

Candas1 commented 2 months ago

No, that's why I said he should use it. It's also explained how it's used in the table.

Candas1 commented 2 months ago

From the same wiki page:

In general, if you have doubts about you mainboard's compatibility:

AILIFE4798 commented 2 months ago

adc pin cannot be changedin the firmware,how can control the board, is there a test rotation feature in the firmware

Candas1 commented 2 months ago

ADC channels have to be changed here based on the datasheet.

Already replied here.

hiliving commented 2 months ago

So what works? One motor and uart? The board LED is on, and the buzzer has a be be alarm sound,That means the board is working properly, Just detected that the Hall wire is not connected,right?

hiliving commented 2 months ago

my steps for first test:

  1. in platformio.ini default_envs = VARIANT_ADC ; Variant for control via ADC input
  2. in config.h
    `// Control selections

    define CTRL_TYP_SEL SIN_CTRL // [-] Control type selection: COM_CTRL, SIN_CTRL, FOC_CTRL (default)`

Can these two configurations enable sinusoidal control type with ADC variant?

I tested it without modifying the ADC channels, and the buzzer beeped softly. When one motor was disabled, //#define MOTOR_LEFT_ENA the warning sound disappeared. But disabling the other motor does not work, and the alarm still sounds.

Should I modify the ADC channels first, and which one should I modify it to? Or do we try it one by one?

Candas1 commented 2 months ago

But what beeps ? Did you read this ?

In this mode, you need only need correct ADC channels for speed and steer control. ADC channels for phase currents will not be used. ADC channels for DC current is always used for battery current limiting. If it's wrong and always 0, DC current won't be limited.

yiwlg commented 2 months ago

I also have the same motherboard and am currently struggling with how to debug the connection. After flashing the universal firmware, my buzzer is no longer ringing

hiliving commented 2 months ago

But what beeps ? Did you read this ?

In this mode, you need only need correct ADC channels for speed and steer control. ADC channels for phase currents will not be used. ADC channels for DC current is always used for battery current limiting. If it's wrong and always 0, DC current won't be limited.

I have modified a total of 6 ADC channels based on the datasheet,


void MX_ADC1_Init(void) {
  ADC_MultiModeTypeDef multimode;
  ADC_ChannelConfTypeDef sConfig;

  __HAL_RCC_ADC1_CLK_ENABLE();

  hadc1.Instance                   = ADC1;
  hadc1.Init.ScanConvMode          = ADC_SCAN_ENABLE;
  hadc1.Init.ContinuousConvMode    = DISABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv      = ADC_EXTERNALTRIGCONV_T8_TRGO;
  hadc1.Init.DataAlign             = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion       = 5;
  HAL_ADC_Init(&hadc1);
  /**Enable or disable the remapping of ADC1_ETRGREG:
    * ADC1 External Event regular conversion is connected to TIM8 TRG0
    */
  __HAL_AFIO_REMAP_ADC1_ETRGREG_ENABLE();

  /**Configure the ADC multi-mode
    */
  multimode.Mode = ADC_DUALMODE_REGSIMULT;
  HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode);

  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfig.Channel = ADC_CHANNEL_5;  // pc1 left cur  ->  right RIGHT_DC_CUR_PORT PA5  ADC01_IN5
  sConfig.Rank    = 1;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  // sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  sConfig.Channel = ADC_CHANNEL_3;  // pa0 right a   ->  left LEFT_U_CUR_PORT  PA3 ADC012_IN3
  sConfig.Rank    = 2;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  sConfig.Channel = ADC_CHANNEL_15;  // pc4 left b   -> right  RIGHT_U_CUR_PORT  PC5 ADC01_IN15
  sConfig.Rank    = 3;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  #if BOARD_VARIANT == 0
  sConfig.Channel = ADC_CHANNEL_12;  // pc2 vbat      
  #elif BOARD_VARIANT == 1
  sConfig.Channel = ADC_CHANNEL_1;   // pa1 vbat
  #endif
  sConfig.Rank    = 4;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  //temperature requires at least 17.1uS sampling time
  sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
  sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;  // internal temp
  sConfig.Rank    = 5;
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  hadc1.Instance->CR2 |= ADC_CR2_DMA | ADC_CR2_TSVREFE;

  __HAL_ADC_ENABLE(&hadc1);

  __HAL_RCC_DMA1_CLK_ENABLE();

  DMA1_Channel1->CCR   = 0;
  DMA1_Channel1->CNDTR = 5;
  DMA1_Channel1->CPAR  = (uint32_t) & (ADC1->DR);
  DMA1_Channel1->CMAR  = (uint32_t)&adc_buffer;
  DMA1_Channel1->CCR   = DMA_CCR_MSIZE_1 | DMA_CCR_PSIZE_1 | DMA_CCR_MINC | DMA_CCR_CIRC | DMA_CCR_TCIE;
  DMA1_Channel1->CCR |= DMA_CCR_EN;

  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
}

/* ADC2 init function */
void MX_ADC2_Init(void) {
  ADC_ChannelConfTypeDef sConfig;

  __HAL_RCC_ADC2_CLK_ENABLE();

  // HAL_ADC_DeInit(&hadc2);
  // hadc2.Instance->CR2 = 0;
  /**Common config
    */
  hadc2.Instance                   = ADC2;
  hadc2.Init.ScanConvMode          = ADC_SCAN_ENABLE;
  hadc2.Init.ContinuousConvMode    = DISABLE;
  hadc2.Init.DiscontinuousConvMode = DISABLE;
  hadc2.Init.ExternalTrigConv      = ADC_SOFTWARE_START;
  hadc2.Init.DataAlign             = ADC_DATAALIGN_RIGHT;
  hadc2.Init.NbrOfConversion       = 5;
  HAL_ADC_Init(&hadc2);

  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfig.Channel = ADC_CHANNEL_13;  // pc0 right cur   -> left LEFT_DC_CUR_PORT now is PC3 ADC012_IN13
  sConfig.Rank    = 1;
  HAL_ADC_ConfigChannel(&hadc2, &sConfig);

  // sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  sConfig.Channel = ADC_CHANNEL_4;  // pc3 right b   -> left LEFT_V_CUR_PORT PA4 now is ADC01_IN4
  sConfig.Rank    = 2;
  HAL_ADC_ConfigChannel(&hadc2, &sConfig);

  sConfig.Channel = ADC_CHANNEL_14;  // pc5 left c   -> right RIGHT_V_CUR_PORT PC4 now is ADC01_IN14 
  sConfig.Rank    = 3;
  HAL_ADC_ConfigChannel(&hadc2, &sConfig);

  sConfig.Channel = ADC_CHANNEL_2;  // pa2 uart-l-tx not modify
  sConfig.Rank    = 4;
  HAL_ADC_ConfigChannel(&hadc2, &sConfig);

  // sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;   // Commented-out to make `uart-l-rx` ADC sample time the same as `uart-l-tx`
  sConfig.Channel = ADC_CHANNEL_3;  // pa3 uart-l-rx not modify ADC012_IN3
  sConfig.Rank    = 5;
  HAL_ADC_ConfigChannel(&hadc2, &sConfig);

  hadc2.Instance->CR2 |= ADC_CR2_DMA;
  __HAL_ADC_ENABLE(&hadc2);
}

but there is still a short circuit in UART mode. After pressing the power button, the buzzer will sound normally and then shut down. In ADC mode, there is no short circuit shutdown, DEBUG_SERIAL_UART3 is enabled, and when using ST link to connect USB for power supply, the LED light on the motherboard will light up without an alarm sound. Connecting PB10 and PB11 can read Rx Tx serial port data, and webTool can display logs. However, whether or not the Rx TX pin is swapped, commands cannot be sent, and there is no return when sending commands.

AILIFE4798 commented 2 months ago

@Candas1 did you even read the list of pin/the image attached to the issue Because you say to use adc control method, but the board does not have adc pin Both pb6,7 and pb10,11 does not have adc

Now the problem afaik is the board auto power off after all the internal adc channel is configured correctly, when using stlink to power the board it can work with uart communication, but because it power off from battery connector it cannot run the motor I'm not entirely sure now exactly the problem cuz hiliving don't know what he's doing

Candas1 commented 2 months ago

I have provided hints, don't expect me to search the datasheet.

Candas1 commented 2 months ago

However, whether or not the Rx TX pin is swapped, commands cannot be sent, and there is no return when sending commands.

If webtool works, it's good enough to control the firmware.

Debug protocol doesn't allow to control but only to tweak parameters. This is how it should be enabled. https://github.com/EFeru/hoverboard-firmware-hack-FOC/wiki/Debug-Serial#keyboard-debug-protocol

AILIFE4798 commented 2 months ago

I didn't know gen1 already have serial terminal config actually,I thought I was the first one to do it Why is there no pre compiled binary then since you can set the parameter later