Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
af112f4
files from spi
ars-24 Jan 6, 2026
0973267
Revert "files from spi"
ars-24 Jan 6, 2026
18a9d91
adding spi files to new branch
ars-24 Jan 6, 2026
12cd064
Fixed all errors in compilation and added proper CMake linkage for PE…
Colin-Bickel Jan 9, 2026
441e9a0
Automatic CMake Format: Standardized formatting automatically
github-actions[bot] Jan 9, 2026
5e41de1
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 9, 2026
87f3a19
Merge branch 'main' into spi_new
dchansen06 Jan 9, 2026
ca5b392
Merge branch 'main' into spi_new
dchansen06 Jan 9, 2026
664c7ec
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 9, 2026
f5b812a
set up spi parameters for test + GR_SPI_Close()
horizon-ab Jan 13, 2026
30e9db8
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 13, 2026
ebf51bf
comment out opsi
horizon-ab Jan 13, 2026
aa056da
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 13, 2026
a3b5430
compiles
horizon-ab Jan 13, 2026
4a62792
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 13, 2026
977c595
blinky not working
horizon-ab Jan 13, 2026
dd84787
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 13, 2026
e087906
Add SWO configuration for G4PERTESTING launch configuration
dchansen06 Jan 13, 2026
407d704
Add Logomatic logging and update clock configuration
dchansen06 Jan 13, 2026
f132a18
Merge branch 'main' into spi_new
dchansen06 Jan 13, 2026
2411769
Changed print statements to LOGOMATIC
Colin-Bickel Jan 16, 2026
f4318f4
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
064f022
Co-authored-by: Colin-Bickel <Colin-Bickel@users.noreply.github.com>
ars-24 Jan 16, 2026
0ec8e56
Automatic Clang-Format: Standardized formatting automatically
github-actions[bot] Jan 16, 2026
cab7d46
Merge branch 'main' into spi_new
dchansen06 Jan 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
],
"command": "cmake --build build/${command:cmake.activeBuildPresetName} --target G4BLINKY"
},
{
"label": "CMake: configure and build G4PERTESTING",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"CMake: configure"
],
"command": "cmake --build build/${command:cmake.activeBuildPresetName} --target G4PERTESTING"
},
{
"label": "CMake: configure and build U5BLINKY",
"type": "shell",
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include("${platform_path}/STM32L476xG/chip.cmake")
include("${lib_path}/GlobalShare/common.cmake")
include("${lib_path}/Utils/CircularBuffer/circular-buffer-lib.cmake")
include("${lib_path}/cmake/gr-lib.cmake")
include("${lib_path}/FancyLayers-RENAME/SPI/spi.cmake")
include("${lib_path}/Utils/BitManipulations/bit-utils.cmake")

# Peripherals
Expand Down
3 changes: 1 addition & 2 deletions G4PERTESTING/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ target_sources(
Core/Src/gpio.c
Core/Src/i2c.c
Core/Src/main.c
Core/Src/spi.c
Core/Src/stm32g4xx_hal_msp.c
Core/Src/stm32g4xx_it.c
Core/Src/syscalls.c
Expand All @@ -46,6 +45,6 @@ target_sources(
Core/Src/usart.c
)

target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE)
target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE SPI_Lib)

