Hoverboard-Firmware-Hack-Gen2.x icon indicating copy to clipboard operation
Hoverboard-Firmware-Hack-Gen2.x copied to clipboard

Gen2.4.x = ALL about MM32SPIN0X (ex2.8 / ex2.8.1 / ex2.21)

Open ghost opened this issue 1 year ago • 122 comments

if you had a mm32spin0x board please create a new layout and hopefully help us make the blink code run on it

currently the progress is 90% complete

motor and uart control works

https://github.com/AILIFE4798/Hoverboard-Firmware-Hack-Gen2.x-MM32

ghost avatar Jan 28 '24 14:01 ghost

@AILIFE4798 the link to the old issues just takes me back here. Link to issue 22

reed-dan avatar Jan 30 '24 16:01 reed-dan

@RoboDurden blink code worked

ghost avatar Feb 02 '24 14:02 ghost

Good News. I won't drive for the next days, so I could do some programming. The autodetect as it currently is would need a 16 khz timer (that triggers ADC conversion) But with the timer working the led stage should already work. And the hall detection. The bldc driver would need the advanced timer with three own channels..

Did you make any modifications to the blink example in the Keil package ?

If so, where can I download your project ?

RoboDurden avatar Feb 02 '24 14:02 RoboDurden

I will update my code later Because there is no crystal hardware on the board you cannot use clock and it was the problem stopping program from running Hers a proof of it running I don't have motor so I'm not going to test it you will have to

https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/assets/142502122/6524f378-afb3-491e-a699-2050c66896ce

ghost avatar Feb 02 '24 14:02 ghost

fuck that ill use youtube https://youtu.be/Byqhe22NDPg

ghost avatar Feb 02 '24 14:02 ghost

https://github.com/AILIFE4798/Hoverboard-Firmware-Hack-Gen2.x-MM32 use this project and the code in hoverboardmindmotion

ghost avatar Feb 02 '24 14:02 ghost

@reed-dan also try it the led pin you traced is wrong i have corrected it now

ghost avatar Feb 02 '24 14:02 ghost

Recently I will work on driving motor and uart I'm pretty sure it'll be possible But I can already say foc is not because the lack of comparator on my board

ghost avatar Feb 02 '24 21:02 ghost

Better spend the time rewriting all the gd32 code and then add foc to it

ghost avatar Feb 02 '24 21:02 ghost

@AILIFE4798 , i have downloaded your HoverBoardMindMotion/ but when i doubleclick on HoverBoardMindMotion/Hoverboard.uvprojx , i still have to change the compiler version from missing-5 to 6. And when i then hit F7 i get

Src/main.c(88): error: call to undeclared function '__nop'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] It would be nice to have a Keil project that i can download and that does compile successfully like on your computer :-/

RoboDurden avatar Feb 03 '24 10:02 RoboDurden

I do not really find Timer code and dma-adc code in MM32SPIN0x_q_Lib_Samples But it looks like Motor-DK_Low_Power_DEV_Kit_MM32SPIN0x_V1.7\4-Software\03.Hall FOC\SPIN05\MM32SPIN05_HALL_FOC_3R_V_1.3_20230314\KEIL_PRJ might contain everything we need:

mm32_it.c = Gen2.x:it.c

void ADC1_COMP_IRQHandler(void) 
{
...
		//»ô¶û½Ç¶È¼°¹ÊÕϼì²â
		HALLModuleCalc(&HALL1);

hallhandle.c = gen2.x:bldc.c

void HALLModuleCalc(HALLType *u)
{
...
	u->RunHallValue = HALL_JudgeState();

...

uint8_t HALL_JudgeState(void)
{
...
	bReadValue1 = HALL_ReadHallPorts();

...

uint8_t HALL_ReadHallPorts(void)
{
	uint8_t HallA;
	uint8_t HallB;
	uint8_t HallC;
	uint8_t HallValue;
	
	HallA = GPIO_ReadInputDataBit(HALL_PORT,HALLU_PIN);
	HallB = GPIO_ReadInputDataBit(HALL_PORT,HALLV_PIN);
	HallC = GPIO_ReadInputDataBit(HALL_PORT,HALLW_PIN);
	
	if(HALL1.CMDDIR == 1)
	{
		HallValue = HallC*4 + HallB*2 + HallA;
	}
	else
	{
		HallValue = 7-(HallC*4 + HallB*2 + HallA);
	}
	
	return HallValue;
}

So if we get all this runing we should have the adc for VBATT and currentDC, the hall position and then instead of FOC the simple block commutation of gen2 to drive the motor :-)

RoboDurden avatar Feb 03 '24 10:02 RoboDurden

code updated with compiler v6 because i was using compiler v5 on my computer

ghost avatar Feb 03 '24 11:02 ghost

Until now noone have tell me if the code really can be run on other boards but at least on mine it can now self hold and working hall2led Now trying to get timer1 maybe later will get uart But uart is 5v it may destroy the esp but it dies have series resistor so we'll see Adc is not so important so it'll be at the end

ghost avatar Feb 03 '24 12:02 ghost

now i have tried to generate some pwm but so far only all 3 channel low side is conducting

ghost avatar Feb 03 '24 12:02 ghost

Yes now i can compile :-) Your new files initialize.c etc. are not in the src folder. Not really important.

The advanced timer TIM1 can be configured to drive the three low side mosfet and the three high side mosfet at the same time. So when pwm channel 1 is low, low side is high and when channel 1 is high then low side is low and high side is high. The deadtime when switching can also be configured. Also if the low/high-side on should be on boolean 0 or 1 = negate or not.

I guess you will find the init procedure in the hall bldc example i mentioned.

RoboDurden avatar Feb 03 '24 12:02 RoboDurden

The hall foc example as well as my gen2.x both trigger the bldcClalculate when adc has finished. That is why we get adc for VBATT and currentDC and/or phase currents for free.

RoboDurden avatar Feb 03 '24 12:02 RoboDurden

There is this ever ongoing discussion if ESP is 5VT or not.. Maybe put normal diodes in between anyway. Then the setup is uartBus ready an the 5V get reduced by 0.7V.

RoboDurden avatar Feb 03 '24 12:02 RoboDurden

i have fixed the file placement adc need dma so not really easy to implement all microcontroler have anti esd diode from gpio to power rail as long as the current is not too much it will keep the pin voltage at 4v(3.3+diode drop) so it will not destroy the esp as long as there is series resistor to limit the current because stm32 can output more current on gpio then the esp

btw now timer1 working

ghost avatar Feb 03 '24 12:02 ghost

video https://youtu.be/g6V8mLyiMQo

ghost avatar Feb 03 '24 12:02 ghost

I am happy to see that you are already doing all the work, so i wait until tomorrow to see if you already succeeded :-)

Please study the 0.3.Hall. FOC the (dma) adc comes for free:

int main(void)
{
...
    Peripheral_Init();
    Interrupt_Init();

...

void Peripheral_Init(void)
{
    Board_ADC_Init();

...

void Board_ADC_Init(void)
{
...
    GPIO_InitStructure.GPIO_Pin     = VBUS_PIN;
    GPIO_Init(VBUS_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin     = ISUM_PIN;
    GPIO_Init(ISUM_PORT, &GPIO_InitStructure);    
...
		ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 4, ADC_SampleTime_7_5Cycles);
		ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 5, ADC_SampleTime_7_5Cycles);

...

void Interrupt_Init(void)
{
...
    /** ADC EOF interrupt enabled */
    ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
    ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
	
    /** Initialization TIM interrupt */
    NVIC_Configure(TIM1_BRK_UP_TRG_COM_IRQn, TIM1_UPDATE_INTERRUPT);
	
...


void ADC1_COMP_IRQHandler(void) 
{
...
    if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC))
    {

...

		//»ô¶û½Ç¶È¼°¹ÊÕϼì²â
		HALLModuleCalc(&HALL1);
				

RoboDurden avatar Feb 03 '24 13:02 RoboDurden

@AILIFE4798 , where do you copy and paste your code from ? I see that you do the 6 step block commutation directly in interrupt.c:TIM1_BRK_UP_TRG_COM_IRQHandler() This of course will also work. But it is not really compatible to the Gen2 code.

But hey good to see that you make so much progress so quickly :-)

RoboDurden avatar Feb 03 '24 13:02 RoboDurden

i copied from MM32SPIN0x_q_Lib_Samples i think i will just rewrite everything while maintaining the uart protocol to be the same so you can actually use them together

ghost avatar Feb 03 '24 13:02 ghost

it is easier to rewrite then to understand the code other people write

ghost avatar Feb 03 '24 13:02 ghost

aparently in debug mode you can only see int variable but not uint32_t i really needed debug because no serial yet

ghost avatar Feb 03 '24 13:02 ghost

maybe i will be able to get foc if the board you ordered for me have comparators the $2 board is too cheap to afford a comparator not even 1

ghost avatar Feb 03 '24 13:02 ghost

serial with dma and interrupt now working

ghost avatar Feb 03 '24 17:02 ghost

the foc hall example is using timer2 for driving hall sensor so on mm32 the hall pin is also always the same

ghost avatar Feb 03 '24 18:02 ghost

I do not understand

RoboDurden avatar Feb 03 '24 18:02 RoboDurden

image board.c line93

because the timer2 is needed for foc i guess to calculate motor speed so it have to use these 3 pin image

ghost avatar Feb 03 '24 18:02 ghost

image adc is kinda working now with interrupt this is all i have time for today tomorrow will print it with serial

ghost avatar Feb 03 '24 20:02 ghost