bmd-studio / stm32-for-vscode

STM32 extension for working with STM32 and CubeMX in VSCode
MIT License
207 stars 27 forks source link

Custom makefile rules #109

Closed bonnee closed 2 years ago

bonnee commented 2 years ago

Hi! Is there a way to create custom rules in the makefile? My use case is that I need to flash the firmware over CAN-bus and I have a custom command set in place for that. Having the possibility to handle that in the makefile would streamline my workflow significantly.

federico-carbone commented 2 years ago

That would be great

jortbmd commented 2 years ago

Could you maybe give me and example what you would implement in the makefile? I have thus far not implemented something like this, because it is usually doable by using the tasks in VSCode itself. However if there is a need for this from a CI/CD perspective or that is not easily doable in a VSCode task. I might dedicate some time to this.

federico-carbone commented 2 years ago

Personally I would like to create two different binaries, using two different linker scripts, then convert the second one in a .srec format in order to flash the board using openblt with canbus

federico-carbone commented 2 years ago

Actually I think that you could just add a "user code section" which is not overwrite when the makefile is created

bonnee commented 2 years ago

My use case is that I have some custom rules like this:

can:
    ip link set can0 type can bitrate 1000000
    ip link set can0 up

$(BUILD_DIR)/$(TARGET).srec: $(BUILD_DIR)/$(TARGET).bin
    bin2srec -a 0x8004000 -i $<-o $@

canflash: $(BUILD_DIR)/$(TARGET).srec
    <flash via can command> $<

That are used to flash a microcontroller through CAN-bus, by using a special bootloader. I would like to not have the rules overwritten every time I issue a build though vscode. I could maybe implement the rules as vscode tasks but I would like to execute them on an headless system. Moreover, some rules are required to be launched as root. I know this is a niche use case, but the possibility to add rules to the makefile could come useful to others as well.

federico-carbone commented 2 years ago

I made a pull request that should solve this issue: #111

jortbmd commented 2 years ago

Thanks so much for the pull request! Much appreciated, however due to the fact I want to let both makefiles be completely generatable this does not fit within the overall design. However I did implement the feature, by adding it to the configuration file. You can add a makefile rule in the configuration files as follows:

customMakefileRules:
 - command: sayhello
   rule: echo "hello"
   dependsOn: $(BUILD_DIR)/$(TARGET).elf  # can be left out    

I hope this is what you were envisioning. If you need something else please let me know! This feature is already implemented in the new version (3.2.2).

jortbmd commented 2 years ago

Closing it as I have not received any further comments or bugs. Should any arise feel free te create a new issue or re-open this issue.