Browse Source

add code to do tristate led blinking...

This was for a project that is now partly abandoned due to cell
phone camera limitations...
blinkled
John-Mark Gurney 2 years ago
parent
commit
a4f76dc0bb
7 changed files with 12318 additions and 3 deletions
  1. +3
    -0
      blinkled/Makefile
  2. +102
    -3
      blinkled/main.c
  3. +4
    -0
      stm32/.srcs
  4. +7483
    -0
      stm32/f103c8t6/stm32f1xx_hal_tim.c
  5. +2129
    -0
      stm32/f103c8t6/stm32f1xx_hal_tim.h
  6. +2335
    -0
      stm32/f103c8t6/stm32f1xx_hal_tim_ex.c
  7. +262
    -0
      stm32/f103c8t6/stm32f1xx_hal_tim_ex.h

+ 3
- 0
blinkled/Makefile View File

@@ -38,9 +38,12 @@ PROGS = blinkled

SRCS.blinkled = main.c
SRCS.blinkled+= $(SRCTOP)/rs485hid/memdebug.c
SRCS.blinkled+= stm32f1xx_hal_tim.c
SRCS.blinkled+= stm32f1xx_hal_tim_ex.c

CFLAGS+= -I$(.CURDIR)
CFLAGS+= -g
CFLAGS+= -DHAL_TIM_MODULE_ENABLED=1
#CFLAGS+= -DNDEBUG

WITH_STM32F103 = yes


+ 102
- 3
blinkled/main.c View File

@@ -30,16 +30,25 @@

#include <sysinit.h>

#include <stm32f1xx_hal.h>
#include <main.h>

static void
c13led(const void *none)
c13led(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();

GPIO_InitStruct = (GPIO_InitTypeDef){
.Pin = GPIO_PIN_3,
.Mode = GPIO_MODE_OUTPUT_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_LOW,
};
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct = (GPIO_InitTypeDef){
.Pin = GPIO_PIN_13,
.Mode = GPIO_MODE_OUTPUT_PP,
@@ -50,7 +59,58 @@ c13led(const void *none)

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
}
SYSINIT(c13led, SI_SUB_HAL, SI_ORDER_SECOND, c13led, NULL);
SYSINIT_VF(c13led, SI_SUB_HAL, SI_ORDER_SECOND, c13led);

static TIM_HandleTypeDef htim2;

/* 36.2.2 Step 1 */
void
HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
{
}

#define PERIOD_VALUE (700 - 1)

void
tim2ch4(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
uint32_t uhPrescalerValue;

/*
* various parts from F1's
* Projects/STM3210E_EVAL/Examples/TIM/TIM_PWMOutput/Src/main.c
*/
uhPrescalerValue = (uint32_t)(SystemCoreClock / 2000000) - 1;

/* 36.2.2 Step 2a */
__HAL_RCC_TIM2_CLK_ENABLE();

/* 36.2.2 Step 2b */
__HAL_RCC_GPIOA_CLK_ENABLE();

GPIO_InitStruct = (GPIO_InitTypeDef){
.Pin = GPIO_PIN_3,
.Mode = GPIO_MODE_AF_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_LOW,
};
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* 36.2.2 Step 4 */
htim2 = (TIM_HandleTypeDef){
.Instance = TIM2,

/* TIM_Base_InitTypeDef */
.Init.Prescaler = uhPrescalerValue,
.Init.Period = PERIOD_VALUE,
.Init.CounterMode = TIM_COUNTERMODE_UP,
.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE,
};
HAL_TIM_PWM_Init(&htim2);

}
SYSINIT_VF(tim2ch4, SI_SUB_HAL, SI_ORDER_THIRD, tim2ch4);

int
main(void)
@@ -58,11 +118,50 @@ main(void)

debug_printf("starting...\n");

#if 0
/* toggle on LED */
for (;;) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(250);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(250);
}
#else
/* PA3 TIM2_CH4 */
TIM_OC_InitTypeDef oconfig;
oconfig = (TIM_OC_InitTypeDef){
.OCMode = TIM_OCMODE_PWM1,
.OCPolarity = TIM_OCPOLARITY_HIGH,
.OCFastMode = TIM_OCFAST_DISABLE,
.OCNPolarity = TIM_OCNPOLARITY_HIGH,
.OCNIdleState = TIM_OCNIDLESTATE_RESET,

.OCIdleState = TIM_OCIDLESTATE_RESET,

.Pulse = PERIOD_VALUE, // OFF
};
HAL_TIM_PWM_ConfigChannel(&htim2, &oconfig, TIM_CHANNEL_4);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);
for (int i = 0;; i = (i + 1) % 3) {
switch (i) {
case 0:
TIM2->CCR4 = PERIOD_VALUE;
break;
case 1:
TIM2->CCR4 = PERIOD_VALUE / 2;
break;
case 2:
TIM2->CCR4 = 0;
break;
}
#if 0
HAL_Delay(100);
#else
HAL_Delay(35);
#endif
}
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4);
#endif
}

