Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen2.4.1 (ex2.8) = MM32SPIN05PFOP :-( #22

Open
RoboDurden opened this issue Sep 19, 2023 · 315 comments
Open

Gen2.4.1 (ex2.8) = MM32SPIN05PFOP :-( #22

RoboDurden opened this issue Sep 19, 2023 · 315 comments

Comments

@RoboDurden
Copy link
Owner

RoboDurden commented Sep 19, 2023

master front/back

https://www.mindmotion.com.cn/en/products/mm32mcu/mm32spin/mm32spin_specific_mcu/mm32spin05/

  • 32bit Arm® Cortex®M0 processor as the core
  • Maximum operating frequency is up to 72M
  • 32K bytes of Flash memory
  • 4K bytes of SRAM
  • Boot loader supports Chip Flash and ISP (InSystem Programming)
  • Embedded factorytuned 48/72MHz high speed oscillator
  • One 12bit ADC and 1μS of conversion time (up to 13 channel)
  • Supported peripherals: Timer, UART, I2C, SPI and ADC
  • One 16bit 4channel advancedcontrol timer with 4channel PWM output, dead-time
    generation and emergency stop
  • Serial wire debug (SWD)
  • Two UARTs
  • One I2C
  • Two SPIs

https://www.keil.com/dd2/mindmotion/mm32spin05nt/

https://github.com/topics/mm32

Would be nice if someone knows how to add this device to the Keil IDE.

@reed-dan
Copy link

Does the information here help add it to KEIL?

https://github.com/iclite/mm32_startup/tree/master

@RoboDurden
Copy link
Owner Author

Would be nice if @WizzardDr would explain how he added the GD32E230 target to the project:
grafik
If a new target would be added, then your MM mcu can be choosen:
grafik

Then this repo might already compile.
It might need some fixes like fore the E230 mcu in target.h

#ifdef GD32E230
	#include "gd32e23x.h"
	#define TARGET_nvic_irq_enable(a, b, c){nvic_irq_enable(a, b);}
	#define TARGET_nvic_priority_group_set(a)	// that function does not exist for this target = not needed ?
	#define TARGET_adc_vbat_disable()
#else
	#include "gd32f1x0.h"
	
	#define TARGET_nvic_irq_enable(a, b, c){nvic_irq_enable(a, b, c);}
	#define TARGET_nvic_priority_group_set(a){nvic_priority_group_set(a);}
	#define TARGET_adc_vbat_disable(){adc_vbat_disable();}
#endif

But as WizzardDr succeeded with adding a new target, i now am quite optimistic that he and me could add your MM mcu and i/we resolve all compiler errors.

But are you willing to invest some hours to trace the pins ??

@RoboDurden
Copy link
Owner Author

Okay, a target can be added in menu->Project->Manage->ProjectItems..
grafik

But now i am stuck at adding the Device files and i do not know the name of the propper #include file:
grafik

ideas welcome.

@reed-dan
Copy link

reed-dan commented Oct 31, 2023

When I look at my board it is slightly different than this board, appears to have the same processor though.

20231031_112219
20231031_111844
20231031_111811

Board Source: Jetson Plasma
Model: Plasma (JPLSM-BLK)
Construction: Plastic Base Plastic wheel
UPC: 811991031504
Battery: ELITOP-1001U-JD LI-ION 36V 90Wh 2500mAh
-Shenzhen Elite Electric Co. Ltd. MH63800 HY-JD-A20GNB3642
Input: 36VDC 0.85A Max capicity 2.5AH
Max Speed 10 Mph
Max Weight 220LB

Slave Board Identifiers
Taotao Technology
2025
pu20200616011
94v-0 y-d
e253642
816117r

@RoboDurden
Copy link
Owner Author

To me this looks identical to the photos of the first board.

But i have no idea from where to get the MM counterplay of the Standard Peripherals:
grafik

I have nearly zero experience with the Keil Ide :-/

@RoboDurden
Copy link
Owner Author

Yes thanks, i have added the pdf documents to the manuals folder.
But i fear we still do not know how to install the Standard Peripherals like ADC, DMA, GPIO

@reed-dan
Copy link

reed-dan commented Nov 22, 2023

Also found in

Board Source: JETSON ALPA
Model: Alpha (JALPHA-BLK)
Construction: Plastic Base
FCC: 2AV54ALPHA
https://fcc.report/FCC-ID/2AV54ALPHA

@BigVoo
Copy link

BigVoo commented Jan 6, 2024

Looking for help on this board. I've burned through many of the RioRand motor controllers and decided to use one of the 4 different hoverboard motors that I have. Any help will be appreciated. I'm a newbie, but I love tinkering and learning new things.

@RoboDurden
Copy link
Owner Author

If you have different boards you better start with a GD32F130 MCU and not this not yet supported MM32SPIN05.

@BigVoo
Copy link

BigVoo commented Jan 6, 2024

I do have a GD32F130 C8T6 MCU board, but it's a newer board and does not match any of the examples. I wasn't sure if I could flash or not since it didn't exactly match. If I can, then that will be perfect since that's the board and motor that I want to use.

@RoboDurden
Copy link
Owner Author

No you need to start a new issue here, upload high res photos of front and backside and start tracing the pins. See the 2.6.1 issue currently being active.
This 2.8 is not yet traced either.

I always like to add new layouts, so feel free to go ahead :-)

@AILIFE4798
Copy link

@RoboDurden heres a toturial of using keil with mm32spin maybe itll help i cannot tell
mm32spinexample(changeZIPto7Z).zip
MM32_KEIL_Pack_2.18.zip

@AILIFE4798
Copy link

AILIFE4798 commented Jan 6, 2024

Okay, a target can be added in menu->Project->Manage->ProjectItems.. grafik

But now i am stuck at adding the Device files and i do not know the name of the propper #include file: grafik

ideas welcome.

i am not sure if this is your problem but i think you can copy it from example
image

@AILIFE4798
Copy link

@RoboDurden can you please look into it now i have included the new build target
it still have 83 error but those are related to constant not defined can you fix them
image
#50

@RoboDurden
Copy link
Owner Author

Thanks for you work ! I have accepted the pull request :-)
But i did not like that you changed

