LeptonG4 design

I’ve been working on an updated version of Valentine’s Lepton design, which uses the considerably faster STM32G431 MCU. @Anthony_Douglas , you were asking about it.

It has deviated in some points from the original Lepton’s design, but the core idea was still to make a fairly simple design (so no current sensing) that is low cost to produce.

The differences include:

  • Faster G431 MCU
  • Different (available) FETs with hopefully similar performance
  • On-board electrolytic bulk capacitance 200uF + 20uF ceramic caps, all 50V
  • Added gate resistances
  • Added snubbing circuits
  • Added some ESD protection to 3.3V rail
  • Changed SPI port for JST-SH-6pin type, to match my sensors
  • Changed SWD port for 1.27mm pitch ARM-14 header for direct connection to ST-Link V3
  • SWD header carries Serial signal
  • Changed other ports (I2C, Serial) to simple 2.54mm pitch headers (for user to solder)
  • Changed to use (optional) 1-pin clock source
  • Added power LED and 2 status LEDs

I’ve attached the schematic below, feedback is certainly appreciated…

In terms of the layout it is not yet finished, I have to add in the snubbers and gate resistances, for which I’ll have to make it a bit bigger. It’s a 4 layer layout, single sided design, currently using only 0603 or larger parts.
At the moment the board is around 5mm longer and 5mm wider than the Lepton, the G431 MCU is bigger and the bulk capacitors take some space. But I’ll have to increase the size a little more, as mentioned. Here’s a render of what it looks like at the moment (fairly dense):


I’ll post some more infos like the BOM once I finalise it all…


Nice, as I mentioned in the DM I sent, I aim to continue the effort by trying to minimally modify boards that other more skilled people make, in order to add features I believe are important. That way no one person has to do everything.

You note that current sense costs $ and I agree however if I can find some cheap 30 milliohm resistors or something, or maybe even use a suitably sized length of wire of suitable gauge, I think that would be worth it, IIRC the g431 mcu already has built in op amps (3 or 2? it would suck a bit if it was only 2 but that still works because you can infer the current of the third phase from the other 2).

Even a single resistor on one side of the input to the half h-bridges would still be useful for safety to limit current I think. It’s easier to program and easier to reset and ultimately still cheaper than a circuit breaker of some kind. I found this to be useful in my context in case the motor jams or something else goes wrong.

Secondly I do believe that good current sense has a lot of value because sensorless has great potential because these sensors themselves may be inexpensive but the calibration, extra parts they require, ,mounting provisions, wires and connetors, additional assembly and design effort etc. really adds up on you. In my case of a simple fan it came to like $70 per fan to add the sensor. There is even the potential discussed elsewhere and realized in other motor drivers to use high frequency injection techniques to get the motor position even at zero and very low speeds. That could allow for a sort of servo motor that was totally plug and play which I think would be really cool, although it may not be able to tell absolute position.

Actually, I was wondering recently if by very carefully observing variations during a full revolution caused by imperfections in the motor, one might actually be able to detect motor position on an absolute basis… But don’t want to change the subject of course and that’s a little far fetched. My main point is that current sensing has really a lot of potential and may actually save money in a lot of cases.

It’s not just adding shunts, there is a lot of additional circuitry which is needed.
Adding current sense will cause a series of changes:

  • adding sense resistors or Hall effect sensors
  • adding suitable amplifiers and filters
  • adding suitable protection
  • dealing with the analog portion of the G431, e.g. presumably adding another LDO and power filtering to make sure it has clean power
  • enlarging the board to accommodate all these components, and clean analog signal paths

It will be a different proposition to the Lepton, and cost considerably more.

I have other designs in the works which do include the current sensing, but I would take it one step at a time.

I’d use this one as a base version, and then go from there to a slightly larger model with current sensing, and support for either USB or CAN as well.

1 Like

The Qvadrans already uses G431 and inline current sense, so you may be better off trying that one.
I’m extremely busy atm so haven’t had the chance to make it and test it.


1 Like