target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc)
3 changes: 2 additions & 1 deletion G4PERTESTING/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ extern "C" {

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include <stdio.h>
#include <stdlib.h>
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
Expand Down
49 changes: 0 additions & 49 deletions G4PERTESTING/Core/Inc/spi.h

This file was deleted.

130 changes: 119 additions & 11 deletions G4PERTESTING/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
#include "fdcan.h"
#include "gpio.h"
#include "i2c.h"
#include "spi.h"
// #include "stm32g4xx_hal_ospi.h"
#include "tim.h"
#include "usart.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include "Logomatic.h"
#include "spi.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -61,6 +62,18 @@ void SystemClock_Config(void);

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* Enable ITM for SWO output */
static void ITM_Enable(void)
{
/* Enable TRC (Trace) */
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

/* Enable stimulus port 0 */
ITM->TER |= (1UL << 0);

/* Set trace control register */
ITM->TCR |= ITM_TCR_ITMENA_Msk;
}

/* USER CODE END 0 */

Expand All @@ -72,6 +85,11 @@ int main(void)
{

/* USER CODE BEGIN 1 */
static GR_SPI_Handler ex_handler;
static LL_SPI_InitTypeDef ex_config;
static GR_SPI_Pins ex_pins;
/*HAL_OSPI_HandleTypeDef hospi;
HAL_StatusTypeDef status;*/

/* USER CODE END 1 */

Expand All @@ -83,6 +101,7 @@ int main(void)
HAL_Init();

/* USER CODE BEGIN Init */
ITM_Enable();

/* USER CODE END Init */

Expand All @@ -101,10 +120,95 @@ int main(void)
MX_LPUART1_UART_Init();
MX_I2C2_Init();
MX_USART1_UART_Init();
MX_SPI3_Init();
// MX_SPI3_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
LOGOMATIC("Booted!\n");

ex_config.TransferDirection = LL_SPI_HALF_DUPLEX_TX;
ex_config.Mode = LL_SPI_MODE_MASTER;
ex_config.DataWidth = LL_SPI_DATAWIDTH_8BIT;
ex_config.ClockPolarity = LL_SPI_POLARITY_LOW;
ex_config.ClockPhase = LL_SPI_PHASE_1EDGE;
ex_config.NSS = LL_SPI_NSS_HARD_INPUT;
ex_config.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
ex_config.BitOrder = LL_SPI_LSB_FIRST;
ex_config.CRCCalculation = LL_SPI_CRCCALCULATION_ENABLE;
ex_config.CRCPoly = 0x1D;

ex_pins.SPIx = SPI1;
ex_pins.GPIOx = (GPIO_TypeDef **)(malloc(4 * sizeof(GPIO_TypeDef *)));
// All pins are in the A clock port
for (int i = 0; i < 4; i++) {
*(ex_pins.GPIOx + i) = GPIOA;
}
ex_pins.num_pins = 4;
ex_pins.pin_nums = (uint32_t *)malloc(4 * sizeof(int));
ex_pins.pin_nums[0] = LL_GPIO_PIN_7; // COPI
ex_pins.pin_nums[1] = LL_GPIO_PIN_6; // CIPO
ex_pins.pin_nums[2] = LL_GPIO_PIN_5; // SCK
ex_pins.pin_nums[3] = LL_GPIO_PIN_4; // NSS
ex_pins.alternate_function_number = 5;

GR_SPI_Initialize(&ex_handler, &ex_config, &ex_pins);

LOGOMATIC("-= SPI + GPIO Init Verification (Measured | Expected) =-\n");
/* ---------------- SPI ---------------- */
LOGOMATIC("TransferDirection = %lu | %lu\n", LL_SPI_GetTransferDirection(ex_pins.SPIx), ex_config.TransferDirection);
LOGOMATIC("Mode = %lu | %lu\n", LL_SPI_GetMode(ex_pins.SPIx), ex_config.Mode);
LOGOMATIC("DataWidth = %lu | %lu\n", LL_SPI_GetDataWidth(ex_pins.SPIx), ex_config.DataWidth);
LOGOMATIC("ClockPolarity = %lu | %lu\n", LL_SPI_GetClockPolarity(ex_pins.SPIx), ex_config.ClockPolarity);
LOGOMATIC("ClockPhase = %lu | %lu\n", LL_SPI_GetClockPhase(ex_pins.SPIx), ex_config.ClockPhase);
LOGOMATIC("NSS = %lu | %lu\n", LL_SPI_GetNSSMode(ex_pins.SPIx), ex_config.NSS);
LOGOMATIC("BaudRate = %lu | %lu\n", LL_SPI_GetBaudRatePrescaler(ex_pins.SPIx), ex_config.BaudRate);
LOGOMATIC("BitOrder = %lu | %lu\n", LL_SPI_GetTransferBitOrder(ex_pins.SPIx), ex_config.BitOrder);
LOGOMATIC("CRC Enable = %lu | 1\n", LL_SPI_IsEnabledCRC(ex_pins.SPIx));
LOGOMATIC("CRC Polynomial = 0x%lx | 0x%lx\n", ex_pins.SPIx->CRCPR, ex_config.CRCPoly);
LOGOMATIC("SPI Enable = %lu | 1\n", LL_SPI_IsEnabled(ex_pins.SPIx));

uint32_t spi_clk_en = 0;
if (ex_handler.pins->SPIx == SPI1) {
spi_clk_en = LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_SPI1);
} else if (ex_handler.pins->SPIx == SPI2) {
spi_clk_en = LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_SPI2);
} else if (ex_handler.pins->SPIx == SPI3) {
spi_clk_en = LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_SPI3);
}
LOGOMATIC("SPI Clock Enable = %lu | 1\n", spi_clk_en);
/* ---------------- GPIO CLOCKS ---------------- */
for (int i = 0; i < ex_pins.num_pins; i++) {
uint32_t clk_en = 0;

if (ex_pins.GPIOx[i] == GPIOA) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOA);
} else if (ex_pins.GPIOx[i] == GPIOB) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOB);
} else if (ex_pins.GPIOx[i] == GPIOC) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOC);
} else if (ex_pins.GPIOx[i] == GPIOD) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOD);
} else if (ex_pins.GPIOx[i] == GPIOE) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOE);
} else if (ex_pins.GPIOx[i] == GPIOF) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOF);
} else if (ex_pins.GPIOx[i] == GPIOG) {
clk_en = LL_AHB2_GRP1_IsEnabledClock(LL_AHB2_GRP1_PERIPH_GPIOG);
}

LOGOMATIC("GPIO Clock [%p] = %lu | 1\n", (void *)ex_pins.GPIOx[i], clk_en);
}
/* ---------------- GPIO MODE + AF ---------------- */
for (int i = 0; i < ex_pins.num_pins; i++) {
uint32_t pin = ex_pins.pin_nums[i];

LOGOMATIC("GPIO[%d] Mode = %lu | %lu\n", pin, LL_GPIO_GetPinMode(ex_pins.GPIOx[i], pin), LL_GPIO_MODE_ALTERNATE);

LOGOMATIC("GPIO[%d] AF = %lu | %lu\n", pin, (ex_pins.pin_nums[i] < LL_GPIO_PIN_8) ? LL_GPIO_GetAFPin_0_7(ex_pins.GPIOx[i], pin) : LL_GPIO_GetAFPin_8_15(ex_pins.GPIOx[i], pin),
ex_pins.alternate_function_number);
}
LOGOMATIC("-= End Verification =-\n");

GR_SPI_Close(&ex_handler);
/* USER CODE END 2 */

/* Infinite loop */
Expand All @@ -117,11 +221,16 @@ int main(void)
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_Delay(1000);
LOGOMATIC("Blinking!\n");

/* USER CODE BEGIN 3 */
}
}

/* void test_spi_initialize(GR_SPI_Handler* handle, LL_SPI_InitTypeDef* config,
GR_SPI_Pins* pin_config){ if(GR_SPI_Initialize(&handle, &config, &pin_config)
} */

/**
* @brief System Clock Configuration
* @retval None
Expand All @@ -132,13 +241,13 @@ void SystemClock_Config(void)
while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {
}
LL_PWR_EnableRange1BoostMode();
LL_RCC_HSE_Enable();
/* Wait till HSE is ready */
while (LL_RCC_HSE_IsReady() != 1) {
LL_RCC_HSI_Enable();
/* Wait till HSI is ready */
while (LL_RCC_HSI_IsReady() != 1) {
}

LL_RCC_HSE_EnableCSS();
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2);
LL_RCC_HSI_SetCalibTrimming(64);
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2);
LL_RCC_PLL_EnableDomain_SYS();
LL_RCC_PLL_Enable();
/* Wait till PLL is ready */
Expand All @@ -159,14 +268,14 @@ void SystemClock_Config(void)
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_SetSystemCoreClock(160000000);
LL_SetSystemCoreClock(170000000);

/* Update the time base */
if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) {
// status = ERROR;
Error_Handler();
}
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */
Expand All @@ -183,7 +292,6 @@ void Error_Handler(void)
__disable_irq();
while (1) {
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
Expand Down
Loading
Loading