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 made a simple adapter PCB to match the required pins of the NUCLEO G431 board to the Arduino 2560 footprint . The PCB was made using the "toner transfer" method, that worked very well:

And here it is fitted to the Mini's existing ECU:

I've done about 100 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).

Update 25th May 2020

With the slight relaxation of the Coronavirus lockdown, I've been able to do a further couple of hundred miles using the STM32 CPU and have discovered some of the negative aspects of this CPU compared to Arduino. Most importantly, it was showing a regular and sustained number of trigger wheel sync errors, coupled with an occasional nasty misfire. There's a facility for the ECU to self-tune the VE Map according to the air-fuel ratio (AFR) measurements as you drive along. The AFR correction data is periodically saved to non-volatile memory (NVM) and restored when the ECU is next switched on. In the STM32, there's no separate EEPROM as in the Arduino so the NVM is implemented using the main Flash memory. I've since discovered that while writing to Flash, programme execution is stalled, hence it can't keep up with the trigger wheel pulses, resulting in the sync errors. There's no simple solution to this in software, so I'm looking at an external I2C EEPROM for version 2 of the ECU design. In the meantime, I've simply inhibited the save to NVM process in the configuration data. In practise, it doesn't affect the overall improvements that the STM32 has provided: With the improved CPU speed allowing more sophisticated algorithms, the responsiveness and drivability of the engine is much the same for any modern 16V and the mixture control is greatly improved over the Arduino.

 

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.