#ifndef ADC_BATTERY_VOLT
	#define ADC_BATTERY_VOLT      0.024169921875 

to

#ifndef ADC_BATTERY_VOLT
	#define ADC_BATTERY_VOLT      0.02488682634 	// V_Batt to V_BattMeasure = factor 30: ( (ADC-Data/4095) *3,3V *30 )

This would apply to all other layouts and not only the 2.6.
Instead i will add

#define ADC_BATTERY_VOLT 0.02488682634 // V_Batt to V_BattMeasure = factor 30: ( (ADC-Data/4095) *3,3V *30 )
to the defines_2-6.h

@RoboDurden
Copy link
Owner Author

i have uploaded my first changes, so please @AILIFE4798 sync your code.

#ifdef GD32E230
	#define LAYOUT 7
#elif MM32SPIN05
	#define LAYOUT 8
#else
	#define LAYOUT 6
#endif

//#define MASTER		// uncomment for MASTER firmware. Choose USART0_MASTERSLAVE or USART1_MASTERSLAVE in your defines_2-?.h file
//#define SLAVE			// uncomment for SLAVE firmware. Choose USART0_MASTERSLAVE or USART1_MASTERSLAVE in your defines_2-?.h file
#define SINGLE			// uncomment if firmware is for single board and no master-slave dual board setup

Looks like many files in the Inc project folder should not be there. Maybe you can fix this:
grafik

@RoboDurden
Copy link
Owner Author

RoboDurden commented Jan 8, 2024

I am down to 75 errors and 0 warning.
Many errors are to my PB8 -> PORT_B + PIN_8 marcors that i introduced lately to make the defines_2-x.h easier.
But these macros are GD32 specific so i now first have to investigate how MM is coding PORT and PIN.
This might take some hours.

I am still struggeling to get water and electricity running in my autarcic train station:
grafik
It is -7°C outside (10:44 o' clock)

@AILIFE4798
Copy link

yes,the adc calibration should be done on every board because the resistors and mcus are not exactly identical

you can delete those files in inc its not needed
i am just experimenting with it and those file is included in device already
image

@RoboDurden
Copy link
Owner Author

done and repo updated :-)

@AILIFE4798
Copy link

do you have real hardware layout2.8 to test on or should i buy more of them to test
because the real problem will start from how to flash it

@RoboDurden
Copy link
Owner Author

MM is also using port defines like GPIOB but not pin defines like GPIO_PIN_9 :-/ So i must learn the defines to acces a port/pin for MM.
With GD32 the GPIO_PIN_9 is defined in gd32f1x0_gpio.h:


/* GPIO pin definitions */
#define GPIO_PIN_0                 BIT(0)                /*!< GPIO pin 0 */
#define GPIO_PIN_1                 BIT(1)                /*!< GPIO pin 1 */
#define GPIO_PIN_2                 BIT(2)                /*!< GPIO pin 2 */
#define GPIO_PIN_3                 BIT(3)                /*!< GPIO pin 3 */
#define GPIO_PIN_4                 BIT(4)                /*!< GPIO pin 4 */
#define GPIO_PIN_5                 BIT(5)                /*!< GPIO pin 5 */
#define GPIO_PIN_6                 BIT(6)                /*!< GPIO pin 6 */
#define GPIO_PIN_7                 BIT(7)                /*!< GPIO pin 7 */
#define GPIO_PIN_8                 BIT(8)                /*!< GPIO pin 8 */
#define GPIO_PIN_9                 BIT(9)                /*!< GPIO pin 9 */
#define GPIO_PIN_10                BIT(10)               /*!< GPIO pin 10 */
#define GPIO_PIN_11                BIT(11)               /*!< GPIO pin 11 */
#define GPIO_PIN_12                BIT(12)               /*!< GPIO pin 12 */
#define GPIO_PIN_13                BIT(13)               /*!< GPIO pin 13 */
#define GPIO_PIN_14                BIT(14)               /*!< GPIO pin 14 */
#define GPIO_PIN_15                BIT(15)               /*!< GPIO pin 15 */
#define GPIO_PIN_ALL               BITS(0,15)            /*!< GPIO pin all */

The PORT definitions for MM are in reg_gpio.h :

#define GPIOA                           ((GPIO_TypeDef*) GPIOA_BASE)
#define GPIOB                           ((GPIO_TypeDef*) GPIOB_BASE)
#define GPIOC                           ((GPIO_TypeDef*) GPIOC_BASE)
#define GPIOD                           ((GPIO_TypeDef*) GPIOD_BASE)

But i can no identify the PIN definitions yet. Maye a MM32 code example would help

I think i have 2.8 but not here in the train station i think. And honestly i do not have the time=happiness at the moment to build yet another test setup. So it would be great if you had 2.8 hardware. Was $2 a typo or can you really buy fully assembled 2.8 boards for USD 2 ???

@RoboDurden
Copy link
Owner Author

Maybe these are the definitions we need: https://github.com/koendv/MM32SPIN27-Arduino/blob/525f27bd91b756aeabad3b7a706f60cb9fb75275/mm32/cores/arduino/HAL_Lib/hal_gpio.h#L89

But i would like to find these defines in the target files you added.

@AILIFE4798
Copy link

AILIFE4798 commented Jan 8, 2024

image
here is a example of mm32 blynk

$2 is for a pair of master and slave layout2.8.1 board by razor no led or motor
i think its hard to beat
heres a link not sure if you can open it outside of china if not you have to use VPN
https://m.intl.taobao.com/detail/detail.html?id=722577319258
a set of gen1 board with mainboard+2 side board+led board is $12 still cheap(seller say its full GD32 so compatiable with eferu)
keep in mind its china everything is dirt cheap

@RoboDurden
Copy link
Owner Author

Where can i download this blynk example ?

We have problems to port the EFeru gen1 firmware to the newer AT32 Gen1 boards ! So if there is no GD32 mcu on theser $12 boards i would be caucious.

@I-hate-2FA
Copy link

i see its 1, its the most terrible of all, you should really try other ones

@I-hate-2FA
Copy link

is your board foc capable, the $2 one isnt

@trondin
Copy link

trondin commented Sep 22, 2024

I hope so, it is $4 :)
https://www.aliexpress.com/item/1005005959910034.html
Trying to modify EFeru software for this board now.

@I-hate-2FA
Copy link

oh this one is just the one i use its $2 in china, its not foc capable, what do you expect for the price lmao

@I-hate-2FA
Copy link

eferu firmware is terrible, mine is way superior, you just didnt rtfm

@trondin
Copy link

trondin commented Sep 22, 2024

so far EFeru software are used by many peoples, and they are happy. For sure his simulink generated code - it is something... If you are not simulink user.
I don't like idea to do automatic pin adjustment, not so easy to modify code if you need.
Let's hope your code will be more user friendly, so far control is not elementary. BTW, are you sure ESP32 will survive with 5V mm32spin?

@I-hate-2FA
Copy link

yes esp32 is 5v tolerant
the auto pin adjustment is better to modify the code, so you can test same code on different hardware without changing config every time, and eferu code its just IMPOSSIBLE to modify for board with other layout
the low speed problem is clearly with drivemode, if you used drivemode 2 or 3 itll be very good
im not simulink user

@trondin
Copy link

