I'm trying to learn stm32cube framework :sadge:

This commit is contained in:
2025-12-06 22:56:56 +01:00
parent 5a67e90143
commit 2d564b2670
11 changed files with 60678 additions and 26 deletions

18
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/hdd/GiTea-REPO/MD1200/PC_CONTROL_CODE/CPP/noInflux",
"program": "/hdd/GiTea-REPO/MD1200/PC_CONTROL_CODE/CPP/noInflux/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

BIN
58FO8iY.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -1 +1,2 @@
testing testing
cpp

Binary file not shown.

View File

@@ -8,10 +8,10 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env:genericSTM32F103C6] [env:bluepill_f103c6]
platform = ststm32 platform = ststm32
board = genericSTM32F103C6 board = bluepill_f103c6
framework = arduino framework = stm32cube
lib_deps = adafruit/DHT sensor library@^1.4.6 lib_deps = adafruit/DHT sensor library@^1.4.6
debug_tool = stlink debug_tool = stlink
upload_protocol = stlink upload_protocol = stlink

130
STM32_CONTROL/src/main.cpp Normal file
View File

@@ -0,0 +1,130 @@
#include <stm32f1xx_hal.h>
UART_HandleTypeDef huart1;
// --- Function prototypes ---
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
// --- Optional RX buffer for interrupt ---
uint8_t rx_byte;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
char msg[] = "UART started at 38400 baud\r\n";
// Send a startup message
HAL_UART_Transmit(&huart1, (uint8_t*)msg, sizeof(msg)-1, HAL_MAX_DELAY);
// Start interrupt-based receive of one byte
HAL_UART_Receive_IT(&huart1, &rx_byte, 1);
while (1)
{
// Send a heartbeat message every second
char heartbeat[] = "Ping\r\n";
HAL_UART_Transmit(&huart1, (uint8_t*)heartbeat, sizeof(heartbeat)-1, HAL_MAX_DELAY);
HAL_Delay(1000);
}
}
// -----------------------------------------------------------------------------
// Error handler
// -----------------------------------------------------------------------------
void Error_Handler(void)
{
while (1) { }
}
// -----------------------------------------------------------------------------
// UART1 initialization (38400 baud)
// -----------------------------------------------------------------------------
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 38400;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
}
// -----------------------------------------------------------------------------
// GPIO for UART1 pins (PA9 TX, PA10 RX)
// -----------------------------------------------------------------------------
static void MX_GPIO_Init(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
// PA9 -> USART1_TX (Alternate Function Push-Pull)
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// PA10 -> USART1_RX (Input)
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
// -----------------------------------------------------------------------------
// Interrupt callback for UART receive
// -----------------------------------------------------------------------------
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART1) {
// Echo received byte back
HAL_UART_Transmit(&huart1, &rx_byte, 1, HAL_MAX_DELAY);
// Re-enable reception of next byte
HAL_UART_Receive_IT(&huart1, &rx_byte, 1);
}
}
// -----------------------------------------------------------------------------
// Basic system clock (HSE not required for 38400 UART)
// -----------------------------------------------------------------------------
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_SYSCLK |
RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
}

View File

@@ -1,22 +0,0 @@
#include <Arduino.h>
// UART2 (PA3 = RX, PA2 = TX)
HardwareSerial mdSerial(PA10, PA9);
// HardwareSerial sigma(PA9, )
void setup() {
mdSerial.begin(38400);
}
void loop() {
mdSerial.write("skibidi");
delay(5000); // wait before next loop
}

View File

@@ -0,0 +1,24 @@
// #include <Arduino.h>
#include <stm32f1xx_hal.h>
#define PIN_SERIAL3_RX PB11
#define PIN_SERIAL3_TX PB10
// UART2 (PA3 = RX, PA2 = TX)
HardwareSerial Serial1(PA10, PA9);
// HardwareSerial sigma(PA9, )
void setup() {
Serial1.begin(38400);
}
void loop() {
Serial1.write("skibidi");
delay(5000); // wait before next loop
}

File diff suppressed because one or more lines are too long