Skip to content

Commit 66ed60b

Browse files
committed
setup timer
1 parent 07152e8 commit 66ed60b

38 files changed

+11750
-13166
lines changed

stm_workspace/hydrophone/Core/Inc/main.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,12 @@ void Error_Handler(void);
6464
#define B1_GPIO_Port GPIOC
6565
#define MCO_Pin GPIO_PIN_0
6666
#define MCO_GPIO_Port GPIOH
67-
#define USART_TX_Pin GPIO_PIN_2
68-
#define USART_TX_GPIO_Port GPIOA
69-
#define USART_RX_Pin GPIO_PIN_3
70-
#define USART_RX_GPIO_Port GPIOA
7167
#define SMPS_V1_Pin GPIO_PIN_5
7268
#define SMPS_V1_GPIO_Port GPIOA
7369
#define SMPS_PG_Pin GPIO_PIN_6
7470
#define SMPS_PG_GPIO_Port GPIOA
7571
#define SMPS_SW_Pin GPIO_PIN_7
7672
#define SMPS_SW_GPIO_Port GPIOA
77-
#define LD4_Pin GPIO_PIN_13
78-
#define LD4_GPIO_Port GPIOB
7973
#define TMS_Pin GPIO_PIN_13
8074
#define TMS_GPIO_Port GPIOA
8175
#define TCK_Pin GPIO_PIN_14

stm_workspace/hydrophone/Core/Src/main.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
/* Private includes ----------------------------------------------------------*/
2323
/* USER CODE BEGIN Includes */
24-
2524
/* USER CODE END Includes */
2625

2726
/* Private typedef -----------------------------------------------------------*/
@@ -51,21 +50,32 @@ UART_HandleTypeDef huart2;
5150
/* Private function prototypes -----------------------------------------------*/
5251
void SystemClock_Config(void);
5352
static void MX_GPIO_Init(void);
54-
static void MX_USART2_UART_Init(void);
5553
static void MX_TIM2_Init(void);
54+
static void MX_USART2_UART_Init(void);
5655
/* USER CODE BEGIN PFP */
56+
#ifdef __GNUC__
57+
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
58+
#else
59+
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
60+
#endif
5761

62+
PUTCHAR_PROTOTYPE
63+
{
64+
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
65+
return ch;
66+
}
5867
/* USER CODE END PFP */
5968

6069
/* Private user code ---------------------------------------------------------*/
6170
/* USER CODE BEGIN 0 */
62-
void sineF32(const float32_t frequency, const float32_t amplitude, const float32_t offset, float32_t time, const float32_t alignment, uint32_t *pOut) {
71+
void sineF32(const float32_t frequency, const float32_t amplitude, const float32_t offset, float32_t time, float32_t *pOut) {
6372
float32_t point;
6473
point = amplitude * arm_sin_f32((2*M_PI*frequency)*time) + offset;
65-
*pOut = (uint32_t) roundf(point * alignment);
74+
*pOut = point;
6675
}
6776

68-
static uint32_t sineValues[40];
77+
static float32_t sineValues[1024];
78+
static uint32_t sec = 0;
6979
/* USER CODE END 0 */
7080

7181
/**
@@ -96,17 +106,20 @@ int main(void)
96106

97107
/* Initialize all configured peripherals */
98108
MX_GPIO_Init();
99-
MX_USART2_UART_Init();
100109
MX_TIM2_Init();
110+
MX_USART2_UART_Init();
101111
/* USER CODE BEGIN 2 */
102-
float32_t x = 0.0f;
112+
HAL_TIM_Base_Start_IT(&htim2);
113+
/*float32_t x = 0.0f;
103114
float32_t fx;
104-
for (uint8_t i = 0; i < 40; i++) {
105-
uint32_t *y = &sineValues[i];
106-
sineF32(1102.3f, 0.333f, 0.5f, x, 4095, y);
107-
x += 0.00002268f;
108-
}
109-
fx = fft(sineValues, 40, 1102.3f, 92972972.97297);
115+
HAL_UART_Transmit(&huart2, (uint8_t *)"hello", 5, HAL_MAX_DELAY);
116+
for (uint16_t i = 0; i < 1024; i += 2) {
117+
float32_t *y = &sineValues[i];
118+
sineF32(1102.3f, 0.5f, 0.5f, x, y);
119+
sineValues[i+1] = 0;
120+
x += 0.00002268f;
121+
}
122+
fx = fft(sineValues, 1024, 1102, 92972972.97297);*/
110123
/* USER CODE END 2 */
111124

112125
/* Infinite loop */
@@ -190,7 +203,7 @@ static void MX_TIM2_Init(void)
190203
htim2.Instance = TIM2;
191204
htim2.Init.Prescaler = 0;
192205
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
193-
htim2.Init.Period = 1814;
206+
htim2.Init.Period = 80000000;
194207
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
195208
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
196209
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
@@ -269,9 +282,6 @@ static void MX_GPIO_Init(void)
269282
/*Configure GPIO pin Output Level */
270283
HAL_GPIO_WritePin(GPIOA, SMPS_V1_Pin|SMPS_SW_Pin, GPIO_PIN_RESET);
271284

272-
/*Configure GPIO pin Output Level */
273-
HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);
274-
275285
/*Configure GPIO pin : B1_Pin */
276286
GPIO_InitStruct.Pin = B1_Pin;
277287
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
@@ -291,18 +301,15 @@ static void MX_GPIO_Init(void)
291301
GPIO_InitStruct.Pull = GPIO_PULLUP;
292302
HAL_GPIO_Init(SMPS_PG_GPIO_Port, &GPIO_InitStruct);
293303

294-
/*Configure GPIO pin : LD4_Pin */
295-
GPIO_InitStruct.Pin = LD4_Pin;
296-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
297-
GPIO_InitStruct.Pull = GPIO_NOPULL;
298-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
299-
HAL_GPIO_Init(LD4_GPIO_Port, &GPIO_InitStruct);
300-
301304
/* USER CODE BEGIN MX_GPIO_Init_2 */
302305
/* USER CODE END MX_GPIO_Init_2 */
303306
}
304307

305308
/* USER CODE BEGIN 4 */
309+
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
310+
sec++;
311+
printf("%d microseconds\r\n", sec);
312+
}
306313
/* USER CODE END 4 */
307314

308315
/**

stm_workspace/hydrophone/Core/Src/ping.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@ const arm_cfft_instance_f32 instance = {
88
};
99

1010

11-
float32_t fft(uint32_t* buff, uint32_t size, uint32_t target, float32_t fs)
11+
float32_t fft(float32_t* buff, uint32_t size, uint32_t target, float32_t fs)
1212
{
13-
float32_t temp_buff[size];
14-
for (int i = 0; i < size; i++)
15-
{
16-
temp_buff[i] = (float32_t) buff[i];
17-
}
1813

19-
arm_cfft_f32(&arm_cfft_sR_f32_len512, temp_buff, 0, 0);
14+
arm_cfft_f32(&instance, buff, 0, 0);
2015

2116
float32_t freq[size / 2];
22-
arm_cmplx_mag_f32(temp_buff, freq, size / 2);
17+
arm_cmplx_mag_f32(buff, freq, size / 2);
2318

2419
uint32_t target_bin = (uint32_t) (target * size / fs);
2520

stm_workspace/hydrophone/Core/Src/stm32l4xx_hal_msp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
160160
PA2 ------> USART2_TX
161161
PA3 ------> USART2_RX
162162
*/
163-
GPIO_InitStruct.Pin = USART_TX_Pin|USART_RX_Pin;
163+
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
164164
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
165165
GPIO_InitStruct.Pull = GPIO_NOPULL;
166166
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
@@ -194,7 +194,7 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
194194
PA2 ------> USART2_TX
195195
PA3 ------> USART2_RX
196196
*/
197-
HAL_GPIO_DeInit(GPIOA, USART_TX_Pin|USART_RX_Pin);
197+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
198198

199199
/* USER CODE BEGIN USART2_MspDeInit 1 */
200200

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
../Core/Src/main.c:62:6:sineF32 1
2-
../Core/Src/main.c:75:5:main 2
3-
../Core/Src/main.c:127:6:SystemClock_Config 4
4-
../Core/Src/main.c:177:13:MX_TIM2_Init 4
5-
../Core/Src/main.c:222:13:MX_USART2_UART_Init 2
6-
../Core/Src/main.c:257:13:MX_GPIO_Init 1
7-
../Core/Src/main.c:312:6:Error_Handler 1
1+
../Core/Src/main.c:62:1:__io_putchar 1
2+
../Core/Src/main.c:71:6:sineF32 1
3+
../Core/Src/main.c:85:5:main 1
4+
../Core/Src/main.c:140:6:SystemClock_Config 4
5+
../Core/Src/main.c:190:13:MX_TIM2_Init 4
6+
../Core/Src/main.c:235:13:MX_USART2_UART_Init 2
7+
../Core/Src/main.c:270:13:MX_GPIO_Init 1
8+
../Core/Src/main.c:309:6:HAL_TIM_PeriodElapsedCallback 1
9+
../Core/Src/main.c:319:6:Error_Handler 1
792 Bytes
Binary file not shown.
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
../Core/Src/main.c:62:6:sineF32 48 static
2-
../Core/Src/main.c:75:5:main 24 static
3-
../Core/Src/main.c:127:6:SystemClock_Config 96 static
4-
../Core/Src/main.c:177:13:MX_TIM2_Init 40 static
5-
../Core/Src/main.c:222:13:MX_USART2_UART_Init 8 static
6-
../Core/Src/main.c:257:13:MX_GPIO_Init 48 static
7-
../Core/Src/main.c:312:6:Error_Handler 4 static,ignoring_inline_asm
1+
../Core/Src/main.c:62:1:__io_putchar 16 static
2+
../Core/Src/main.c:71:6:sineF32 48 static
3+
../Core/Src/main.c:85:5:main 8 static
4+
../Core/Src/main.c:140:6:SystemClock_Config 96 static
5+
../Core/Src/main.c:190:13:MX_TIM2_Init 40 static
6+
../Core/Src/main.c:235:13:MX_USART2_UART_Init 8 static
7+
../Core/Src/main.c:270:13:MX_GPIO_Init 48 static
8+
../Core/Src/main.c:309:6:HAL_TIM_PeriodElapsedCallback 16 static
9+
../Core/Src/main.c:319:6:Error_Handler 4 static,ignoring_inline_asm
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
../Core/Src/ping.c:11:11:fft 3
2-
../Core/Src/ping.c:35:10:get_frequency 4
3-
../Core/Src/ping.c:65:10:get_total_power 2
4-
../Core/Src/ping.c:78:10:get_power_at_target_frequency 4
5-
../Core/Src/ping.c:101:9:has_ping 2
1+
../Core/Src/ping.c:11:11:fft 2
2+
../Core/Src/ping.c:30:10:get_frequency 4
3+
../Core/Src/ping.c:60:10:get_total_power 2
4+
../Core/Src/ping.c:73:10:get_power_at_target_frequency 4
5+
../Core/Src/ping.c:96:9:has_ping 2
-336 Bytes
Binary file not shown.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
../Core/Src/ping.c:11:11:fft 96 dynamic
2-
../Core/Src/ping.c:35:10:get_frequency 120 dynamic
3-
../Core/Src/ping.c:65:10:get_total_power 32 static
4-
../Core/Src/ping.c:78:10:get_power_at_target_frequency 40 static
5-
../Core/Src/ping.c:101:9:has_ping 72 static
1+
../Core/Src/ping.c:11:11:fft 72 dynamic
2+
../Core/Src/ping.c:30:10:get_frequency 120 dynamic
3+
../Core/Src/ping.c:60:10:get_total_power 32 static
4+
../Core/Src/ping.c:73:10:get_power_at_target_frequency 40 static
5+
../Core/Src/ping.c:96:9:has_ping 72 static

0 commit comments

Comments
 (0)