add button test at the board startup, part 1

This commit is contained in:
ІО-23 Шмуляр Олег 2025-03-08 14:23:18 +02:00
parent a2c5b2fe87
commit 82a3907d8a
6 changed files with 116 additions and 36 deletions

View File

@ -55,9 +55,10 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void EXTI0_IRQHandler(void);
/* USER CODE BEGIN EFP */
void EXTI0_IRQHandler(void);
/* USER CODE END EFP */
#ifdef __cplusplus

View File

@ -102,9 +102,88 @@ int main(void)
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
GPIOD->ODR = 0xF000;
GPIOD->ODR = 0x1000;
display_init();
GPIOD->ODR = 0xF000;
// init showcase
display_write_data_seq("Fill any bar:");
DISPLAY_SET_CURSOR(1, 5);
display_write_data_seq("[-] [-----]");
size_t pressed_elements;
uint32_t sw_button_locations[5][2] = {
{GPIOC, GPIO_PIN_11},
{GPIOA, GPIO_PIN_15},
{GPIOC, GPIO_PIN_9},
{GPIOC, GPIO_PIN_6},
{GPIOC, GPIO_PIN_8}
};
do {
HAL_Delay(100);
pressed_elements = 0;
DISPLAY_SET_CURSOR(1, 6);
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) {
pressed_elements |= 0x20;
display_write_data_byte('*');
} else {
display_write_data_byte('-');
}
DISPLAY_SET_CURSOR(1, 10);
for (size_t i = 0; i < 5; i++) {
pressed_elements >>= 1;
size_t input = !HAL_GPIO_ReadPin(sw_button_locations[i][0], sw_button_locations[i][1]);
if (input) {
pressed_elements |= 0x20;
display_write_data_byte('*');
} else {
display_write_data_byte('-');
}
}
} while (pressed_elements != 0x1 && pressed_elements != 0x3E);
GPIOD->ODR = 0x1000;
HAL_Delay(500);
GPIOD->ODR = 0x2000;
HAL_Delay(500);
GPIOD->ODR = 0x4000;
HAL_Delay(500);
GPIOD->ODR = 0x8000;
HAL_Delay(500);
GPIOD->ODR = 0x0000;
while (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0));
HAL_Delay(500);
// switch mode for user button
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
// switch mode for SW5 (alternative advancing method)
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI8_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI8_IRQn);
/* USER CODE END 2 */
@ -230,6 +309,7 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12
@ -238,9 +318,9 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
/*Configure GPIO pins : PA0 PA15 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
@ -260,9 +340,11 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
/*Configure GPIO pins : PC6 PC8 PC9 PC11 */
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */

View File

@ -41,8 +41,6 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
extern void ((*executors[])(void));
extern void *current_executor(void);
extern int current_executor_id;
/* USER CODE END PV */
@ -200,29 +198,20 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32f4xx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line0 interrupt.
*/
/* USER CODE BEGIN 1 */
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
GPIOD->ODR = 0x1000;
current_executor_id += 1;
current_executor_id &= 1;
current_executor_id %= 2;
for (int i = 900000; i > 0; i--) asm("nop");
GPIOD->ODR = 0x0000;
/* USER CODE END EXTI0_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
/* USER CODE BEGIN EXTI0_IRQn 1 */
/* USER CODE END EXTI0_IRQn 1 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@ -5,7 +5,6 @@
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../Core/Src/external-temperature.c \
../Core/Src/external_temp.c \
../Core/Src/lcd.c \
../Core/Src/main.c \
@ -16,7 +15,6 @@ C_SRCS += \
../Core/Src/system_stm32f4xx.c
OBJS += \
./Core/Src/external-temperature.o \
./Core/Src/external_temp.o \
./Core/Src/lcd.o \
./Core/Src/main.o \
@ -27,7 +25,6 @@ OBJS += \
./Core/Src/system_stm32f4xx.o
C_DEPS += \
./Core/Src/external-temperature.d \
./Core/Src/external_temp.d \
./Core/Src/lcd.d \
./Core/Src/main.d \
@ -45,7 +42,7 @@ Core/Src/%.o Core/Src/%.su Core/Src/%.cyclo: ../Core/Src/%.c Core/Src/subdir.mk
clean: clean-Core-2f-Src
clean-Core-2f-Src:
-$(RM) ./Core/Src/external-temperature.cyclo ./Core/Src/external-temperature.d ./Core/Src/external-temperature.o ./Core/Src/external-temperature.su ./Core/Src/external_temp.cyclo ./Core/Src/external_temp.d ./Core/Src/external_temp.o ./Core/Src/external_temp.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su
-$(RM) ./Core/Src/external_temp.cyclo ./Core/Src/external_temp.d ./Core/Src/external_temp.o ./Core/Src/external_temp.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su
.PHONY: clean-Core-2f-Src

View File

@ -1,4 +1,3 @@
"./Core/Src/external-temperature.o"
"./Core/Src/external_temp.o"
"./Core/Src/lcd.o"
"./Core/Src/main.o"

View File

@ -27,7 +27,12 @@ Mcu.Pin1=PB1
Mcu.Pin10=PD13
Mcu.Pin11=PD14
Mcu.Pin12=PD15
Mcu.Pin13=VP_SYS_VS_Systick
Mcu.Pin13=PC6
Mcu.Pin14=PC8
Mcu.Pin15=PC9
Mcu.Pin16=PA15
Mcu.Pin17=PC11
Mcu.Pin18=VP_SYS_VS_Systick
Mcu.Pin2=PE7
Mcu.Pin3=PE10
Mcu.Pin4=PE11
@ -36,7 +41,7 @@ Mcu.Pin6=PE13
Mcu.Pin7=PE14
Mcu.Pin8=PE15
Mcu.Pin9=PD12
Mcu.PinsNb=14
Mcu.PinsNb=19
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F407VGTx
@ -44,7 +49,6 @@ MxCube.Version=6.12.1
MxDb.Version=DB.6.0.121
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.EXTI0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
@ -55,9 +59,19 @@ NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA0-WKUP.Locked=true
PA0-WKUP.Signal=GPXTI0
PA0-WKUP.Signal=GPIO_Input
PA15.Locked=true
PA15.Signal=GPIO_Input
PB1.Locked=true
PB1.Signal=ADCx_IN9
PC11.Locked=true
PC11.Signal=GPIO_Input
PC6.Locked=true
PC6.Signal=GPIO_Input
PC8.Locked=true
PC8.Signal=GPIO_Input
PC9.Locked=true
PC9.Signal=GPIO_Input
PD12.Locked=true
PD12.Signal=GPIO_Output
PD13.Locked=true
@ -111,7 +125,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true
RCC.AHBFreq_Value=16000000
RCC.APB1Freq_Value=16000000
RCC.APB1TimFreq_Value=16000000
@ -140,9 +154,7 @@ RCC.VCOOutputFreq_Value=192000000
RCC.VcooutputI2S=96000000
SH.ADCx_IN9.0=ADC1_IN9,IN9
SH.ADCx_IN9.ConfNb=1
SH.GPXTI0.0=GPIO_EXTI0
SH.GPXTI0.ConfNb=1
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom
isbadioc=false
isbadioc=true