tl++ works now, unchecked dma or whatever
This commit is contained in:
1481
.metadata/.ide.log
1481
.metadata/.ide.log
File diff suppressed because one or more lines are too long
@@ -890,3 +890,57 @@ Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||
|
||||
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-10-13 14:21:59.450
|
||||
!MESSAGE Started RMI Server, listening on port 41337
|
||||
!SESSION 2025-10-13 14:55:51.990 -----------------------------------------------
|
||||
eclipse.buildId=Version 1.19.0
|
||||
java.version=21.0.3
|
||||
java.vendor=Eclipse Adoptium
|
||||
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
|
||||
Command-line arguments: -os linux -ws gtk -arch x86_64
|
||||
|
||||
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 4 4 2025-10-13 14:55:58.181
|
||||
!MESSAGE CubeMX plugin appears to be active, Log4j initialization might be too late.
|
||||
|
||||
!ENTRY com.st.stm32cube.ide.mcu.informationcenter 1 1 2025-10-13 14:55:58.181
|
||||
!MESSAGE Log4j2 initialized with config file /home/ja/st/Home/.metadata/.log4j2.xml
|
||||
|
||||
!ENTRY com.st.stm32cube.ide.mcu.ide 1 1 2025-10-13 14:56:04.995
|
||||
!MESSAGE Started RMI Server, listening on port 41337
|
||||
|
||||
!ENTRY org.eclipse.ui 4 0 2025-10-13 15:15:27.871
|
||||
!MESSAGE Unhandled event loop exception
|
||||
!STACK 0
|
||||
java.lang.NullPointerException: Cannot invoke "org.eclipse.ui.IWorkbenchWindow.getShell()" because the return value of "org.eclipse.ui.IWorkbench.getActiveWorkbenchWindow()" is null
|
||||
at com.st.stm32cube.common.mx.oss.core.awtswtbridge.AwtEnvironment.getShell(AwtEnvironment.java:281)
|
||||
at com.st.stm32cube.common.mx.oss.core.awtswtbridge.SwtInputBlocker.block(SwtInputBlocker.java:98)
|
||||
at com.st.stm32cube.common.mx.oss.core.awtswtbridge.AwtEnvironment.invokeAwt(AwtEnvironment.java:179)
|
||||
at com.st.stm32cube.common.mx.oss.core.awtswtbridge.EmbeddedSwingComposite$3.widgetDisposed(EmbeddedSwingComposite.java:244)
|
||||
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:140)
|
||||
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
|
||||
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5855)
|
||||
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1617)
|
||||
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1643)
|
||||
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1622)
|
||||
at org.eclipse.swt.widgets.Widget.release(Widget.java:1394)
|
||||
at org.eclipse.swt.widgets.Control.release(Control.java:4753)
|
||||
at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:1560)
|
||||
at org.eclipse.swt.widgets.Canvas.releaseChildren(Canvas.java:279)
|
||||
at org.eclipse.swt.widgets.Decorations.releaseChildren(Decorations.java:503)
|
||||
at org.eclipse.swt.widgets.Shell.releaseChildren(Shell.java:3435)
|
||||
at org.eclipse.swt.widgets.Widget.release(Widget.java:1401)
|
||||
at org.eclipse.swt.widgets.Control.release(Control.java:4753)
|
||||
at org.eclipse.swt.widgets.Widget.dispose(Widget.java:575)
|
||||
at org.eclipse.swt.widgets.Shell.dispose(Shell.java:3352)
|
||||
at org.eclipse.swt.widgets.Display.release(Display.java:4573)
|
||||
at org.eclipse.swt.graphics.Device.dispose(Device.java:276)
|
||||
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:168)
|
||||
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
|
||||
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
|
||||
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:668)
|
||||
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
|
||||
at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
|
||||
at org.eclipse.equinox.launcher.Main.main(Main.java:1454)
|
||||
|
||||
@@ -24,3 +24,4 @@
|
||||
*** SESSION Sep 30, 2025 16:10:38.815 ------------------------------------------
|
||||
*** SESSION Oct 06, 2025 14:00:17.912 ------------------------------------------
|
||||
*** SESSION Oct 13, 2025 14:21:51.496 ------------------------------------------
|
||||
*** SESSION Oct 13, 2025 14:55:57.07 -------------------------------------------
|
||||
|
||||
Binary file not shown.
@@ -1,11 +1,17 @@
|
||||
14:52:33 **** Incremental Build of configuration Debug for project TrafficLightsPlusPlus ****
|
||||
15:13:41 **** Incremental Build of configuration Debug for project TrafficLightsPlusPlus ****
|
||||
make -j8 all
|
||||
arm-none-eabi-g++ "../Core/Src/main.cpp" -mcpu=cortex-m4 -std=gnu++14 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"
|
||||
arm-none-eabi-g++ -o "TrafficLightsPlusPlus.elf" @"objects.list" -mcpu=cortex-m4 -T"/home/ja/st/Home/TrafficLightsPlusPlus/STM32F429ZITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TrafficLightsPlusPlus.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
|
||||
/home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.linux64_1.0.0.202410170706/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/stm32f4xx_it.o: in function `DMA2D_IRQHandler':
|
||||
/home/ja/st/Home/TrafficLightsPlusPlus/Debug/../Core/Src/stm32f4xx_it.c:203:(.text.DMA2D_IRQHandler+0x10): undefined reference to `hdma2d'
|
||||
collect2: error: ld returned 1 exit status
|
||||
make: *** [makefile:92: TrafficLightsPlusPlus.elf] Error 1
|
||||
"make -j8 all" terminated with exit code 2. Build might be incomplete.
|
||||
Finished building target: TrafficLightsPlusPlus.elf
|
||||
|
||||
arm-none-eabi-size TrafficLightsPlusPlus.elf
|
||||
arm-none-eabi-objdump -h -S TrafficLightsPlusPlus.elf > "TrafficLightsPlusPlus.list"
|
||||
text data bss dec hex filename
|
||||
9328 8 1832 11168 2ba0 TrafficLightsPlusPlus.elf
|
||||
Finished building: default.size.stdout
|
||||
|
||||
Finished building: TrafficLightsPlusPlus.list
|
||||
|
||||
|
||||
14:52:33 Build Failed. 2 errors, 0 warnings. (took 171ms)
|
||||
15:13:41 Build Finished. 0 errors, 0 warnings. (took 434ms)
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
14:52:33 **** Incremental Build of configuration Debug for project TrafficLightsPlusPlus ****
|
||||
15:13:41 **** Incremental Build of configuration Debug for project TrafficLightsPlusPlus ****
|
||||
make -j8 all
|
||||
arm-none-eabi-g++ "../Core/Src/main.cpp" -mcpu=cortex-m4 -std=gnu++14 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"
|
||||
arm-none-eabi-g++ -o "TrafficLightsPlusPlus.elf" @"objects.list" -mcpu=cortex-m4 -T"/home/ja/st/Home/TrafficLightsPlusPlus/STM32F429ZITX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TrafficLightsPlusPlus.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group
|
||||
/home/ja/st/stm32cubeide_1.19.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.linux64_1.0.0.202410170706/tools/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld: ./Core/Src/stm32f4xx_it.o: in function `DMA2D_IRQHandler':
|
||||
/home/ja/st/Home/TrafficLightsPlusPlus/Debug/../Core/Src/stm32f4xx_it.c:203:(.text.DMA2D_IRQHandler+0x10): undefined reference to `hdma2d'
|
||||
collect2: error: ld returned 1 exit status
|
||||
make: *** [makefile:92: TrafficLightsPlusPlus.elf] Error 1
|
||||
"make -j8 all" terminated with exit code 2. Build might be incomplete.
|
||||
Finished building target: TrafficLightsPlusPlus.elf
|
||||
|
||||
arm-none-eabi-size TrafficLightsPlusPlus.elf
|
||||
arm-none-eabi-objdump -h -S TrafficLightsPlusPlus.elf > "TrafficLightsPlusPlus.list"
|
||||
text data bss dec hex filename
|
||||
9328 8 1832 11168 2ba0 TrafficLightsPlusPlus.elf
|
||||
Finished building: default.size.stdout
|
||||
|
||||
Finished building: TrafficLightsPlusPlus.list
|
||||
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
// Feeling sneaky.
|
||||
extern "C" {
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
}
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
#include <stdbool.h>
|
||||
|
||||
enum class TrafficState { GREEN, YELLOW, RED };
|
||||
void SetTrafficLights(TrafficState s);
|
||||
|
||||
TrafficState currentState = TrafficState::GREEN;
|
||||
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||
bool buttonPressedThisCycle = false;
|
||||
bool pedestrianNextCycle = false;
|
||||
bool pedestrianThisCycle = false;
|
||||
|
||||
const uint32_t DURATION_GREEN = 5000;
|
||||
const uint32_t DURATION_YELLOW = 3000;
|
||||
const uint32_t DURATION_RED_NOPED = 5000;
|
||||
const uint32_t DURATION_RED_PED = 7000;
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
|
||||
void SetTrafficLights(TrafficState s)
|
||||
{
|
||||
// reset all
|
||||
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||
|
||||
switch (s)
|
||||
{
|
||||
case TrafficState::GREEN :
|
||||
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case TrafficState::YELLOW :
|
||||
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case TrafficState::RED:
|
||||
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
MX_GPIO_Init();
|
||||
|
||||
stateStartTime = HAL_GetTick();
|
||||
SetTrafficLights(currentState);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
uint32_t now = HAL_GetTick();
|
||||
uint32_t elapsed = now - stateStartTime;
|
||||
|
||||
switch(currentState)
|
||||
{
|
||||
case TrafficState::GREEN:
|
||||
if (buttonPressedThisCycle)
|
||||
pedestrianThisCycle = true;
|
||||
|
||||
/*
|
||||
if (buttonPressedThisCycle)
|
||||
{
|
||||
currentState = TrafficState::YELLOW;
|
||||
stateStartTime = now;
|
||||
buttonPressedThisCycle = false;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
else
|
||||
{
|
||||
pedestrianNextCycle = false;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
*/
|
||||
|
||||
else if (elapsed >= DURATION_GREEN)
|
||||
{
|
||||
currentState = TrafficState::YELLOW;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
break;
|
||||
case TrafficState::YELLOW:
|
||||
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||
pedestrianThisCycle = true;
|
||||
|
||||
if (elapsed >= DURATION_YELLOW)
|
||||
{
|
||||
currentState = TrafficState::RED;
|
||||
stateStartTime = now;
|
||||
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||
SetTrafficLights(currentState);
|
||||
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||
}
|
||||
break;
|
||||
case TrafficState::RED:
|
||||
/*
|
||||
if (pedestrianNextCycle)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_SET); // turn on Pedestrian LED
|
||||
if (elapsed >= DURATION_RED_PED)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||
pedestrianNextCycle = false;
|
||||
currentState = TrafficState::GREEN;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIOD,White_Pin,GPIO_PIN_RESET);
|
||||
if(elapsed >= DURATION_RED_PED)
|
||||
{
|
||||
currentState = TrafficState::GREEN;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (buttonPressedThisCycle)
|
||||
pedestrianNextCycle = true;
|
||||
|
||||
if (pedestrianThisCycle) {
|
||||
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||
pedestrianThisCycle = false;
|
||||
pedestrianNextCycle = false;
|
||||
currentState = TrafficState::GREEN;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
buttonPressedThisCycle = false;
|
||||
} else {
|
||||
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||
if (elapsed >= DURATION_RED_NOPED)
|
||||
{
|
||||
currentState = TrafficState::GREEN;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
buttonPressedThisCycle = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PedButton_Pin */
|
||||
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/*
|
||||
extern "C" void EXTI15_10_IRQHandler()
|
||||
{
|
||||
HAL_GPIO_EXTI_IRQHandler(PedButton_Pin);
|
||||
}
|
||||
*/
|
||||
|
||||
extern "C" void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||
{
|
||||
static uint32_t lastInterruptTime = 0;
|
||||
uint32_t now = HAL_GetTick();
|
||||
|
||||
// software debounce
|
||||
if (now - lastInterruptTime < 100)
|
||||
return;
|
||||
|
||||
lastInterruptTime = now;
|
||||
|
||||
if (GPIO_Pin == PedButton_Pin)
|
||||
buttonPressedThisCycle = true;
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
// Feeling sneaky.
|
||||
extern "C" {
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
}
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
#include <stdbool.h>
|
||||
|
||||
enum class TrafficState { GREEN, YELLOW, RED };
|
||||
void SetTrafficLights(TrafficState s);
|
||||
|
||||
TrafficState currentState = TrafficState::GREEN;
|
||||
uint32_t stateStartTime = 0; //HAL_GetTick() at the start of this state
|
||||
bool buttonPressedThisCycle = false;
|
||||
bool pedestrianNextCycle = false;
|
||||
bool pedestrianThisCycle = false;
|
||||
|
||||
const uint32_t DURATION_GREEN = 5000;
|
||||
const uint32_t DURATION_YELLOW = 3000;
|
||||
const uint32_t DURATION_RED_NOPED = 5000;
|
||||
const uint32_t DURATION_RED_PED = 7000;
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
|
||||
void SetTrafficLights(TrafficState s)
|
||||
{
|
||||
// reset all
|
||||
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||
|
||||
switch (s)
|
||||
{
|
||||
case TrafficState::GREEN :
|
||||
HAL_GPIO_WritePin(GPIOD, Green_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case TrafficState::YELLOW :
|
||||
HAL_GPIO_WritePin(GPIOD, Yellow_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case TrafficState::RED:
|
||||
HAL_GPIO_WritePin(GPIOD, Red_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
MX_GPIO_Init();
|
||||
|
||||
stateStartTime = HAL_GetTick();
|
||||
SetTrafficLights(currentState);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
uint32_t now = HAL_GetTick();
|
||||
uint32_t elapsed = now - stateStartTime;
|
||||
|
||||
switch(currentState)
|
||||
{
|
||||
case TrafficState::GREEN:
|
||||
if (buttonPressedThisCycle)
|
||||
pedestrianThisCycle = true;
|
||||
|
||||
/*
|
||||
if (buttonPressedThisCycle)
|
||||
{
|
||||
currentState = TrafficState::YELLOW;
|
||||
stateStartTime = now;
|
||||
buttonPressedThisCycle = false;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
else
|
||||
{
|
||||
pedestrianNextCycle = false;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
*/
|
||||
|
||||
else if (elapsed >= DURATION_GREEN)
|
||||
{
|
||||
currentState = TrafficState::YELLOW;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
}
|
||||
break;
|
||||
case TrafficState::YELLOW:
|
||||
if (buttonPressedThisCycle || pedestrianNextCycle)
|
||||
pedestrianThisCycle = true;
|
||||
|
||||
if (elapsed >= DURATION_YELLOW)
|
||||
{
|
||||
currentState = TrafficState::RED;
|
||||
stateStartTime = now;
|
||||
buttonPressedThisCycle = false; //TODO add pressed pedestrian button in yellow
|
||||
SetTrafficLights(currentState);
|
||||
// If Ped Button was pressed during GREEN or YELLOW, we need to enable WHITE this cycle
|
||||
}
|
||||
break;
|
||||
case TrafficState::RED:
|
||||
if (buttonPressedThisCycle)
|
||||
pedestrianNextCycle = true;
|
||||
|
||||
if (pedestrianThisCycle) {
|
||||
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||
pedestrianThisCycle = false;
|
||||
pedestrianNextCycle = false;
|
||||
currentState = TrafficState::GREEN;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
buttonPressedThisCycle = false;
|
||||
} else {
|
||||
HAL_GPIO_WritePin(White_GPIO_Port, White_Pin, GPIO_PIN_RESET);
|
||||
if (elapsed >= DURATION_RED_NOPED)
|
||||
{
|
||||
currentState = TrafficState::GREEN;
|
||||
stateStartTime = now;
|
||||
SetTrafficLights(currentState);
|
||||
buttonPressedThisCycle = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||
RCC_OscInitStruct.PLL.PLLN = 50;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV8;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, White_Pin|Red_Pin|Yellow_Pin|Green_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PedButton_Pin */
|
||||
GPIO_InitStruct.Pin = PedButton_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(PedButton_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : White_Pin Red_Pin Yellow_Pin Green_Pin */
|
||||
GPIO_InitStruct.Pin = White_Pin|Red_Pin|Yellow_Pin|Green_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/*
|
||||
extern "C" void EXTI15_10_IRQHandler()
|
||||
{
|
||||
HAL_GPIO_EXTI_IRQHandler(PedButton_Pin);
|
||||
}
|
||||
*/
|
||||
|
||||
extern "C" void HAL_GPIO_EXTI_CallBack(uint16_t GPIO_Pin)
|
||||
{
|
||||
static uint32_t lastInterruptTime = 0;
|
||||
uint32_t now = HAL_GetTick();
|
||||
|
||||
// software debounce
|
||||
if (now - lastInterruptTime < 100)
|
||||
return;
|
||||
|
||||
lastInterruptTime = now;
|
||||
|
||||
if (GPIO_Pin == PedButton_Pin)
|
||||
buttonPressedThisCycle = true;
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -1,3 +1,3 @@
|
||||
#Mon Oct 13 14:21:49 CDT 2025
|
||||
#Mon Oct 13 14:55:54 CDT 2025
|
||||
org.eclipse.core.runtime=2
|
||||
org.eclipse.platform=4.33.0.v20240903-0240
|
||||
|
||||
Reference in New Issue
Block a user