Ignore:
Timestamp:
Feb 7, 2025, 2:56:14 PM (3 months ago)
Author:
Zed
Message:

Added TIM6 in CubeMX to generate 1µs delays for 1-Wire Protocol.

Location:
ctrl/firmware/Main/CubeMX/Core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ctrl/firmware/Main/CubeMX/Core/Inc/main.h

    r81 r84  
    9898#define SD_DETECT_Pin GPIO_PIN_8
    9999#define SD_DETECT_GPIO_Port GPIOA
     100#define ONEWIRE_TEMP_BUS_Pin GPIO_PIN_15
     101#define ONEWIRE_TEMP_BUS_GPIO_Port GPIOA
    100102#define ETH_SPI_PWR_Pin GPIO_PIN_3
    101103#define ETH_SPI_PWR_GPIO_Port GPIOD
  • ctrl/firmware/Main/CubeMX/Core/Inc/tim.h

    r66 r84  
    3535extern TIM_HandleTypeDef htim3;
    3636
     37extern TIM_HandleTypeDef htim6;
     38
    3739extern TIM_HandleTypeDef htim8;
    3840
     
    4244
    4345void MX_TIM3_Init(void);
     46void MX_TIM6_Init(void);
    4447void MX_TIM8_Init(void);
    4548
  • ctrl/firmware/Main/CubeMX/Core/Src/freertos.c

    r83 r84  
    2323#include "main.h"
    2424#include "cmsis_os.h"
    25 #include "queue.h"
    2625
    2726/* Private includes ----------------------------------------------------------*/
     
    2928
    3029#include <stdio.h>
     30
     31#include "queue.h"
    3132
    3233#include "keys_task.h"
     
    3435#include "mb_slave_task.h"
    3536#include "beeper_task.h"
     37#include "onewire_task.h"
    3638
    3739/* USER CODE END Includes */
     
    5052#define MB_SLAVE_TASK_STACK_DEPTH_WORDS                         (1024U)
    5153#define BEEPER_TASK_STACK_DEPTH_WORDS                           (128U)
     54#define ONEWIRE_TASK_STACK_DEPTH_WORDS                          (128U)
    5255
    5356/* USER CODE END PD */
     
    6568static StackType_t mbSlaveTaskStackBuffer[MB_SLAVE_TASK_STACK_DEPTH_WORDS]                              __attribute__((section(".DTCM_RAM")));
    6669static StackType_t beeperTaskStackBuffer[BEEPER_TASK_STACK_DEPTH_WORDS]                                 __attribute__((section(".DTCM_RAM")));
     70static StackType_t onewireTaskStackBuffer[ONEWIRE_TASK_STACK_DEPTH_WORDS]                               __attribute__((section(".DTCM_RAM")));
     71
    6772static uint8_t beeperQueueStorageArea[BEEPER_QUEUE_SIZE * BEEPER_QUEUE_ITEM_SIZE]               __attribute__((section(".DTCM_RAM")));
    68 
    69 static StaticTask_t keysTaskBuffer;
    70 static StaticTask_t ethTaskBuffer;
    71 static StaticTask_t mbSlaveTaskBuffer;
    72 static StaticTask_t beeperTaskBuffer;
    73 static StaticQueue_t beeperQueueBuffer;
     73static uint8_t onewireQueueStorageArea[ONEWIRE_QUEUE_SIZE * ONEWIRE_QUEUE_ITEM_SIZE]    __attribute__((section(".DTCM_RAM")));
     74
     75static StaticTask_t keysTaskBuffer                                                                                                              __attribute__((section(".DTCM_RAM")));
     76static StaticTask_t ethTaskBuffer                                                                                                               __attribute__((section(".DTCM_RAM")));
     77static StaticTask_t mbSlaveTaskBuffer                                                                                                   __attribute__((section(".DTCM_RAM")));
     78static StaticTask_t beeperTaskBuffer                                                                                                    __attribute__((section(".DTCM_RAM")));
     79static StaticTask_t onewireTaskBuffer                                                                                                   __attribute__((section(".DTCM_RAM")));
     80
     81static StaticQueue_t beeperQueueBuffer                                                                                                  __attribute__((section(".DTCM_RAM")));
     82static StaticQueue_t onewireQueueBuffer                                                                                                 __attribute__((section(".DTCM_RAM")));
    7483
    7584static const char* const keysTaskName = "ScanKeysTask";
     
    7786static const char* const mbSlaveTaskName = "MBSlaveTask";
    7887static const char* const beeperTaskName = "BeeperTask";
    79 
     88static const char* const onewireTaskName = "1WireTask";
    8089
    8190
     
    154163  if (beeperQueue == NULL) printf("Cannot create Beeper Queue!\n");
    155164
     165  onewireQueue = xQueueCreateStatic(ONEWIRE_QUEUE_SIZE, ONEWIRE_QUEUE_ITEM_SIZE, onewireQueueStorageArea, &onewireQueueBuffer);
     166  if (onewireQueue == NULL) printf("Cannot create 1-Wire Queue!\n");
     167
    156168  /* USER CODE END RTOS_QUEUES */
    157169
     
    174186  r = xTaskCreateStatic(beeperTaskStart, beeperTaskName, BEEPER_TASK_STACK_DEPTH_WORDS, NULL, 25, beeperTaskStackBuffer, &beeperTaskBuffer);
    175187  if (r == NULL) printf("Cannot create %s!\n", beeperTaskName);
     188
     189  r = xTaskCreateStatic(onewireTaskStart, onewireTaskName, ONEWIRE_TASK_STACK_DEPTH_WORDS, NULL, 25, onewireTaskStackBuffer, &onewireTaskBuffer);
     190  if (r == NULL) printf("Cannot create %s!\n", onewireTaskName);
    176191
    177192  /* USER CODE END RTOS_THREADS */
  • ctrl/firmware/Main/CubeMX/Core/Src/gpio.c

    r81 r84  
    7171
    7272  /*Configure GPIO pin Output Level */
     73  HAL_GPIO_WritePin(ONEWIRE_TEMP_BUS_GPIO_Port, ONEWIRE_TEMP_BUS_Pin, GPIO_PIN_RESET);
     74
     75  /*Configure GPIO pin Output Level */
    7376  HAL_GPIO_WritePin(ETH_SPI_PWR_GPIO_Port, ETH_SPI_PWR_Pin, GPIO_PIN_SET);
    7477
     
    116119  /*Configure GPIO pins : PA0 PA1 PA2 PA3
    117120                           PA4 PA5 PA6 PA7
    118                            PA9 PA10 PA11 PA12
    119                            PA15 */
     121                           PA9 PA10 PA11 PA12 */
    120122  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
    121123                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
    122                           |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12
    123                           |GPIO_PIN_15;
     124                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
    124125  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
    125126  GPIO_InitStruct.Pull = GPIO_NOPULL;
     
    185186  HAL_GPIO_Init(SD_DETECT_GPIO_Port, &GPIO_InitStruct);
    186187
     188  /*Configure GPIO pin : ONEWIRE_TEMP_BUS_Pin */
     189  GPIO_InitStruct.Pin = ONEWIRE_TEMP_BUS_Pin;
     190  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
     191  GPIO_InitStruct.Pull = GPIO_NOPULL;
     192  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     193  HAL_GPIO_Init(ONEWIRE_TEMP_BUS_GPIO_Port, &GPIO_InitStruct);
     194
    187195  /*Configure GPIO pins : ETH_SPI_NSS_Pin ETH_SPI_RST_Pin */
    188196  GPIO_InitStruct.Pin = ETH_SPI_NSS_Pin|ETH_SPI_RST_Pin;
  • ctrl/firmware/Main/CubeMX/Core/Src/main.c

    r83 r84  
    136136  MX_USART2_UART_Init();
    137137  MX_USART10_UART_Init();
     138  MX_TIM6_Init();
    138139  /* USER CODE BEGIN 2 */
    139140
  • ctrl/firmware/Main/CubeMX/Core/Src/tim.c

    r72 r84  
    2626
    2727TIM_HandleTypeDef htim3;
     28TIM_HandleTypeDef htim6;
    2829TIM_HandleTypeDef htim8;
    2930
     
    8283  /* USER CODE END TIM3_Init 2 */
    8384  HAL_TIM_MspPostInit(&htim3);
     85
     86}
     87/* TIM6 init function */
     88void MX_TIM6_Init(void)
     89{
     90
     91  /* USER CODE BEGIN TIM6_Init 0 */
     92
     93  /* USER CODE END TIM6_Init 0 */
     94
     95  TIM_MasterConfigTypeDef sMasterConfig = {0};
     96
     97  /* USER CODE BEGIN TIM6_Init 1 */
     98
     99  /* USER CODE END TIM6_Init 1 */
     100  htim6.Instance = TIM6;
     101  htim6.Init.Prescaler = 99;
     102  htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
     103  htim6.Init.Period = 65535;
     104  htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
     105  if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
     106  {
     107    Error_Handler();
     108  }
     109  if (HAL_TIM_OnePulse_Init(&htim6, TIM_OPMODE_SINGLE) != HAL_OK)
     110  {
     111    Error_Handler();
     112  }
     113  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
     114  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
     115  if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
     116  {
     117    Error_Handler();
     118  }
     119  /* USER CODE BEGIN TIM6_Init 2 */
     120
     121  /* USER CODE END TIM6_Init 2 */
    84122
    85123}
     
    167205
    168206  /* USER CODE END TIM3_MspInit 1 */
     207  }
     208  else if(tim_baseHandle->Instance==TIM6)
     209  {
     210  /* USER CODE BEGIN TIM6_MspInit 0 */
     211
     212  /* USER CODE END TIM6_MspInit 0 */
     213    /* TIM6 clock enable */
     214    __HAL_RCC_TIM6_CLK_ENABLE();
     215  /* USER CODE BEGIN TIM6_MspInit 1 */
     216
     217  /* USER CODE END TIM6_MspInit 1 */
    169218  }
    170219  else if(tim_baseHandle->Instance==TIM8)
     
    243292  /* USER CODE END TIM3_MspDeInit 1 */
    244293  }
     294  else if(tim_baseHandle->Instance==TIM6)
     295  {
     296  /* USER CODE BEGIN TIM6_MspDeInit 0 */
     297
     298  /* USER CODE END TIM6_MspDeInit 0 */
     299    /* Peripheral clock disable */
     300    __HAL_RCC_TIM6_CLK_DISABLE();
     301  /* USER CODE BEGIN TIM6_MspDeInit 1 */
     302
     303  /* USER CODE END TIM6_MspDeInit 1 */
     304  }
    245305  else if(tim_baseHandle->Instance==TIM8)
    246306  {
Note: See TracChangeset for help on using the changeset viewer.