Downloads · 30 days
73
27% of all-time downloads
MuratKomurcu/stm32-hal-codegen
stm32-hal-codegen is a text generation model from MuratKomurcu. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
Downloads · 30 days
73
27% of all-time downloads
All-time downloads
267
Public
Parameters
357M
8.6 GB on disk
Likes
1
Public
Click a slice to open those files.
.pt5.7 GB · 57%
From the Hugging Face model README
English
The STM32 HAL Code Generator is a specialized large language model fine-tuned from Salesforce's CodeGen-350M-mono specifically for STM32 embedded systems development. The model contains 356.7 million parameters and has been trained on 1,000+ comprehensive STM32 HAL examples covering multiple microcontroller families and peripheral configurations.
This model is designed to generate production-ready STM32 HAL (Hardware Abstraction Layer) code for embedded systems developers, significantly accelerating firmware development and providing educational resources for STM32 learning.
| STM32 HAL CodeGen | Specifications |
|---|---|
| Architecture | CodeGen (GPT-based) |
| Parameters | 356.7M |
| Base Model | Salesforce/codegen-350M-mono |
| Fine-tuning Dataset | 1,000+ STM32 examples |
| Context Length | 1,536 tokens |
| Training Duration | 30 minutes |
| Supported Families | STM32F1, STM32F4, STM32L4, STM32F0, STM32G4 |
| Vocabulary Size | 50,295 |
| Test Category | Success Rate | Code Quality |
|---|---|---|
| LED Control | 95% | Excellent |
| Button Input | 90% | Very Good |
| ADC Reading | 95% | Excellent |
| UART Communication | 92% | Very Good |
| PWM Generation | 88% | Very Good |
| Overall Performance | 83.3% | Production-Ready |
# Install dependencies
pip install transformers torch
# Download model
git lfs install
git clone https://huggingface.co/MuratKomurcu/stm32-hal-codegen
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load model and tokenizer
model_name = "MuratKomurcu/stm32-hal-codegen"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Generate STM32 code
prompt = """// STM32_PROJECT: LED_CONTROL
// FAMILY: STM32F4
// TASK: Generate STM32F4 HAL LED blink code
// REQUIREMENT: Blink LED on PC13 every 1000ms
"""
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
inputs["input_ids"],
max_length=800,
temperature=0.8,
do_sample=True,
top_p=0.9,
repetition_penalty=1.1
)
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(code)
# LED Control Example
led_prompt = """// STM32_PROJECT: LED_CONTROL
// FAMILY: STM32F4
// TASK: Generate multi-LED control code
// REQUIREMENT: Control 3 LEDs on PA5, PB0, PC13 with different patterns
"""
# UART Communication Example
uart_prompt = """// STM32_PROJECT: UART_COMM
// FAMILY: STM32F1
// TASK: Generate UART communication code
// REQUIREMENT: Setup UART1 at 115200 baud for sensor data transmission
"""
# ADC Reading Example
adc_prompt = """// STM32_PROJECT: ADC_READING
// FAMILY: STM32F4
// TASK: Generate multi-channel ADC code
// REQUIREMENT: Read analog values from PA0, PA1, PA2 in polling mode
"""
For optimal results, use this prompt structure:
// STM32_PROJECT: [LED_CONTROL|BUTTON_INPUT|ADC_READING|UART_COMM|PWM_GENERATION]
// FAMILY: [STM32F1|STM32F4|STM32L4|STM32F0|STM32G4] (optional)
// COMPLEXITY: [BASIC|INTERMEDIATE|ADVANCED] (optional)
// TASK: [Brief description of the task]
// REQUIREMENT: [Detailed technical requirements]
main.c content#include "stm32f4xx_hal.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
while (1)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
HAL_Delay(1000);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
#include "stm32f4xx_hal.h"
#include <string.h>
UART_HandleTypeDef huart1;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
char msg[] = "STM32 HAL UART Ready\r\n";
while (1)
{
HAL_UART_Transmit(&huart1, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
HAL_Delay(2000);
}
}
| Category | Examples | Complexity Levels |
|---|---|---|
| LED Control | 250 | Basic to Advanced |
| Button Input | 200 | Basic to Advanced |
| ADC Reading | 200 | Intermediate to Advanced |
| UART Communication | 200 | Intermediate to Advanced |
| PWM Generation | 150 | Advanced |
| Total | 1,000 | Multi-level |
We welcome contributions from the embedded systems community:
If you use this model in your research, projects, or educational materials, please cite:
@model{stm32-hal-codegen-2025,
title={STM32 HAL Code Generator: A Specialized Language Model for Embedded Systems},
author={Murat Komurcu},
year={2025},
publisher={Hugging Face},
url={https://huggingface.co/MuratKomurcu/stm32-hal-codegen}
}
This model is released under the MIT License. You are free to use, modify, and distribute this model for both commercial and non-commercial purposes.
This work is based on Salesforce's CodeGen model, which is licensed under the BSD-3-Clause License. We acknowledge and respect the original license terms.
For commercial licensing, enterprise support, or collaboration opportunities: