2023-10-23 05:15 AM
I have a hard fault on startup of my near clone of a B-G431B-ESC1 pcb.
Generated the code using the latest version of MC (6.2.0). Code runs and waits for a start command from Motor Pilot. It then tries to start with a short burst of high current which is not what I expect, then stops on the hard fault.
I enabled the 3 fault handlers, mem, bus and usage, then try and run the code. It stops immediately on UsageFault_Handler I find an unaligned error reported. looking further via msp reg, pushed stack etc. I find an assembly line
"str.w r5, [r12, #22]"
This looks like it is storing a word variable into a location with 22 bytes offset.
Going to the C code I get
FOCVars[bMotor].Vqd = NULL_qd;
Vqd is defined in a structure FOCVars_t, where it is 22nd byte and the var is a structure of 2 int16_t so 4 bytes long.
I put an int16_y dummy, just before the Vqd var in the typedef to push into a 4 byte alignment, then test, and it does not fault there but goes further on to another usage fault unaligned, I do the same and it stops at another, this is a more complicated structure, but still I find in each case the offset is not divisible by 4.
This is odd, because it was obviously not failing on these before I enabled the fault handlers!
Is this normal behavior? Or is it leading to the original hardfault due to mis aligned variables in memory?
All assistance greatly appreciated.
Cheers.
Pete L.
2023-10-31 10:08 AM
Hello @Peter Lissenburg,
Your issue sounds strange to me.
Could you attach to this post your stwb6 file and tell us what your compiler is.
Regards
Cedric
2023-11-03 12:25 AM
Hello @cedric H ,
sorry for the delayed reply as I have been away from the office, and thank you for your time.
I have attached the project A_LV-ESC-1_001Ohm_100A_V2. This was generated by MC workbench version 6.2.0. Compiled by STM32CubeIDE 1.13.1
I did proceed a little further, disabled the UsageFault handler, and it works as before until I start with Motor Pilot. The instead of the HardFault it stops with an imprecise bus fault. Disabled buffering, and the address seems to be around the RUC code. But that is as far as I got.
Project hardware is based upon the B-G431B-ESC1. Different Mosfets and the same driver. CPU is the STM32G431CBT6 otherwise the major change is to current measurement making it 100A. The 3 low side current shunt resistor networks are 3k3 series to shunt, 1k8 pull down and pull up 62k for each phase.
I have done a previous version of the hardware with just changing these resistor to give a 40 Amp max and it worked OK. ie motor started smoothly and accelerated to 800RPM at a 25v Supply.
Hoping you can see my fault and a fix would be great.
Cheers.
Pete L.
2023-11-03 09:09 AM
Dear Peter Lissenburg,
Coming back to your first post, may I ask a basic question? Does "FOCVars[bMotor].Vqd = NULL_qd;" mentioned is the one called in FOC_Clear() function?
If yes, it sounds strange as this function is once at MCBoot() call (and then before start motor command) and a second time at TSK_MediumFrequencyTaskM1() function after a start motor. Could you please compare these two calls?
On the other hand, concerning your second attempt, do you monitor the MCU DC supply? Could the power side start impact the control DC values?
2023-11-05 06:38 PM - edited 2023-11-08 02:09 AM
Hello @GMA
Regards the "FOCVars[bMotor].Vqd = NULL_qd;" reference, it is within FOC_Clear, however I cannot find any reference to FOCVars[bMotor].Vqd anywhere else in the mc_task.c file.
At the moment I use a isolated lab supply for the low voltage side.
This is the 3v3 supply and the first few High side gate PWM pulses. At the end is where the Hardfault / Busfault occurs.
Looking closer and triggering off the 3v3.
Would this be enough to cause the Hardfault? (I have checked the ADC supply pin and this glitch is not visible with this being filtered).
If so I'll have to move on to the next reiteration of the PCB, (more layers, more shielding, shorter tracks) which is waiting a final look over.
However if I change just the current range back to 40 amps all is OK. This does seem odd to me.
Thanks for your time and consideration.
Cheers.
Pete L.
2023-11-09 12:38 AM
Hello Peter,
Thank you for your feedback.
Please have a look to this post with some other MCU signals to be considered...
2023-11-09 01:06 AM
Thank you @GMA ,
interesting problem referred to in that link.
However I can change only the current sense network resistors for a +-50Max scale, feed that into the Board file, generate the code. And with no other change, the motor will spin. Starting to do so at 250mA, accelerating to 800 RPM at 2A. So from that, I infer that there is no reason for the system configured for -+100Amp scale to draw 200x more current at startup, (before the busfault is triggered).
So far I am not able to determine why the duty, and therefore high current is being set. That high current I believe is causing the glitch, and so is an effect rather that a cause of the problem.
The search continues....
PeteL