Font Size Selector
AAAAA
Header

Technology, old cars, & other stuff...

00:00:00

Saturday 28 January

ARM Cortex STM32 ECU Software

I've been wanting to expand the code in my ECU for quite a while but, although it's a brilliant device, I decided the Arduino 2560 is too limited as a basis for future developments - there's little spare CPU time, it has too few 16-bit timers and insufficient SRAM, for example. I also felt the Arduino IDE is no longer adequate for more complex developments as it lacks a comprehensive debugging capability.

I've been really impressed by the STM32 ARM Cortex NUCLEO boards and the CubeMX IDE from ST Microelectronics, so decided this was the way to go for developing the ECU software. I ported (as in completely rewritten) the existing ECU code from the Arduino C++ code into STM32 / CubeMX C code - IMHO C is better for embedded applications than C++. The NUCLEO-F411RE board would have been perfect for the ECU application, but I wanted to stick to the NUCLEO-32 board format (which is a 32 pin device with more limited IO) to ensure the board could fit into an existing ECU, so plumped for the NUCLEO G431KB. Once running on the bench, I did some performance tests to compare with the Arduino. Here's how the cyclic functions (where the fuel calcs, 3D interpolation, ignition, auto AFR correction, etc are perfromed) matched up - the execution time is shown for each, in milli-seconds...

Arduino 2560 NUCLEO-G431KB
1.76 0.16

You can see from the data that the G431KB is stonkingly quick and it has just enough IO so that I could implement the full code but limited to paired injectors used in semi-sequential mode. The main ECU board had to be modified to limit the signals going into the microcontroller to 3.3V and a small adapter board was needed to match the NUCLEO-32 pins to the Arduino 2560 format:

 

I used the CubeMX configuration tool to configure the IO pins and peripherals (ADCs, USARTs, Timers, PWM, etc). Here's the adapter board fitted to an ECU installed in the Mini:

I've done about 10 miles with the STM32 ECU and, so far, it's working great. It seems to start the engine easier, idle seems more stable and accelerating to high RPM seems smoother. There's no changes to the functionality over the latest Arduino code but if there is a real improvement (and not my imagination) then I'd say it's down to a number of factors:

  • the ADC's have better resolution (12 bit vs 10 bit)
  • the injector pulse timing uses a 16-bit timer instead of 8-bit, allowing a more accurate pulse width
  • from bench testing, the crankshaft position measurement is more accurate and there's far less latency from measurement to output

The initial STM32 ECU application code is here but watch out for further developments in the coming months. (Note that the CubeMX/HAL initialisation code and drivers are not included).

Privacy Notice

The elements of this website developed by Just Technology uses cookies to store user settings such as the requested font-size to enhance the usability of the site. For reqistered users, cookies are also used to identify the user's logged-in status.

The elements of this website developed by Just Technology do not attempt to access cookies sent to your computer by other websites you have visited nor will it try to obtain any other information from your computer for use by Just Technology or for passing on to any other party.

This website uses 3rd party software from Disqus, Twitter, and Facebook. The privacy policy of these vendors is therefore applicable to any facilities provided by these 3rd parties. Just Technology cannot provide any statement regarding protection of your privacy with respect to the facilities provided by these 3rd parties and cannot accept any responsibility for the way that any facility provided by them interacts with your computer or uses the information obtained from you or your computer.