diff --git a/Examples/06_TmLtchdMPBttn_b.cpp b/Examples/06_TmLtchdMPBttn_b.cpp index 306ff3d..c7ff57a 100644 --- a/Examples/06_TmLtchdMPBttn_b.cpp +++ b/Examples/06_TmLtchdMPBttn_b.cpp @@ -57,9 +57,9 @@ BaseType_t xReturned; void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); -void tstDefTaskExec(void *pvParameters); void Error_Handler(void); +void tstDefTaskExec(void *pvParameters); void swpEnableCb(TimerHandle_t pvParam); /** diff --git a/Examples/07_XtrnUnltchMPBttn_2a.cpp.txt b/Examples/07_XtrnUnltchMPBttn_2a.cpp similarity index 82% rename from Examples/07_XtrnUnltchMPBttn_2a.cpp.txt rename to Examples/07_XtrnUnltchMPBttn_2a.cpp index 1d6d1c1..36c74b5 100644 --- a/Examples/07_XtrnUnltchMPBttn_2a.cpp.txt +++ b/Examples/07_XtrnUnltchMPBttn_2a.cpp @@ -6,6 +6,7 @@ * The test instantiates a XtrnUnltchMPBttn object using: * - The Nucleo board user pushbutton attached to GPIO_B00 * - The Nucleo board user LED attached to GPIO_A05 + * - The external unlatch pushbutton attached to GPIO_PB00 * * @author : Gabriel D. Goldman * @@ -18,11 +19,14 @@ * ****************************************************************************** */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +//----------------------- BEGIN Specific to use STM32F4xxyy testing platform +#define MCU_SPEC +//======================> Replace the following two lines with the files corresponding with the used STM32 configuration files +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_gpio.h" +//----------------------- End Specific to use STM32F4xxyy testing platform /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ //===========================>> Next lines used to avoid CMSIS wrappers #include "FreeRTOS.h" #include "task.h" @@ -30,6 +34,7 @@ #include "event_groups.h" //===========================>> Previous lines used to avoid CMSIS wrappers +/* USER CODE BEGIN Includes */ #include "../../mpbAsSwitch_STM32/src/mpbAsSwitch_STM32.h" /* USER CODE END Includes */ @@ -37,9 +42,10 @@ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ -gpioPinId_t ledOnPC00{GPIOC, 0b001}; -gpioPinId_t ledOnPC01{GPIOC, 0b010}; -gpioPinId_t mpbttnOnPB00{GPIOB, 0b001}; +gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0010 0000 +gpioPinId_t tstMpbOnBoard{GPIOC, GPIO_PIN_13}; // Pin 0b 0010 0000 0000 0000 + +gpioPinId_t mpbttnOnPB00{GPIOB, GPIO_PIN_0}; //Pin 0b 0000 0001 TaskHandle_t tstDefTaskHandle {NULL}; BaseType_t xReturned; @@ -50,6 +56,7 @@ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); void tstDefTaskExec(void *pvParameters); +void Error_Handler(void); /** * @brief The application entry point. @@ -71,14 +78,14 @@ int main(void) /* Create the thread(s) */ /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ xReturned = xTaskCreate( tstDefTaskExec, //taskFunction "TstMainTask", //Task function legible name 256, // Stack depth in words NULL, //Parameters to pass as arguments to the taskFunction configTIMER_TASK_PRIORITY, //Set to the same priority level as the software timers - &tstDefTaskHandle); + &tstDefTaskHandle + ); /* USER CODE END RTOS_THREADS */ /* Start scheduler */ @@ -167,8 +174,6 @@ static void MX_USART2_UART_Init(void) 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_GPIOC_CLK_ENABLE(); @@ -177,38 +182,20 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level for tstLedOnBoard*/ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level for ledOnPC00))*/ -// HAL_GPIO_WritePin(ledOnPC00.portId, ledOnPC00.pinNum, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level for ledOnPC01))*/ -// HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); /*Configure GPIO pin : tstMpbOnBoard_Pin */ - GPIO_InitStruct.Pin = tstMpbOnBoard_Pin; + GPIO_InitStruct.Pin = tstMpbOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(tstMpbOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstMpbOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : tstLedOnBoard_Pin */ - GPIO_InitStruct.Pin = tstLedOnBoard_Pin; + GPIO_InitStruct.Pin = tstLedOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(tstLedOnBoard_GPIO_Port, &GPIO_InitStruct); - -/*Configure GPIO pin : ledOnPC00_Pin */ -// GPIO_InitStruct.Pin = ledOnPC00.pinNum; -// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; -// GPIO_InitStruct.Pull = GPIO_NOPULL; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; -// HAL_GPIO_Init(ledOnPC00.portId, &GPIO_InitStruct); - - /*Configure GPIO pin : ledOnPC01_Pin */ -// GPIO_InitStruct.Pin = ledOnPC01.pinNum; -// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; -// GPIO_InitStruct.Pull = GPIO_NOPULL; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; -// HAL_GPIO_Init(ledOnPC01.portId, &GPIO_InitStruct); + HAL_GPIO_Init(tstLedOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : mpbttnOnPB00_Pin */ GPIO_InitStruct.Pin = mpbttnOnPB00.pinNum; @@ -227,7 +214,7 @@ void tstDefTaskExec(void *pvParameters) DbncdDlydMPBttn unLtchTstBttnObj(mpbttnOnPB00.portId, mpbttnOnPB00.pinNum, true, true, 0, 200); DbncdDlydMPBttn* unLtchTstBttnPtr {&unLtchTstBttnObj}; - XtrnUnltchMPBttn tstBttn(tstMpbOnBoard_GPIO_Port, tstMpbOnBoard_Pin, unLtchTstBttnPtr, true, true, 0, 50); + XtrnUnltchMPBttn tstBttn(tstMpbOnBoard.portId, tstMpbOnBoard.pinNum, unLtchTstBttnPtr, true, true, 0, 50); unLtchTstBttnObj.begin(20); tstBttn.setTrnOffASAP(false); @@ -239,9 +226,9 @@ void tstDefTaskExec(void *pvParameters) tmpBttnIsOn = tstBttn.getIsOn(); if(tmpBttnWasOn != tmpBttnIsOn){ if(tmpBttnIsOn) - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_SET); else - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); } unLtchBttnWasOn = unLtchBttnIsOn; diff --git a/Examples/07_XtrnUnltchMPBttn_2a.h b/Examples/07_XtrnUnltchMPBttn_2a.h new file mode 100644 index 0000000..c6827ed --- /dev/null +++ b/Examples/07_XtrnUnltchMPBttn_2a.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __STM32F4xx_HAL_H + #include "stm32f4xx_hal.h" +#endif + +/* Private defines -----------------------------------------------------------*/ +#define USART_TX_Pin GPIO_PIN_2 +#define USART_TX_GPIO_Port GPIOA +#define USART_RX_Pin GPIO_PIN_3 +#define USART_RX_GPIO_Port GPIOA + +//#define TMS_Pin GPIO_PIN_13 +//#define TMS_GPIO_Port GPIOA + +//#define TCK_Pin GPIO_PIN_14 +//#define TCK_GPIO_Port GPIOA + +//#define SWO_Pin GPIO_PIN_3 +//#define SWO_GPIO_Port GPIOB + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/07_XtrnUnltchMPBttn_2b.cpp.txt b/Examples/07_XtrnUnltchMPBttn_2b.cpp similarity index 85% rename from Examples/07_XtrnUnltchMPBttn_2b.cpp.txt rename to Examples/07_XtrnUnltchMPBttn_2b.cpp index b675441..0904931 100644 --- a/Examples/07_XtrnUnltchMPBttn_2b.cpp.txt +++ b/Examples/07_XtrnUnltchMPBttn_2b.cpp @@ -1,14 +1,16 @@ /** ****************************************************************************** * @file : 07_XtrnUnltchMPBttn_2b.cpp - * @brief : Test for the MpbAsSwitch_STM32 library XtrnUnltchMPBttn class + * @brief : Example for the MpbAsSwitch_STM32 library XtrnUnltchMPBttn class * - * The test instantiates a XtrnUnltchMPBttn object using: + * The example instantiates a XtrnUnltchMPBttn object using: * - The Nucleo board user pushbutton attached to GPIO_B00 * - The Nucleo board user LED attached to GPIO_A05 + * - The external unlatch pushbutton attached to GPIO_PB00 + * - A LED attached to GPIO_C00 to visualize the isEnabled attribute flag status * - * This example includes a timer that periodically toggle the isEnabled flag value - * showing the behavior of the instantiated object. + * This example includes a timer that periodically toggle the isEnabled attribute flag value + * showing the behavior of the instantiated object when enabled and when disabled. * * @author : Gabriel D. Goldman * @@ -21,11 +23,14 @@ * ****************************************************************************** */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +//----------------------- BEGIN Specific to use STM32F4xxyy testing platform +#define MCU_SPEC +//======================> Replace the following two lines with the files corresponding with the used STM32 configuration files +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_gpio.h" +//----------------------- End Specific to use STM32F4xxyy testing platform /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ //===========================>> Next lines used to avoid CMSIS wrappers #include "FreeRTOS.h" #include "task.h" @@ -33,6 +38,7 @@ #include "event_groups.h" //===========================>> Previous lines used to avoid CMSIS wrappers +/* USER CODE BEGIN Includes */ #include "../../mpbAsSwitch_STM32/src/mpbAsSwitch_STM32.h" /* USER CODE END Includes */ @@ -40,9 +46,11 @@ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ -gpioPinId_t ledOnPC00{GPIOC, 0b001}; -gpioPinId_t ledOnPC01{GPIOC, 0b010}; -gpioPinId_t mpbttnOnPB00{GPIOB, 0b001}; +gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0010 0000 +gpioPinId_t tstMpbOnBoard{GPIOC, GPIO_PIN_13}; // Pin 0b 0010 0000 0000 0000 + +gpioPinId_t ledOnPC00{GPIOC, GPIO_PIN_0}; //Pin 0b 0000 0001 +gpioPinId_t mpbttnOnPB00{GPIOB, GPIO_PIN_0}; //Pin 0b 0000 0001 TaskHandle_t tstDefTaskHandle {NULL}; BaseType_t xReturned; @@ -53,9 +61,9 @@ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); void tstDefTaskExec(void *pvParameters); -/* USER CODE BEGIN PFP */ +void Error_Handler(void); + void swpEnableCb(TimerHandle_t pvParam); -/* USER CODE END PFP */ /** * @brief The application entry point. @@ -77,14 +85,14 @@ int main(void) /* Create the thread(s) */ /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ xReturned = xTaskCreate( tstDefTaskExec, //taskFunction "TstMainTask", //Task function legible name 256, // Stack depth in words NULL, //Parameters to pass as arguments to the taskFunction configTIMER_TASK_PRIORITY, //Set to the same priority level as the software timers - &tstDefTaskHandle); + &tstDefTaskHandle + ); /* USER CODE END RTOS_THREADS */ /* Start scheduler */ @@ -173,8 +181,6 @@ static void MX_USART2_UART_Init(void) 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_GPIOC_CLK_ENABLE(); @@ -183,24 +189,22 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level for tstLedOnBoard*/ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); /*Configure GPIO pin Output Level for ledOnPC00))*/ HAL_GPIO_WritePin(ledOnPC00.portId, ledOnPC00.pinNum, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level for ledOnPC01))*/ -// HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); /*Configure GPIO pin : tstMpbOnBoard_Pin */ - GPIO_InitStruct.Pin = tstMpbOnBoard_Pin; + GPIO_InitStruct.Pin = tstMpbOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(tstMpbOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstMpbOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : tstLedOnBoard_Pin */ - GPIO_InitStruct.Pin = tstLedOnBoard_Pin; + GPIO_InitStruct.Pin = tstLedOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(tstLedOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstLedOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : ledOnPC00_Pin */ GPIO_InitStruct.Pin = ledOnPC00.pinNum; @@ -209,13 +213,6 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(ledOnPC00.portId, &GPIO_InitStruct); - /*Configure GPIO pin : ledOnPC01_Pin */ -// GPIO_InitStruct.Pin = ledOnPC01.pinNum; -// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; -// GPIO_InitStruct.Pull = GPIO_NOPULL; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; -// HAL_GPIO_Init(ledOnPC01.portId, &GPIO_InitStruct); - /*Configure GPIO pin : mpbttnOnPB00_Pin */ GPIO_InitStruct.Pin = mpbttnOnPB00.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; @@ -236,7 +233,7 @@ void tstDefTaskExec(void *pvParameters) DbncdDlydMPBttn unLtchTstBttnObj(mpbttnOnPB00.portId, mpbttnOnPB00.pinNum, true, true, 0, 200); DbncdDlydMPBttn* unLtchTstBttnPtr {&unLtchTstBttnObj}; - XtrnUnltchMPBttn tstBttn(tstMpbOnBoard_GPIO_Port, tstMpbOnBoard_Pin, unLtchTstBttnPtr, true, true, 0, 50); + XtrnUnltchMPBttn tstBttn(tstMpbOnBoard.portId, tstMpbOnBoard.pinNum, unLtchTstBttnPtr, true, true, 0, 50); XtrnUnltchMPBttn* tstBttnPtr {&tstBttn}; enableSwpTmrHndl = xTimerCreate( @@ -245,7 +242,7 @@ void tstDefTaskExec(void *pvParameters) pdTRUE, tstBttnPtr, swpEnableCb - ); + ); if (enableSwpTmrHndl != NULL){ tmrModRslt = xTimerStart(enableSwpTmrHndl, portMAX_DELAY); if(tmrModRslt == pdFAIL) @@ -263,9 +260,9 @@ void tstDefTaskExec(void *pvParameters) tmpBttnIsOn = tstBttn.getIsOn(); if(tmpBttnWasOn != tmpBttnIsOn){ if(tmpBttnIsOn) - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_SET); else - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); } unLtchBttnWasOn = unLtchBttnIsOn; diff --git a/Examples/07_XtrnUnltchMPBttn_2b.h b/Examples/07_XtrnUnltchMPBttn_2b.h new file mode 100644 index 0000000..c6827ed --- /dev/null +++ b/Examples/07_XtrnUnltchMPBttn_2b.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __STM32F4xx_HAL_H + #include "stm32f4xx_hal.h" +#endif + +/* Private defines -----------------------------------------------------------*/ +#define USART_TX_Pin GPIO_PIN_2 +#define USART_TX_GPIO_Port GPIOA +#define USART_RX_Pin GPIO_PIN_3 +#define USART_RX_GPIO_Port GPIOA + +//#define TMS_Pin GPIO_PIN_13 +//#define TMS_GPIO_Port GPIOA + +//#define TCK_Pin GPIO_PIN_14 +//#define TCK_GPIO_Port GPIOA + +//#define SWO_Pin GPIO_PIN_3 +//#define SWO_GPIO_Port GPIOB + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/09_TmVdblMPBttn_1a.cpp.txt b/Examples/09_TmVdblMPBttn_1a.cpp similarity index 81% rename from Examples/09_TmVdblMPBttn_1a.cpp.txt rename to Examples/09_TmVdblMPBttn_1a.cpp index 3663345..cd62f91 100644 --- a/Examples/09_TmVdblMPBttn_1a.cpp.txt +++ b/Examples/09_TmVdblMPBttn_1a.cpp @@ -1,12 +1,11 @@ /** ****************************************************************************** * @file : 09_TmVdblMPBttn_1a.cpp - * @brief : Test for the MpbAsSwitch_STM32 library TmVdblMPBttn class + * @brief : Example for the MpbAsSwitch_STM32 library TmVdblMPBttn class * - * The test instantiates a TmVdblMPBttn object using: + * The example instantiates a TmVdblMPBttn object using: * - The Nucleo board user pushbutton attached to GPIO_B00 * - The Nucleo board user LED attached to GPIO_A05 - * - A digital output to GPIO_PC01 to show _isVoided flag state * * @author : Gabriel D. Goldman * @@ -19,19 +18,22 @@ * ****************************************************************************** */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +//----------------------- BEGIN Specific to use STM32F4xxyy testing platform +#define MCU_SPEC +//======================> Replace the following two lines with the files corresponding with the used STM32 configuration files +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_gpio.h" +//----------------------- End Specific to use STM32F4xxyy testing platform /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - //===========================>> Next lines used to avoid CMSIS wrappers #include "FreeRTOS.h" #include "task.h" #include "timers.h" #include "event_groups.h" //===========================>> Previous lines used to avoid CMSIS wrappers + +/* USER CODE BEGIN Includes */ #include "../../mpbAsSwitch_STM32/src/mpbAsSwitch_STM32.h" /* USER CODE END Includes */ @@ -39,26 +41,22 @@ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ -//gpioPinId_t ledOnPC00{GPIOC, 0b001}; -gpioPinId_t ledOnPC01{GPIOC, 0b010}; +gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0010 0000 +gpioPinId_t tstMpbOnBoard{GPIOC, GPIO_PIN_13}; // Pin 0b 0010 0000 0000 0000 + +gpioPinId_t ledOnPC01{GPIOC, GPIO_PIN_1}; // Pin 0b 0000 0000 0000 0010 TaskHandle_t tstDefTaskHandle {NULL}; BaseType_t xReturned; /* USER CODE END PV */ -/* Private function prototypes -----------------------------------------------*/ +/* System generated function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); -void tstDefTaskExec(void *pvParameters); - -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ +void Error_Handler(void); -/* USER CODE END 0 */ +/* Private function prototypes -----------------------------------------------*/ +void tstDefTaskExec(void *pvParameters); /** * @brief The application entry point. @@ -77,31 +75,22 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - /* Create the thread(s) */ - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ - xReturned = xTaskCreate( + xReturned = xTaskCreate( tstDefTaskExec, //taskFunction "TstMainTask", //Task function legible name 256, // Stack depth in words NULL, //Parameters to pass as arguments to the taskFunction configTIMER_TASK_PRIORITY, //Set to the same priority level as the software timers - &tstDefTaskHandle); - + &tstDefTaskHandle + ); /* USER CODE END RTOS_THREADS */ /* Start scheduler */ -// osKernelStart(); vTaskStartScheduler(); - /* We should never get here as control is now taken by the scheduler */ - /* Infinite loop */ while (1) { @@ -184,8 +173,6 @@ static void MX_USART2_UART_Init(void) 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_GPIOC_CLK_ENABLE(); @@ -193,40 +180,30 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ -// HAL_GPIO_WritePin(ledOnPC00.portId, ledOnPC00.pinNum, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level for tstLedOnBoard*/ + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level for ledOnPC01*/ HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); /*Configure GPIO pin : tstMpbOnBoard_Pin */ - GPIO_InitStruct.Pin = tstMpbOnBoard_Pin; + GPIO_InitStruct.Pin = tstMpbOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(tstMpbOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstMpbOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : tstLedOnBoard_Pin */ - GPIO_InitStruct.Pin = tstLedOnBoard_Pin; + GPIO_InitStruct.Pin = tstLedOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(tstLedOnBoard_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : ledOnPC00 */ -// GPIO_InitStruct.Pin = ledOnPC00.pinNum; -// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; -// GPIO_InitStruct.Pull = GPIO_NOPULL; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; -// HAL_GPIO_Init(ledOnPC00.portId, &GPIO_InitStruct); + HAL_GPIO_Init(tstLedOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : ledOnPC01 */ GPIO_InitStruct.Pin = ledOnPC01.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(ledOnPC01.portId, &GPIO_InitStruct); - } /* USER CODE BEGIN 4 */ @@ -238,7 +215,7 @@ void tstDefTaskExec(void *pvParameters) bool tmpBttnWasVoided{false}; bool tmpBttnIsVoided{false}; - TmVdblMPBttn tstBttn(tstMpbOnBoard_GPIO_Port, tstMpbOnBoard_Pin, 3000,true, true, 50, 150); + TmVdblMPBttn tstBttn(tstMpbOnBoard.portId, tstMpbOnBoard.pinNum, 3000,true, true, 50, 150); tstBttn.setIsOnDisabled(true); tstBttn.begin(5); @@ -252,10 +229,10 @@ void tstDefTaskExec(void *pvParameters) if(tmpBttnWasOn != tmpBttnIsOn){ if(tmpBttnIsOn){ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_SET); } else{ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); } } diff --git a/Examples/09_TmVdblMPBttn_1a.h b/Examples/09_TmVdblMPBttn_1a.h new file mode 100644 index 0000000..c6827ed --- /dev/null +++ b/Examples/09_TmVdblMPBttn_1a.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __STM32F4xx_HAL_H + #include "stm32f4xx_hal.h" +#endif + +/* Private defines -----------------------------------------------------------*/ +#define USART_TX_Pin GPIO_PIN_2 +#define USART_TX_GPIO_Port GPIOA +#define USART_RX_Pin GPIO_PIN_3 +#define USART_RX_GPIO_Port GPIOA + +//#define TMS_Pin GPIO_PIN_13 +//#define TMS_GPIO_Port GPIOA + +//#define TCK_Pin GPIO_PIN_14 +//#define TCK_GPIO_Port GPIOA + +//#define SWO_Pin GPIO_PIN_3 +//#define SWO_GPIO_Port GPIOB + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/09_TmVdblMPBttn_1b.cpp.txt b/Examples/09_TmVdblMPBttn_1b.cpp similarity index 86% rename from Examples/09_TmVdblMPBttn_1b.cpp.txt rename to Examples/09_TmVdblMPBttn_1b.cpp index da9c8a2..6052a42 100644 --- a/Examples/09_TmVdblMPBttn_1b.cpp.txt +++ b/Examples/09_TmVdblMPBttn_1b.cpp @@ -1,17 +1,17 @@ /** ****************************************************************************** * @file : 09_TmVdblMPBttn_1b.cpp - * @brief : Test for the MpbAsSwitch_STM32 library TmVdblMPBttn class + * @brief : Example for the MpbAsSwitch_STM32 library TmVdblMPBttn class * * The test instantiates a TmVdblMPBttn object using: * - The Nucleo board user pushbutton attached to GPIO_B00 * - The Nucleo board user LED attached to GPIO_A05 - * - A digital output to GPIO_PC01 to show _isVoided flag state - * - A digital output to GPIO_PC00 to show _isEnabled flag state + * - A LED attached to GPIO_PC01 to show _isVoided flag state + * - A LED attached to GPIO_PC00 to show _isEnabled flag state * This example includes: * - Implementation of the object - * - The use of a timer that periodically enables/disables the object through the - * provided methods + * - A timer that periodically toggle the isEnabled attribute flag value + * showing the behavior of the instantiated object when enabled and when disabled. * * @author : Gabriel D. Goldman * @@ -24,19 +24,22 @@ * ****************************************************************************** */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +//----------------------- BEGIN Specific to use STM32F4xxyy testing platform +#define MCU_SPEC +//======================> Replace the following two lines with the files corresponding with the used STM32 configuration files +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_gpio.h" +//----------------------- End Specific to use STM32F4xxyy testing platform /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - //===========================>> Next lines used to avoid CMSIS wrappers #include "FreeRTOS.h" #include "task.h" #include "timers.h" #include "event_groups.h" //===========================>> Previous lines used to avoid CMSIS wrappers + +/* USER CODE BEGIN Includes */ #include "../../mpbAsSwitch_STM32/src/mpbAsSwitch_STM32.h" /* USER CODE END Includes */ @@ -44,8 +47,11 @@ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ -gpioPinId_t ledOnPC00{GPIOC, 0b001}; -gpioPinId_t ledOnPC01{GPIOC, 0b010}; +gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0010 0000 +gpioPinId_t tstMpbOnBoard{GPIOC, GPIO_PIN_13}; // Pin 0b 0010 0000 0000 0000 + +gpioPinId_t ledOnPC00{GPIOC, GPIO_PIN_0}; +gpioPinId_t ledOnPC01{GPIOC, GPIO_PIN_1}; TaskHandle_t tstDefTaskHandle {NULL}; BaseType_t xReturned; @@ -55,14 +61,11 @@ BaseType_t xReturned; void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); +void Error_Handler(void); void tstDefTaskExec(void *pvParameters); - -/* USER CODE BEGIN PFP */ void swpEnableCb(TimerHandle_t pvParam); -/* USER CODE END PFP */ - /* Private user code ---------------------------------------------------------*/ /** * @brief The application entry point. @@ -75,44 +78,28 @@ int main(void) /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - /* Configure the system clock */ SystemClock_Config(); - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ /* Create the thread(s) */ /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ xReturned = xTaskCreate( tstDefTaskExec, //taskFunction "TstMainTask", //Task function legible name 256, // Stack depth in words NULL, //Parameters to pass as arguments to the taskFunction configTIMER_TASK_PRIORITY, //Set to the same priority level as the software timers - &tstDefTaskHandle); - - /* USER CODE END RTOS_THREADS */ + &tstDefTaskHandle + ); - /* USER CODE BEGIN RTOS_EVENTS */ - /* add events, ... */ /* USER CODE END RTOS_EVENTS */ /* Start scheduler */ -// osKernelStart(); vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ @@ -199,8 +186,6 @@ static void MX_USART2_UART_Init(void) 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_GPIOC_CLK_ENABLE(); @@ -209,24 +194,22 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPC00.portId, ledOnPC00.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin : tstMpbOnBoard_Pin */ - GPIO_InitStruct.Pin = tstMpbOnBoard_Pin; + GPIO_InitStruct.Pin = tstMpbOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(tstMpbOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstMpbOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : tstLedOnBoard_Pin */ - GPIO_InitStruct.Pin = tstLedOnBoard_Pin; + GPIO_InitStruct.Pin = tstLedOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(tstLedOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstLedOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : Output to led in PC0 */ GPIO_InitStruct.Pin = ledOnPC00.pinNum; @@ -258,7 +241,7 @@ void tstDefTaskExec(void *pvParameters) bool tmpBttnWasDisabled{false}; bool tmpBttnIsDisabled{false}; - TmVdblMPBttn tstBttn(tstMpbOnBoard_GPIO_Port, tstMpbOnBoard_Pin, 3000,true, true, 50, 150); + TmVdblMPBttn tstBttn(tstMpbOnBoard.portId, tstMpbOnBoard.pinNum, 3000,true, true, 50, 150); TmVdblMPBttn* tstBttnPtr {&tstBttn}; tstBttn.setIsOnDisabled(false); @@ -269,7 +252,7 @@ void tstDefTaskExec(void *pvParameters) pdTRUE, tstBttnPtr, swpEnableCb - ); + ); tstBttn.begin(5); @@ -290,10 +273,10 @@ void tstDefTaskExec(void *pvParameters) if(tmpBttnWasOn != tmpBttnIsOn){ if(tmpBttnIsOn){ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_SET); } else{ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); } } diff --git a/Examples/09_TmVdblMPBttn_1b.h b/Examples/09_TmVdblMPBttn_1b.h new file mode 100644 index 0000000..c6827ed --- /dev/null +++ b/Examples/09_TmVdblMPBttn_1b.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __STM32F4xx_HAL_H + #include "stm32f4xx_hal.h" +#endif + +/* Private defines -----------------------------------------------------------*/ +#define USART_TX_Pin GPIO_PIN_2 +#define USART_TX_GPIO_Port GPIOA +#define USART_RX_Pin GPIO_PIN_3 +#define USART_RX_GPIO_Port GPIOA + +//#define TMS_Pin GPIO_PIN_13 +//#define TMS_GPIO_Port GPIOA + +//#define TCK_Pin GPIO_PIN_14 +//#define TCK_GPIO_Port GPIOA + +//#define SWO_Pin GPIO_PIN_3 +//#define SWO_GPIO_Port GPIOB + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/10_HntdTmLtchMPBttn_a.cpp.txt b/Examples/10_HntdTmLtchMPBttn_a.cpp similarity index 85% rename from Examples/10_HntdTmLtchMPBttn_a.cpp.txt rename to Examples/10_HntdTmLtchMPBttn_a.cpp index e2392e3..7abefb2 100644 --- a/Examples/10_HntdTmLtchMPBttn_a.cpp.txt +++ b/Examples/10_HntdTmLtchMPBttn_a.cpp @@ -1,13 +1,13 @@ /** ****************************************************************************** * @file : 10_HntdTmLtchMPBttn_a.cpp - * @brief : Test for the MpbAsSwitch_STM32 library HntdTmLtchMPBttn class + * @brief : Example for the MpbAsSwitch_STM32 library HntdTmLtchMPBttn class * - * The test instantiates a HntdTmLtchMPBttn object using: + * The example instantiates a HntdTmLtchMPBttn object using: * - The Nucleo board user pushbutton attached to GPIO_B00 * - The Nucleo board user LED attached to GPIO_A05 - * - A digital output to GPIO_PC00 to show _pilotOn flag state - * - A digital output to GPIO_PC01 to show _wrnngOn flag state + * - A digital output to GPIO_PC00 to show _pilotOn attribute flag state + * - A digital output to GPIO_PC01 to show _wrnngOn attribute flag state * * @author : Gabriel D. Goldman * @@ -20,19 +20,22 @@ * ****************************************************************************** */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +//----------------------- BEGIN Specific to use STM32F4xxyy testing platform +#define MCU_SPEC +//======================> Replace the following two lines with the files corresponding with the used STM32 configuration files +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_gpio.h" +//----------------------- End Specific to use STM32F4xxyy testing platform /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - //===========================>> Next lines used to avoid CMSIS wrappers #include "FreeRTOS.h" #include "task.h" #include "timers.h" #include "event_groups.h" //===========================>> Previous lines used to avoid CMSIS wrappers + +/* USER CODE BEGIN Includes */ #include "../../mpbAsSwitch_STM32/src/mpbAsSwitch_STM32.h" /* USER CODE END Includes */ @@ -40,29 +43,23 @@ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ -gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0010 0000 +gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0000 0000 0010 0000 gpioPinId_t tstMpbOnBoard{GPIOC, GPIO_PIN_13}; // Pin 0b 0010 0000 0000 0000 -gpioPinId_t ledOnPC00{GPIOC, GPIO_PIN_0}; //Pin 0b 0000 0001 -gpioPinId_t ledOnPC01{GPIOC, GPIO_PIN_1}; //Pin 0b 0000 0010 +gpioPinId_t ledOnPC00{GPIOC, GPIO_PIN_0}; //Pin 0b 0000 0000 0000 0001 +gpioPinId_t ledOnPC01{GPIOC, GPIO_PIN_1}; //Pin 0b 0000 0000 0000 0010 TaskHandle_t tstDefTaskHandle {NULL}; BaseType_t xReturned; /* USER CODE END PV */ -/* Private function prototypes -----------------------------------------------*/ +/* System generated function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); -void tstDefTaskExec(void *pvParameters); - -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ +void Error_Handler(void); -/* USER CODE END 0 */ +/* Private function prototypes -----------------------------------------------*/ +void tstDefTaskExec(void *pvParameters); /** * @brief The application entry point. @@ -81,27 +78,20 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - /* Create the thread(s) */ - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ xReturned = xTaskCreate( tstDefTaskExec, //taskFunction "TstMainTask", //Task function legible name 256, // Stack depth in words NULL, //Parameters to pass as arguments to the taskFunction configTIMER_TASK_PRIORITY, //Set to the same priority level as the software timers - &tstDefTaskHandle); - + &tstDefTaskHandle + ); /* USER CODE END RTOS_THREADS */ /* Start scheduler */ -// osKernelStart(); vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ @@ -187,8 +177,6 @@ static void MX_USART2_UART_Init(void) 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_GPIOC_CLK_ENABLE(); @@ -197,24 +185,22 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPC00.portId, ledOnPC00.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); /*Configure GPIO pin : tstMpbOnBoard_Pin */ - GPIO_InitStruct.Pin = tstMpbOnBoard_Pin; + GPIO_InitStruct.Pin = tstMpbOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(tstMpbOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstMpbOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : tstLedOnBoard_Pin */ - GPIO_InitStruct.Pin = tstLedOnBoard_Pin; + GPIO_InitStruct.Pin = tstLedOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(tstLedOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstLedOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : ledOnPC00 */ GPIO_InitStruct.Pin = ledOnPC00.pinNum; @@ -229,7 +215,6 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; HAL_GPIO_Init(ledOnPC01.portId, &GPIO_InitStruct); - } /* USER CODE BEGIN 4 */ @@ -243,7 +228,7 @@ void tstDefTaskExec(void *pvParameters) bool tmpPltWasOn{false}; bool tmpPltIsOn{false}; - HntdTmLtchMPBttn tstBttn(tstMpbOnBoard_GPIO_Port, tstMpbOnBoard_Pin, 4000, 33,true, true, 0, 250); + HntdTmLtchMPBttn tstBttn(tstMpbOnBoard.portId, tstMpbOnBoard.pinNum, 4000, 33,true, true, 0, 250); tstBttn.setKeepPilot(true); tstBttn.setWrnngPrctg(50); tstBttn.setTmerRstbl(true); @@ -264,10 +249,10 @@ void tstDefTaskExec(void *pvParameters) if(tmpBttnWasOn != tmpBttnIsOn){ if(tmpBttnIsOn){ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_SET); } else{ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); } } diff --git a/Examples/10_HntdTmLtchMPBttn_a.h b/Examples/10_HntdTmLtchMPBttn_a.h new file mode 100644 index 0000000..c6827ed --- /dev/null +++ b/Examples/10_HntdTmLtchMPBttn_a.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __STM32F4xx_HAL_H + #include "stm32f4xx_hal.h" +#endif + +/* Private defines -----------------------------------------------------------*/ +#define USART_TX_Pin GPIO_PIN_2 +#define USART_TX_GPIO_Port GPIOA +#define USART_RX_Pin GPIO_PIN_3 +#define USART_RX_GPIO_Port GPIOA + +//#define TMS_Pin GPIO_PIN_13 +//#define TMS_GPIO_Port GPIOA + +//#define TCK_Pin GPIO_PIN_14 +//#define TCK_GPIO_Port GPIOA + +//#define SWO_Pin GPIO_PIN_3 +//#define SWO_GPIO_Port GPIOB + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/10_HntdTmLtchMPBttn_b.cpp.txt b/Examples/10_HntdTmLtchMPBttn_b.cpp similarity index 81% rename from Examples/10_HntdTmLtchMPBttn_b.cpp.txt rename to Examples/10_HntdTmLtchMPBttn_b.cpp index e2fc912..4f7fafd 100644 --- a/Examples/10_HntdTmLtchMPBttn_b.cpp.txt +++ b/Examples/10_HntdTmLtchMPBttn_b.cpp @@ -1,18 +1,17 @@ /** ****************************************************************************** * @file : 10_HntdTmLtchMPBttn_b.cpp - * @brief : Test for the MpbAsSwitch_STM32 library HntdTmLtchMPBttn class + * @brief : Example for the MpbAsSwitch_STM32 library HntdTmLtchMPBttn class * - * The test instantiates a HntdTmLtchMPBttn object using: + * The example instantiates a HntdTmLtchMPBttn object using: * - The Nucleo board user pushbutton attached to GPIO_B00 * - The Nucleo board user LED attached to GPIO_A05 - * - A digital output to GPIO_PC00 to show _pilotOn flag state - * - A digital output to GPIO_PC01 to show _wrnngOn flag state - * - A digital output to GPIO_PA00 to show _isEnabled flag state + * - A digital output to GPIO_PC00 to show _pilotOn attribute flag state + * - A digital output to GPIO_PC01 to show _wrnngOn attribute flag state * This example includes: * - Implementation of the object - * - The use of a timer that periodically enables/disables the object through the - * provided methods + * - A timer that periodically toggle the isEnabled attribute flag value + * showing the behavior of the instantiated object when enabled and when disabled. * * @author : Gabriel D. Goldman * @@ -25,19 +24,22 @@ * ****************************************************************************** */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" +//----------------------- BEGIN Specific to use STM32F4xxyy testing platform +#define MCU_SPEC +//======================> Replace the following two lines with the files corresponding with the used STM32 configuration files +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_gpio.h" +//----------------------- End Specific to use STM32F4xxyy testing platform /* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - //===========================>> Next lines used to avoid CMSIS wrappers #include "FreeRTOS.h" #include "task.h" #include "timers.h" #include "event_groups.h" //===========================>> Previous lines used to avoid CMSIS wrappers + +/* USER CODE BEGIN Includes */ #include "../../mpbAsSwitch_STM32/src/mpbAsSwitch_STM32.h" /* USER CODE END Includes */ @@ -45,27 +47,26 @@ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ -gpioPinId_t ledOnPC00{GPIOC, 0b001}; -gpioPinId_t ledOnPC01{GPIOC, 0b010}; -gpioPinId_t ledOnPA04{GPIOA, 0b010000}; +gpioPinId_t tstLedOnBoard{GPIOA, GPIO_PIN_5}; // Pin 0b 0000 0000 0010 0000 +gpioPinId_t tstMpbOnBoard{GPIOC, GPIO_PIN_13}; // Pin 0b 0010 0000 0000 0000 + +gpioPinId_t ledOnPC00{GPIOC, GPIO_PIN_0}; //Pin 0b 0000 0000 0000 0001 +gpioPinId_t ledOnPC01{GPIOC, GPIO_PIN_1}; //Pin 0b 0000 0000 0000 0010 +gpioPinId_t ledOnPA04{GPIOA, GPIO_PIN_4}; //Pin 0b 0000 0000 0001 0000 + TaskHandle_t tstDefTaskHandle {NULL}; BaseType_t xReturned; /* USER CODE END PV */ -/* Private function prototypes -----------------------------------------------*/ +/* System generated function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); -void tstDefTaskExec(void *pvParameters); +void Error_Handler(void); -/* USER CODE BEGIN PFP */ +/* Private function prototypes -----------------------------------------------*/ +void tstDefTaskExec(void *pvParameters); void swpEnableCb(TimerHandle_t pvParam); -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ /** * @brief The application entry point. @@ -84,27 +85,20 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - /* Create the thread(s) */ - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ xReturned = xTaskCreate( tstDefTaskExec, //taskFunction "TstMainTask", //Task function legible name 256, // Stack depth in words NULL, //Parameters to pass as arguments to the taskFunction configTIMER_TASK_PRIORITY, //Set to the same priority level as the software timers - &tstDefTaskHandle); - + &tstDefTaskHandle + ); /* USER CODE END RTOS_THREADS */ /* Start scheduler */ -// osKernelStart(); vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ @@ -190,8 +184,6 @@ static void MX_USART2_UART_Init(void) 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_GPIOC_CLK_ENABLE(); @@ -200,45 +192,43 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPC00.portId, ledOnPC00.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); HAL_GPIO_WritePin(ledOnPA04.portId, ledOnPA04.pinNum, GPIO_PIN_RESET); /*Configure GPIO pin : tstMpbOnBoard_Pin */ - GPIO_InitStruct.Pin = tstMpbOnBoard_Pin; + GPIO_InitStruct.Pin = tstMpbOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(tstMpbOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstMpbOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : tstLedOnBoard_Pin */ - GPIO_InitStruct.Pin = tstLedOnBoard_Pin; + GPIO_InitStruct.Pin = tstLedOnBoard.pinNum; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(tstLedOnBoard_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(tstLedOnBoard.portId, &GPIO_InitStruct); /*Configure GPIO pin : ledOnPC00 */ GPIO_InitStruct.Pin = ledOnPC00.pinNum; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; +// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; +// GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; HAL_GPIO_Init(ledOnPC00.portId, &GPIO_InitStruct); /*Configure GPIO pin : ledOnPC01 */ GPIO_InitStruct.Pin = ledOnPC01.pinNum; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; +// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; +// GPIO_InitStruct.Pull = GPIO_NOPULL; +// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; HAL_GPIO_Init(ledOnPC01.portId, &GPIO_InitStruct); - /*Configure GPIO pin : ledOnPA04 */ + /*Configure GPIO pin : ledOnA04 */ GPIO_InitStruct.Pin = ledOnPA04.pinNum; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; +// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; +// GPIO_InitStruct.Pull = GPIO_NOPULL; +// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; HAL_GPIO_Init(ledOnPA04.portId, &GPIO_InitStruct); } @@ -253,12 +243,14 @@ void tstDefTaskExec(void *pvParameters) bool tmpWrnngWasOn{false}; bool tmpWrnngIsOn{false}; + bool tmpPltWasOn{false}; bool tmpPltIsOn{false}; + bool tmpBttnWasDisabled{false}; bool tmpBttnIsDisabled{false}; - HntdTmLtchMPBttn tstBttn(tstMpbOnBoard_GPIO_Port, tstMpbOnBoard_Pin, 4000, 33,true, true, 0, 250); + HntdTmLtchMPBttn tstBttn(tstMpbOnBoard.portId, tstMpbOnBoard.pinNum, 4000, 33,true, true, 0, 250); HntdTmLtchMPBttn* tstBttnPtr {&tstBttn}; tstBttn.setIsOnDisabled(true); @@ -273,7 +265,7 @@ void tstDefTaskExec(void *pvParameters) pdTRUE, tstBttnPtr, swpEnableCb - ); + ); tstBttn.begin(20); @@ -299,10 +291,10 @@ void tstDefTaskExec(void *pvParameters) if(tmpBttnWasOn != tmpBttnIsOn){ if(tmpBttnIsOn){ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_SET); } else{ - HAL_GPIO_WritePin(tstLedOnBoard_GPIO_Port, tstLedOnBoard_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(tstLedOnBoard.portId, tstLedOnBoard.pinNum, GPIO_PIN_RESET); } } @@ -319,7 +311,6 @@ void tstDefTaskExec(void *pvParameters) else HAL_GPIO_WritePin(ledOnPC01.portId, ledOnPC01.pinNum, GPIO_PIN_RESET); } - if(tmpBttnWasDisabled != tmpBttnIsDisabled){ if(tmpBttnIsDisabled){ HAL_GPIO_WritePin(ledOnPA04.portId, ledOnPA04.pinNum, GPIO_PIN_SET); diff --git a/Examples/10_HntdTmLtchMPBttn_b.h b/Examples/10_HntdTmLtchMPBttn_b.h new file mode 100644 index 0000000..c6827ed --- /dev/null +++ b/Examples/10_HntdTmLtchMPBttn_b.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 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. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#ifndef __STM32F4xx_HAL_H + #include "stm32f4xx_hal.h" +#endif + +/* Private defines -----------------------------------------------------------*/ +#define USART_TX_Pin GPIO_PIN_2 +#define USART_TX_GPIO_Port GPIOA +#define USART_RX_Pin GPIO_PIN_3 +#define USART_RX_GPIO_Port GPIOA + +//#define TMS_Pin GPIO_PIN_13 +//#define TMS_GPIO_Port GPIOA + +//#define TCK_Pin GPIO_PIN_14 +//#define TCK_GPIO_Port GPIOA + +//#define SWO_Pin GPIO_PIN_3 +//#define SWO_GPIO_Port GPIOB + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Examples/11_SldrLtchMPBttn_2a.cpp.txt b/Examples/11_SldrDALtchMPBttn_2a.cpp.txt similarity index 100% rename from Examples/11_SldrLtchMPBttn_2a.cpp.txt rename to Examples/11_SldrDALtchMPBttn_2a.cpp.txt diff --git a/Examples/11_SldrLtchMPBttn_2b.cpp.txt b/Examples/11_SldrDALtchMPBttn_2b.cpp.txt similarity index 100% rename from Examples/11_SldrLtchMPBttn_2b.cpp.txt rename to Examples/11_SldrDALtchMPBttn_2b.cpp.txt