nice, will have another look

I’m curious about this, why?

How high voltage can that board support? How do you deal with high common mode voltage for inline? I haven’t found a cheap, bidirectional current sense amp with common mode voltage tolerance to 60V. I’m thinking about moving to low-side sensing so I can use more reasonably priced parts and avoid design complexity but obviously it has firmware complications to do so.

I’m using in all my board designs bidirectional hall current sensors, there is no common mode voltage, they take as high as you got. They are galvanically isolated, I’m sure if you crack them with a 10KV it will fail but that’s an outside case.


1 Like

The chip clock sources don’t really cost more, and are less fussy regarding the load capacitance. With the classic oscillators you’re directly implementing the pierce oscillator circuit and the capacitance can matter.
They also have enable inputs if you’re into power-saving you can shut them down.

But really I prefer them because they only need one pin on the MCU and are a bit easier to use.

1 Like

I think I mean, why use external oscillator at all? With built-in xtal you can go to 168MHz. I guess the stability is poor but I’m not sure how much effect that has on motor control.

It’s a good question! I often mark the oscillator as optional in the schematics.

Presumably everything on this board will work fine off the internal oscillators. I’ll probably leave it off and just use the internal one when I build test boards.

But the external one is maybe 20-100x more accurate, it’s usually quite a big difference.

So for things like USB, CAN-bus, Ethernet or other things that depend on precise timing, precise external oscillators are recommended.


They can also be temperature regulated and factory corrected down to 1ppm error, with much higher accuracy than simple crystals.

The internal RC oscillator stability is extremely poor. If your motor is supposed to work for long periods of time, the frequency drift is unacceptably high, we are talking 10% or more drift, I bet you didn’t know that! If you are running a timed application, one MCU minute can be between 54 and 66 seconds in the internal reference time-frame, that’s completely unacceptable. If you are running a hobby DIY educational board, why not! If you are running a commercial/mission critical industrial robot, that can literally kill people.

Even the best internal MCU frequency regulated oscillators cannot achieve more than 1% drift corrections. As a comparison, a proper temperature corrected timer can achieve under one minute drift per year (!!!) running unattended! If you keep it within a very tight temperature region with correct cooling you can do even better. The most (and insanely expensive) accurate timer (the timer for the Citizen Caliber 0100) has an accuracy of +/- one second per year… !!! Or course that would cost you about the price of a new Honda Civic, so YMMV.


Hello. Can anyone explain what these components are here for and how to calculate their denominations? Thank you

It’s a snubber circuit, dampens ringing. Will consume some power (lost through the resistor). See section 7.1.1 here for example:


Indeed it is, and the values currently given In the schematic are perhaps not the final ones.

I have yet to finish layout and then to build the board, and when I assemble it, I will look at the phases under the scope and see which values have the best performance. At least that’s the plan if I have time.
I also have not sized the resistor power-wise, so please take this part of the schematic as “under development”.

1 Like

How are you finding these parts??
I am patient and good at digging through the LCSC pages to find weird parts, but there is actually no identifiable information here to search on:

“Current sensors” seems way too vague to be able to specify anything. Are you just clicking every result?

I think the LCSC webmasters are paid per click…

1 Like

I have access to their database, so for me is just entering the correct parameters in the database.
If you need some parts please ask me, but I cannot promise my availability, very busy atm.


better yet, how do you get access to the database?
or you mean you use a tool like this?

You need to ask them if you have the orders, but you need to program it.

That would also work, I guess?

LCSC is not that bad, if you know what you are looking for. But if you use it for research, I could see this being problematic. LCSC and JLC have a really messy database with a lot of legacy leftovers and parts scattered all over under different categories, it’s not pretty. No tool will help you, unless you combine it with a pretty massive search in octoparts, mouser, arrow, digikey, etc. Parts selection is always the most complicated part of the design, at least for me. Often I have to talk to companies directly to understand what they have. Parts selection is a very highly valued skill on its own. On top of that many don’t speak English, so it’s a really hit or miss.