Skip to content

Commit

Permalink
Example code files update
Browse files Browse the repository at this point in the history
  • Loading branch information
GabyGold67 committed May 22, 2024
1 parent 64ac34e commit c0117b2
Show file tree
Hide file tree
Showing 15 changed files with 511 additions and 273 deletions.
2 changes: 1 addition & 1 deletion Examples/06_TmLtchdMPBttn_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -18,28 +19,33 @@
*
******************************************************************************
*/
/* 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 */

/* Private variables ---------------------------------------------------------*/
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;

Expand All @@ -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.
Expand All @@ -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 */
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
53 changes: 53 additions & 0 deletions Examples/07_XtrnUnltchMPBttn_2a.h
Original file line number Diff line number Diff line change
@@ -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 */
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -21,28 +23,34 @@
*
******************************************************************************
*/
/* 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 */

/* Private variables ---------------------------------------------------------*/
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;

Expand All @@ -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.
Expand All @@ -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 */
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -245,7 +242,7 @@ void tstDefTaskExec(void *pvParameters)
pdTRUE,
tstBttnPtr,
swpEnableCb
);
);
if (enableSwpTmrHndl != NULL){
tmrModRslt = xTimerStart(enableSwpTmrHndl, portMAX_DELAY);
if(tmrModRslt == pdFAIL)
Expand All @@ -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;
Expand Down
Loading

0 comments on commit c0117b2

Please sign in to comment.