+ 4
- 0
stm32/.srcs View File

@@ -35,6 +35,10 @@ f103c8t6/stm32f1xx_hal_rcc_ex.c STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Src/stm
f103c8t6/stm32f1xx_hal_rcc_ex.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h
f103c8t6/stm32f1xx_hal_rtc.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rtc.h
f103c8t6/stm32f1xx_hal_rtc_ex.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rtc_ex.h
f103c8t6/stm32f1xx_hal_tim.c STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c
f103c8t6/stm32f1xx_hal_tim_ex.c STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c
f103c8t6/stm32f1xx_hal_tim.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h
f103c8t6/stm32f1xx_hal_tim_ex.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h
f103c8t6/stm32f1xx_hal_uart.c STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
f103c8t6/stm32f1xx_hal_uart.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h
f103c8t6/stm32f1xx_ll_usb.h STM32CubeF1 Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h

+ 7483
- 0
stm32/f103c8t6/stm32f1xx_hal_tim.c
File diff suppressed because it is too large
View File


+ 2129
- 0
stm32/f103c8t6/stm32f1xx_hal_tim.h
File diff suppressed because it is too large
View File


+ 2335
- 0
stm32/f103c8t6/stm32f1xx_hal_tim_ex.c
File diff suppressed because it is too large
View File


+ 262
- 0
stm32/f103c8t6/stm32f1xx_hal_tim_ex.h View File

@@ -0,0 +1,262 @@
/**
******************************************************************************
* @file stm32f1xx_hal_tim_ex.h
* @author MCD Application Team
* @brief Header file of TIM HAL Extended module.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32F1xx_HAL_TIM_EX_H
#define STM32F1xx_HAL_TIM_EX_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal_def.h"

/** @addtogroup STM32F1xx_HAL_Driver
* @{
*/

/** @addtogroup TIMEx
* @{
*/

/* Exported types ------------------------------------------------------------*/
/** @defgroup TIMEx_Exported_Types TIM Extended Exported Types
* @{
*/

/**
* @brief TIM Hall sensor Configuration Structure definition
*/

typedef struct
{
uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
This parameter can be a value of @ref TIM_Input_Capture_Polarity */

uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
This parameter can be a value of @ref TIM_Input_Capture_Prescaler */

uint32_t IC1Filter; /*!< Specifies the input capture filter.
This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */

uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
} TIM_HallSensor_InitTypeDef;
/**
* @}
*/
/* End of exported types -----------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/
/** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
* @{
*/

/** @defgroup TIMEx_Remap TIM Extended Remapping
* @{
*/
/**
* @}
*/

/**
* @}
*/
/* End of exported constants -------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/
/** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
* @{
*/

/**
* @}
*/
/* End of exported macro -----------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/
/** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
* @{
*/

/**
* @}
*/
/* End of private macro ------------------------------------------------------*/

/* Exported functions --------------------------------------------------------*/
/** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
* @{
*/

/** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
* @brief Timer Hall Sensor functions
* @{
*/
/* Timer Hall Sensor functions **********************************************/
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);

void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);

/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
/**
* @}
*/

/** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
* @brief Timer Complementary Output Compare functions
* @{
*/
/* Timer Complementary Output Compare functions *****************************/
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);

/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);

/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
/**
* @}
*/

/** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
* @brief Timer Complementary PWM functions
* @{
*/
/* Timer Complementary PWM functions ****************************************/
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);

/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
/* Non-Blocking mode: DMA */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
/**
* @}
*/

/** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
* @brief Timer Complementary One Pulse functions
* @{
*/
/* Timer Complementary One Pulse functions **********************************/
/* Blocking mode: Polling */
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);

/* Non-Blocking mode: Interrupt */
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
/**
* @}
*/

/** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
* @brief Peripheral Control functions
* @{
*/
/* Extended Control functions ************************************************/
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
uint32_t CommutationSource);
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
uint32_t CommutationSource);
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
uint32_t CommutationSource);
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
TIM_MasterConfigTypeDef *sMasterConfig);
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
/**
* @}
*/

/** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
* @brief Extended Callbacks functions
* @{
*/
/* Extended Callback **********************************************************/
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
/**
* @}
*/

/** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
* @brief Extended Peripheral State functions
* @{
*/
/* Extended Peripheral State functions ***************************************/
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim);
HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim, uint32_t ChannelN);
/**
* @}
*/

/**
* @}
*/
/* End of exported functions -------------------------------------------------*/

/* Private functions----------------------------------------------------------*/
/** @addtogroup TIMEx_Private_Functions TIMEx Private Functions
* @{
*/
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
/**
* @}
*/
/* End of private functions --------------------------------------------------*/

/**
* @}
*/

/**
* @}
*/

#ifdef __cplusplus
}
#endif


#endif /* STM32F1xx_HAL_TIM_EX_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Loading…
Cancel
Save