trondin commented Sep 22, 2024

STM32's most pins are 5v tolerant, but for last 2 days I manage to kill 2 UARTs. Fortunately it has 3 :)

@trondin
Copy link

trondin commented Sep 22, 2024

just IMPOSSIBLE to modify for board with other layout
BTW, I just got my motor moving with eferu code and mm32spin05 a few minutes ago.
The biggest problem - something is not very smooth with torque foc mode.
For sure his code was modified for bare metal, no any HAL or another libraries.
Problem - cortex m0 is too slow for his code and 16kHz, I have used 12kHz. And something wrong with ADC - one phase level is too small (about 1.5 times difference between phase voltage), probably problem with timing between PWM and ADC measurement.
I hate mm32spin05 UART - it looks simple, but it is something...

@RoboDurden
Copy link
Owner Author

Yes i tested EFeru torque mode only once. With no load, the motor was not spinning smootly. So i continued with simple pwm/voltage mode.
So you succeeded with an EFeruFOC port for the mm32spin05 !?
I thought this board was not capabale of two phase currents - which everyone tells me to be mandatory for FOC.
Are you working with platformIO ?

@I-hate-2FA
Copy link

this board hardware not capable of foc what are you talking about

@I-hate-2FA
Copy link

if you want none blocking uart with dma its not very easy

@I-hate-2FA
Copy link

i did try, simply modify eferu for another gd32f103 is already near impossible, it actually hapenned (#77)

@trondin
Copy link

trondin commented Sep 22, 2024

It has even too much connection - 3 channel for phase, I have used 2 of them. Usually hoverboard control board has amplifiers for current with low amplification (3x). But mm32spin05 ADC has 1.2V ref voltage, it helps a lot.
I have used EFeru software in my mobility scooter few years ago ( I am disabled) https://www.youtube.com/watch?v=8kPj900S7OM

@RoboDurden
Copy link
Owner Author

please upload a full image of your schematics. I do not see the phase currents input pins.

@trondin
Copy link

trondin commented Sep 22, 2024

MM32SPIN05_CTRL_page-0001

@RoboDurden
Copy link
Owner Author

Thanks for the upload.
2.4.1 has three gate driver chips. Your board has analog gate drivers. So this must be a new MM32SPIN05 board.
Better start a new issue so i can assign a new id.

And this is the circuit for the phase currents B and C ?
phase currents

I do not really understand how this should work. But the MM32 has internal comperators that can works as OpAmps ?

If got a EFeru port running, please create your own repo here so we can have a look at your code.
PlatformIO ?

@RoboDurden
Copy link
Owner Author

RoboDurden commented Sep 22, 2024

2.2.22 Comparator (COMP)
The product has one builtin comparator which can be used independently (suitable
for I/Os on all terminals) or in combination with the timer. It can also be used for a
variety of functions, including:
• Trigger wake up events in the lowpower mode by analog signals
• Adjust the analog signal

Maybe this one comperator can be toggle between two analog inputs..

grafik

@trondin
Copy link

trondin commented Sep 23, 2024

timer

	// -------------
	TIM1->SMCR = 0;
  TIM1->CR1 = TIM_CR1_CMS_CENTERALIGNED1;  // Center-aligned mode 1
  TIM1->PSC = 0;
  TIM1->ARR = PWM_RES;  // 2250	
  TIM1->RCR = 1; 
  // master/slave
  TIM1->CR2 = TIM_CR2_MMS_UPDATE;   // TRGO	
	//TIM1->CR2 = TIM_CR2_MMS_OC4REF;  //CCR4
	
  // ConfigChannel 
  TIM1->CCMR1 = TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC2M_PWM1;   
  TIM1->CCMR2 = TIM_CCMR2_OC3M_PWM1;  
//	TIM1->CCMR2 |= TIM_CCMR2_OC4M_INACTIVE; 

  // break
  TIM1->BDTR = TIM_BDTR_OSSR | TIM_BDTR_OSSI | DEAD_TIME;
  // enables
  TIM1->CCER = TIM_CCER_CC1E | TIM_CCER_CC1NE 
	           | TIM_CCER_CC2E | TIM_CCER_CC2NE 
						 | TIM_CCER_CC3E | TIM_CCER_CC3NE;
  TIM1->BDTR |= TIM_BDTR_MOE;
	TIM1->CR2 |= TIM_CR2_OIS1N | TIM_CR2_OIS2N | TIM_CR2_OIS3N;

  //TIM1->CCR4 = TIM1->ARR -500; 




  // start  
  TIM1->CR1 |= TIM_CR1_CEN; 
}

