Yeah it’s hard to compare different versions.
You would need to create your minimal 2.3.1
The SVPWM without atan2 PR is now available on the dev branch.
With this branch, and if you are not using the MPU6050 library, you should see a reduction of the memory usage (and increased speed).
I can use the SVPWM mode, even if I don’t have low_current sense?
Will try it on my splitboard…
Svpwm is just a modulation type, it allows you to reach higher voltages.
But the size will reduce even if you don’t use svpwm.
I came across this, it also has some good hints for you.
I tested the platformio inspect tool and I was surprised to see that spi_init uses 912bytes although I am not using SPI. And if I disable the SPI HAL Module the compiler throws errors then.
Another
[EDIT] probably this has to be used with the minimal project branch
Thanks for the links, they will keep me occupied for a while.
As usual, I only understand 10% of it. So far I have written the hal_conf_custom.h
and placed it in the program file folder.
The compiler throws wild errors, beginning with this one:
...\system/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h... HAL_StatusTypeDef does not name a type
But this is the part were HAL-functions are initialized or not:
/* Initialization and de-initialization functions ******************************/
HAL_StatusTypeDef HAL_Init(void);
HAL_StatusTypeDef HAL_DeInit(void);
There seems to be a bug or missing declaration, but I’m at my wits end.
But what did you place there ?
More or less, the same I found in your link:
I think, I need the QSPI module for SWD and the TIM module for motor-timing?
The funny thing is, even when I outcomment all the modules (create an empty file so to speak), the compiler throws the same errors.
//#define HAL_ADC_MODULE_DISABLED
#define HAL_I2C_MODULE_DISABLED
#define HAL_RTC_MODULE_DISABLED
#define HAL_SPI_MODULE_DISABLED
//#define HAL_TIM_MODULE_DISABLED
#define HAL_DAC_MODULE_DISABLED
#define HAL_EXTI_MODULE_DISABLED
#define HAL_ETH_MODULE_DISABLED
#define HAL_SD_MODULE_DISABLED
//#define HAL_QSPI_MODULE_DISABLED
Baby steps, only disable I2C or SPI for now.
It is the other way round, it seems
I can disable all other modules, except SPI and I2C:
/*----------------------------------------------------------------------------
* Deselect not required HAL-modules
*----------------------------------------------------------------------------*/
//#define HAL_ADC_MODULE_DISABLED
//#define HAL_I2C_MODULE_DISABLED
#define HAL_RTC_MODULE_DISABLED
//#define HAL_SPI_MODULE_DISABLED
//#define HAL_TIM_MODULE_DISABLED
#define HAL_DAC_MODULE_DISABLED
#define HAL_EXTI_MODULE_DISABLED
#define HAL_ETH_MODULE_DISABLED
#define HAL_SD_MODULE_DISABLED
//#define HAL_QSPI_MODULE_DISABLED
The code is 2% or 1.1k Bytes smaller this way.
To make it work, I’ve placed the lines in the file variant_generic.h in:
...AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\variants\STM32F0xx\F030C8T
…not the best solution, but the quickest result
With all these tricks, I could shrink it to 75% flash now (from 81%). Maybe I can fit I2C/bluetooth now…
But the whole concept seems crazy to me: Like the user is planning a weekend-trip with a motorcycle, but the package list contains the whole household…
I imagine disabling SPI and I2C would work with the minimal branch of SimpleFOC then.
Do you think the minimal branch doesn’t use the STM32duino-library for compilation?
That’s hard to believe.
And when it compiles on the lib, it’s using the same full_house of HAL-modules
I mean the minimal branch + disabling the modules
It’s hard to believe you would have to remove files from stm32duino as well
The comments indicate there is another usecase for XX_HandleTypeDef
Maybe that’s why disabling the HAL_module doesn’t work?
// in SPI.h
// Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk.
SPI_HandleTypeDef *getHandle(void)
// in Wire.h
// Could be used to mix Arduino API and STM32Cube HAL API (ex: DMA). Use at your own risk.
I2C_HandleTypeDef *getHandle(void)
I think that means you can use those handles with STM HAL APIs, but it can break the STM32Duino side.
I did something in platformio that seems to work thanks to the good naming convention in SimpleFOC.
I added the following in platformio.ini
:
extra_scripts = pre:filter_src.py
[Simple FOC]
custom_motor = BLDC
custom_driver = 6PWM
custom_current = LowsideCurrentSense
custom_platform = stm32
custom_sensor = HallSensor
And a filter_src.py
script:
Import("env")
filters = [{"library":"Simple FOC", "option":"motor","values":["BLDC","Stepper"],"enable":False},
{"library":"Simple FOC", "option":"driver","values":["2PWM","3PWM","4PWM","6PWM"],"enable":False},
{"library":"Simple FOC", "option":"current","values":["None","GenericCurrentSense","InlineCurrentSense","LowsideCurrentSense"],"enable":False},
{"library":"Simple FOC", "option":"platform","values":["stm32","gd32","esp32","esp8266","rp2040","teensy","atmega","samd","due","nrf52","portenta","renesas"],"enable":False},
{"library":"Simple FOC", "option":"sensor","values":["None","Encoder","MagneticSensorSPI","MagneticSensorI2C","MagneticSensorAnalog","MagneticSensorPWM","HallSensor"],"enable":False}]
def skip_from_build(node):
"""
`node.name` - a name of File System Node
`node.get_path()` - a relative path
`node.get_abspath()` - an absolute path
to ignore file from a build process, just return None
"""
for filter in filters:
# Library name is in the path
if filter["library"] in node.get_path():
# there was a valid option
if filter["enable"]:
# for each value in the list except the selected option (removed)
for value in filter["values"]:
# if value is file name
if value in node.name:
# Return None for exclude
return None
return node
# Read value from other environments
config = env.GetProjectConfig()
for filter in filters:
if config.has_section(filter["library"]):
if config.has_option(filter["library"],"custom_" + filter["option"]):
value = config.get(filter["library"],"custom_" + filter["option"])
if value in filter["values"]:
filter["values"].remove(value)
filter["enable"] = True
# Register callback
env.AddBuildMiddleware(skip_from_build, "*")
So the script skips the files that contain a Motor type, Driver type, Platform or sensor type other than the one selected in platformio.ini. Maybe it’s a bit complicated.
@runger is it useful for the library ?
[EDIT] I abstracted the code to simplify.
[EDIT] Added Current sense and None option for current sense and sensor
Does it work the same as the minimal_branch? I was wondering if it works with the latest library?
I’d add current_sense
and also allow “none” as an option for open-loop or xy_only test .
The minimal branch is something you need to prepare manually, it’s not available for each release.
What I did is something that will skip the files during the build, and should work with any release. But it’s a very stupid algorithm
I am not sure it’s really useful in terms of binary size, but anytime I change the platformio.ini file I have to compile all the files again, so this could save me some time.
If the platformio section is missing, or some custom option is missing, it will just skip it.
But None could also make sense. Also I am not managing multiple values, not sure if it would be useful.
So here is one of the strengths of Platformio for you, it’s a bit complicated but you can automate a lot of stuff.
That’s not the best argument to start with PIO
ArduinoIDE already compiles only one file. No need for a filtering script…
PIO also compiles to one file.
But I am switching between stm32 and gd32, and between branches, all the time.
PIO is automatically downloading the branch of the library, and compiles all the files again.