Running SimpleFOC on a BIGTREETECH S42B

I found this fairly low-cost all in one encoder/driver/MCU board for NEMA 17 stepper motors, and I’m thinking of replacing the stock firmware with a SimpleFOC based implementation.

It has an STM32F103CB onboard, with a pair of A4950 full bridge motor drivers which looks like it is pretty well supported. However, the rotation sensor is a TLE5012B, which looks like it has a currently unsupported communication protocol:

Data communications are accomplished with a bi-directional Synchronous Serial Communication (SSC) that is SPI-compatible. The sensor configuration is stored in registers, which are accessible by the SSC interface. Additionally four other interfaces are available with the TLE5012B: Pulse-Width-Modulation (PWM) Protocol, Short-PWM-Code (SPC) Protocol, Hall Switch Mode (HSM) and Incremental Interface (IIF). These interfaces can be used in parallel with SSC or alone.

Has anyone used one of these before? Any idea if it will end up working well with SimpleFOC?

Welcome @wjbuys. I can’t find a schematic for this board but bigtreetech have released source code. Looks like code is st/cmsis so would need to be translated to Arduino framework.

The spi code for sensor looks fairly standard but I’m no expert:

The pin used for motors, etc can be worked out from here

The code mentions stm32f0, so it’s possible this code isn’t for your board as you mention stm32f1. Perhaps there are two variants?

1 Like

Ah! Good find, that looks like it’s basically all I need. I did some sleuthing, and found a more up to date version of the firmware in a different repo: https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/tree/master/S42B/firmware/S42BV2.0

Looks like all it changes is to use the newer STM, and adds a CAN bus socket.

1 Like

I looked into it in a recent round-up of sensors I did. I think VESC now supports it. I concluded that the extra effort involved in dealing with the half-duplex SPI-compatible SSC wasn’t worth it compared to the other available chips. The PWM and IIF interfaces would be supported.

The firmware isn’t written for Arduino framework as far as I can tell, but the sensor code gives a fairly clear blueprint for reading an angle. I think the chances are pretty good to get SimpleFOC working on this board.

Nice find! If you have the time, please do let us know how it goes.

1 Like

Alas, it looks like those pins are not connected to the STM on this board, so I’ll have to make do with the SSC interface.

Hi, do you have any progress now? recently I am looking into TLE5012B, because it’s really cheap and high resolution~ but i only tested the UVW/ABZ port is ok, I didn’t test the SSC because my broken control board…

I just found this official Arduino library from Infineon. Going to give it a shot once I have the time, but looks promising.

That library looks useful. Particularly it looks as if you can ask it what the angular velocity is. Most other sensors only offer positional readings and then the simplefoc library has to do it’s best to work out the velocity (angle/time) which tends to be a bit noisy and thus needs velocity smoothing. If this sensor provides smooth/accurate velocity then it would be appealing to a lot of us!

Creating a new sensor class has become easier to do since SimpleFOC 2.0+ all you need to do is extend Sensor.cpp and implement getAngle(). But in this case I’d also try to implement getVelocity() as the hardware seems to offer a decent implementation.

I also made such board, it has MA730 sensor and support CAN bus.


It provides 3.5A current for each phase to drive the NEMA17 motor to run like a BLDC motor that reach 5000RPM. I don’t knw how to upload the pdf SCH file, it seems only support picture upload.

2 Likes