ADC (comparator is not in the game)

void ADC1_Init(void)
{
  RCC->APB2ENR |=  RCC_APB2ENR_ADC1EN;	

 	RCC->AHBENR |= RCC_AHBENR_GPIOA | RCC_AHBENR_GPIOB; 
  GPIOA->CRL  = 0;
  GPIOB->CRL &= 0xFFFFFF00;
	
  ADC1->CFGR = ADC_CFGR_ADEN |  ADC_CFGR_TEN | ADC_CFGR_VEN | ADC_CFGR_PRE_5;   //14.4MHz, temper & ref enable
  ADC1->CR = ADC_CR_SCAN | ADC_CR_T1_TRIG  | ADC_CR_DMAEN;		

  ADC1->CHSR = ADC_CHSR_CH0 | ADC_CHSR_CH1   // phase b
             | ADC_CHSR_CH4 | ADC_CHSR_CH5   //phase c
             | ADC_CHSR_CH7                  // I common
	           | ADC_CHSR_CH9                  // voltage             
             | ADC_CHSR_CHT;                 // temperature


  RCC->AHBENR |=  RCC_AHBENR_DMA1EN;

  DMA1_Channel1->CCR   = 0;
  DMA1_Channel1->CNDTR = 7;
  DMA1_Channel1->CPAR  = (uint32_t)&(ADC1->DR);
  DMA1_Channel1->CMAR  = (uint32_t)&adc_buffer_raw;
  DMA1_Channel1->CCR   = DMA_CCR_MSIZE_0 | DMA_CCR_PSIZE_0 | DMA_CCR_MINC | DMA_CCR_CIRC | DMA_CCR_TCIE; 
  DMA1_Channel1->CCR  |= DMA_CCR_EN;

  NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
  NVIC_EnableIRQ(DMA1_Channel1_IRQn);
	

	// ADC1->CR |= ADC_CR_TRGEN;
}

interruption

void DMA1_Channel1_IRQHandler(void) 
{
  DMA1->IFCR = DMA_IFCR_CTCIF1;
	
		adc_buffer.rrB = (adc_buffer_raw[0]- adc_buffer_raw[1]) & 0xFFF;
		adc_buffer.rrC = (adc_buffer_raw[2] - adc_buffer_raw[3]) & 0xFFF;
		adc_buffer.dcr = adc_buffer_raw[4] & 0xFFF;    
	  adc_buffer.batt1 = adc_buffer_raw[5] & 0xFFF;       
	  adc_buffer.temp = adc_buffer_raw[6] & 0xFFF;   
	

board
pinout

@trondin
Copy link

trondin commented Sep 23, 2024

Platformio for editing and keil uVision under wine for compilation. I didn't adapt platformio for mm32, compilation works but binary is wrong. It is possible to get working with platformio, but it takes time. I just use the simplest way.

@I-hate-2FA
Copy link

i already know there are 3 wire connected to phase, but the connection is NOT to the comparator, so its not useable

@I-hate-2FA
Copy link

this wiring is for mcu with a built in opamp like the lks32, the 3 pin wiring is exactly what you will fing connecting to the opamp
but the mm32spin does not have one

@I-hate-2FA
Copy link

this board is 2.4.1, the exact same one i have, long ago i have reverse engineered it(but i didnt draw full schematic)

@trondin
Copy link

trondin commented Sep 24, 2024

this wiring is for mcu with a built in opamp like the lks32, the 3 pin wiring is exactly what you will fing connecting to the op
Brilliant! It explains a role of stupid resistor! Just to find LKS32MC05x and replace - and you board will be perfect! But where to find?

@RoboDurden
Copy link
Owner Author

grafik

@RoboDurden
Copy link
Owner Author

I think the one comperator of the MM32 could do the same as an opamp.. if the PA0,PA1,PA2 pins where connected to the MM32 stlightly different ?

grafik

And as there are multiple io pins available for this one comperator, i guess the software could toggle between two sets to fetch two phase currents..

@I-hate-2FA
Copy link

it is not possible, you have the diagram and pinout, clearly one all connect to in+ other all connect to in-, i already checked

@RoboDurden
Copy link
Owner Author

maybe @trondin got the pin connections wrong in his nice schematics :-)

@I-hate-2FA
Copy link

I-hate-2FA commented Sep 24, 2024

its possible that i or him made mistake, but its not possible that we both do.
you have the board, you can check it your self
303497448-8d725b8a-ae16-4200-9281-23d509e72d12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants