diff --git a/Core/Inc/ev1527.h b/Core/Inc/ev1527.h index 040f18a..dc52a02 100644 --- a/Core/Inc/ev1527.h +++ b/Core/Inc/ev1527.h @@ -17,6 +17,13 @@ #include <string.h> #include <stdbool.h> +#define RF_Read_TIM_RCC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE) +#define RF_Read_TIM_TIMx TIM3 +#define RF_Read_TIM_IRQn TIM3_IRQn +#define RF_Read_TIM_Priority_1 2 +#define RF_Read_TIM_Priority_2 2 +#define RF_Read_TIM_IRQHandler TIM3_IRQHandler + /*********433 DATA GPIO**********/ // 433数据输入 @@ -25,9 +32,22 @@ #define DATA_433_GPIO_PORT GPIOA #define DATA_433_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE(); #endif + /*******************************/ void EV1527_Init(void); void RF_Signal_Decode(void); +// void Delay_us(uint32_t cnt); + +void STS_RF_write_send_1(void); +void STS_RF_write_send_0(void); +void STS_RF_write_send_leading(void); + +void STS_RF_write_send_ending(void); +void STS_RF_Send_Multi_Times(uint8_t *rf_payload, uint8_t rf_length, uint8_t mt); +void STS_RF_Send_Button_Multi_Times(uint8_t *rf_payload, uint8_t one_button, uint8_t rf_length, uint8_t mt); +void STS_RF_Send_AddressBit_and_CmdBit(uint8_t *rf_payload, uint8_t rf_length); + + #endif diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 160a3c1..7d6dddb 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -90,6 +90,9 @@ void Error_Handler(void); #define USART1_TX_GPIO_Port GPIOB #ifdef RC +#define TIM1_PRESCALER_VALUE 47L // 1 us for stm32wle5xx 48Mhz +#define TIM1_PERIOD_VALUE 79L // 80 us + // REMOTE CONTROL EV1527/HS1527 LORA-WAN RELAY NODE #define RC_K0_Pin GPIO_PIN_5 @@ -159,9 +162,16 @@ void Error_Handler(void); #define RC_SHOW_30S 0x0C // 1100 -#define DATA_433_PIN GPIO_PIN_7 -#define DATA_433_GPIO_PORT GPIOA -#define DATA_433_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE(); +#define DATA_433_PIN GPIO_PIN_9 +#define DATA_433_GPIO_PORT GPIOA +#define DATA_433_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE(); + +#define RF_Send_GPIO_Port GPIOA +#define RF_Send_GPIO_Pin GPIO_PIN_8 + +#define RF_Receive_GPIO_Port GPIOA +#define RF_Receive_GPIO_Pin GPIO_PIN_9 +#define RF_Receive_GPIO_CLK_EN() __HAL_RCC_GPIOA_CLK_ENABLE(); #endif diff --git a/Core/Inc/stm32wlxx_hal_conf.h b/Core/Inc/stm32wlxx_hal_conf.h index bae70e9..660926c 100644 --- a/Core/Inc/stm32wlxx_hal_conf.h +++ b/Core/Inc/stm32wlxx_hal_conf.h @@ -54,7 +54,7 @@ /*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */ #define HAL_SUBGHZ_MODULE_ENABLED -/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ diff --git a/Core/Src/ev1527.c b/Core/Src/ev1527.c index 12f5bed..eef0a7d 100644 --- a/Core/Src/ev1527.c +++ b/Core/Src/ev1527.c @@ -7,11 +7,11 @@ * @copyright Copyright (c) 2024 * */ -#include "EV1527.h" - +#include "ev1527.h" +volatile uint32_t TIM1_cnt=0; // 定时周期 #define TIME_CYCLE 80 - +// #define TIME_CYCLE 20 // 定义引导码的最小和最大持续时间(单位:us) #define MIN_LEAD_CODE (5600 / TIME_CYCLE) #define MAX_LEAD_CODE (16000 / TIME_CYCLE) @@ -74,11 +74,10 @@ void EV1527_Init(void) // 配置上拉输入 GPIO_InitStruct.Pin = DATA_433_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; + //GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(DATA_433_GPIO_PORT, &GPIO_InitStruct); } - /**----------------------------------------------------------------------------------------------** **函数名 :RF信号解码函数 **功能说明:解码从433MHz接收到的信号,并根据解码结果执行相应功能 @@ -178,6 +177,106 @@ void RF_Signal_Decode(void) } } +#if 0 +/**----------------------------------------------------------------------------------------------** + **函数名 :RF信号解码函数 + **功能说明:解码从433MHz接收到的信号,并根据解码结果执行相应功能 + **调用说明:80us调用一次 + **----------------------------------------------------------------------------------------------**/ +void RF_Signal_Decode(void) +{ + switch (RF_Decode_State) + { + case LEAD_CODE: // 引导码 + // 判断是否低电平 + if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_RESET) + { + Lead_Code_Count++; + } + else // 高电平判断范围 + { + // 判断引导码范围是否合法 + if (Lead_Code_Count >= MIN_LEAD_CODE && Lead_Code_Count <= MAX_LEAD_CODE) + { + Lead_Code_Count = 0; + Reset_Decode_Parameters(); // 重置解码参数 + RF_Decode_State = HIGH_BIT; // 进入高位数据位判断状态 + } + else + { + Reset_Decode_Parameters(); // 引导码范围不合法,重置解码参数 + } + } + break; + + case HIGH_BIT: + // 判断是否高电平 + if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_SET) + { + High_Bit_Count++; + } + else // 低电平判断范围 + { + // 判断高位数据位范围是否合法 + if (High_Bit_Count >= MIN_BIT_DURATION && High_Bit_Count <= MAX_BIT_DURATION) + { + High_Bit_Duration = High_Bit_Count; // 保存计数值,用于区分0和1 + High_Bit_Count = 0; + RF_Decode_State = LOW_BIT; // 进入低位数据位判断状态 + } + else + { + Reset_Decode_Parameters(); // 高位数据位范围不合法,重置解码参数 + } + } + break; + + case LOW_BIT: + // 判断是否低电平 + if (HAL_GPIO_ReadPin(DATA_433_GPIO_PORT, DATA_433_PIN) == GPIO_PIN_RESET) + { + Low_Bit_Count++; + } + else // 高电平判断范围 + { + // 判断低位数据位范围是否合法 + if (Low_Bit_Count >= MIN_BIT_DURATION && Low_Bit_Count <= MAX_BIT_DURATION) + { + Low_Bit_Duration = Low_Bit_Count; // 保存计数值,用于区分0和1 + Low_Bit_Count = 0; + RF_Decode_State = DATA_PROCESS; // 进入数据处理状态 + } + else + { + Reset_Decode_Parameters(); // 低位数据位范围不合法,重置解码参数 + } + } + break; + + case DATA_PROCESS: + Decode_Data(); // 解码数据 + if (Received_Byte_Count == 3) + { + // 接收到全部数据,包括地址和数据 + RF_Decode_State = FUNCTION_PROCESS; + } + else + { // 数据没接收完 + RF_Decode_State = HIGH_BIT; // 继续解码数据 + } + break; + + case FUNCTION_PROCESS: + Execute_Function(); // 执行功能 + Reset_Decode_Parameters(); // 重置解码参数 + break; + + default: + Reset_Decode_Parameters(); // 默认状态,重置解码参数 + break; + } +} +#endif /**----------------------------------------------------------------------------------------------** **函数名 :Reset_Decode_Parameters **功能说明:重置解码参数,用于开始新的解码周期 @@ -274,3 +373,147 @@ void Execute_Function(void) break; } } + + +uint8_t RF; +uint8_t decode_ok; //解码成功 +uint8_t hh_w,ll_w; //高,低电平宽度 +uint8_t ma_x; //接收到第几位编码了 + +uint8_t bma1,bma2,bma3,bma4; //用于接收过程存放遥控编码,编码比较两次,这是第一次 +uint8_t mma1,mma2,mma3,mma4; +uint8_t mmb1,mmb2,mmb3,mmb4; //用于接收过程存放遥控编码,第二次 +//extern uint8_t mmbl,mmb2,mmb3,mmb4; +uint8_t rf_okl,rf_ok2,rf_ok; //解码过程中的临时接收成功标志,接收到一个完整的遥控命令后置1,通知解码程序可以解码了 + +uint8_t old_rc5; //保存上一次查询到的电平状态 +uint8_t tb_ok; //接收到同步的马时置1 +uint8_t D0,D1,D2,D3; +uint16_t s,s1; + +uint8_t bt_auto; //自动设置遥控接收波特率标志 +extern uint8_t rf_data[4]; +#if 0 +#define BIT1_HIGH_US 1000 // duty cycle = +#define BIT1_LOW_US 500 // +#define BIT0_HIGH_US 400 +#define BIT0_LOW_US 1100 +#endif + +#define BIT1_HIGH_US 1000 // duty cycle = +#define BIT1_LOW_US 500 // +#define BIT0_HIGH_US 250 +#define BIT0_LOW_US 1200 +#define ENDING_LOW_US 200 +#define ENDING_HIGH_US 12000 + +//#define CNT_SHORT_US 305 // 305 usec +#define LEADING_MS 12 // 8 msec +void STS_RF_write_send_1(void) +{ + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, SET); + + HAL_Delay_Us(BIT1_HIGH_US); + + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, RESET); + HAL_Delay_Us(BIT1_LOW_US); +} + +void STS_RF_write_send_0(void) +{ + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, SET); + HAL_Delay_Us(BIT0_HIGH_US); + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, RESET); + HAL_Delay_Us(BIT0_LOW_US); +} + +void STS_RF_write_send_leading(void) +{ +#if 0 + STS_RF_write_send_1(); + STS_RF_write_send_0(); + STS_RF_write_send_1(); +#endif + + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, RESET); + //HAL_Delay(CNT_LONG_MS); // 8 msec long low level + HAL_Delay_Us(LEADING_MS*1000); + HAL_Delay_Us(LEADING_MS*1000); + HAL_Delay_Us(LEADING_MS*1000); +} + +void STS_RF_write_send_ending(void) +{ + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, SET); + HAL_Delay_Us(ENDING_HIGH_US); + HAL_GPIO_WritePin(RF_Send_GPIO_Port, RF_Send_GPIO_Pin, RESET); + HAL_Delay_Us(ENDING_LOW_US); +} + +void STS_RF_Send_Button_Multi_Times(uint8_t *rf_payload, uint8_t one_button, uint8_t rf_length, uint8_t mt) +{ + // normally, send 5-8 cycles of same address and cmd code + uint8_t push_button_cmd = one_button; + + for (uint8_t i=0;i< mt;i++) + { + rf_payload[2] |= ((push_button_cmd)); + printf("%d : Address=%02X:%02X:%01x CMD=%01X\r\n",i, + rf_payload[0], rf_payload[1], rf_payload[2]&0xF0, push_button_cmd); + + STS_RF_Send_AddressBit_and_CmdBit(rf_payload, rf_length); + + rf_payload[2] &= 0xF0; // cmd set to 0 + } + +} + +void STS_RF_Send_Multi_Times(uint8_t *rf_payload, uint8_t rf_length, uint8_t mt) +{ + // normally, send 5-8 cycles of same address and cmd code + // uint8_t push_button_cmd = 0x01; + + + + for (uint8_t i=0;i< mt;i++) + { + rf_payload[2] |= ((i+1) <<4); + printf("%d : Address=%02X:%02X:%01x CMD=%01X\r\n",i, rf_payload[0],rf_payload[1],rf_payload[2]&0x0F, (rf_payload[2]>>4)&0x0F); + + STS_RF_Send_AddressBit_and_CmdBit(rf_payload, rf_length); + + rf_payload[2] &= 0x0F; // cmd set to 0 + } + +} + +void STS_RF_Send_AddressBit_and_CmdBit(uint8_t *rf_payload, uint8_t rf_length) +{ + // send the combined address code and cmd code + // 20 bit address + 4 bit cmd code == 24 bits == 3 bytes + + // send leading or sync signal for receiver to sync the RX clock + // printf("leading sync signal ...\r\n"); + STS_RF_write_send_leading(); + + // printf("address bits and cmd bits ...\r\n"); + // send address and cmd code + for (uint8_t i=0; i < rf_length; i++) + { + for (uint8_t j=0; j < 8; j++) + { + // if (0x01&(rf_payload[i]>>j)) // TODO XXXX if (0x80&(rf_payload[i]<<j)) + if (0x80&(rf_payload[i]<<j)) + { + STS_RF_write_send_1(); + } else { + STS_RF_write_send_0(); + } + } + } + STS_RF_write_send_ending(); + printf("ending bits ...\r\n"); +} + + + diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index a2daade..d6ff2b3 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -82,23 +82,23 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(BUT3_GPIO_Port, &GPIO_InitStruct); -#ifdef RC +#ifdef XRC /*Configure GPIO pins : PBPin PBPin PBPin */ - GPIO_InitStruct.Pin = RC_K0_Pin|RC_K1_Pin|RC_K2_Pin|RC_K3_Pin|RC_SET_Pin|RC_VT_Pin; + GPIO_InitStruct.Pin = RC_K0_Pin|RC_K1_Pin|RC_K2_Pin|RC_K3_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(RC_K0_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = RC_D0_Pin|RC_D1_Pin|RC_D2_Pin|RC_D3_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(RC_D0_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = RC_D4_Pin|RC_D5_Pin|RC_D6_Pin|RC_D7_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(RC_D4_GPIO_Port, &GPIO_InitStruct); @@ -109,13 +109,27 @@ void MX_GPIO_Init(void) HAL_GPIO_Init(RC_SET_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = RC_VT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(RC_VT_GPIO_Port, &GPIO_InitStruct); #endif + + GPIO_InitStruct.Pin = RF_Send_GPIO_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + HAL_GPIO_Init(RF_Send_GPIO_Port, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = RF_Receive_GPIO_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + HAL_GPIO_Init(RF_Receive_GPIO_Port, &GPIO_InitStruct); + + #ifdef L8 /*Configure GPIO pins : PAPin PAPin */ GPIO_InitStruct.Pin = TOF_INT_EXTI_PIN; @@ -159,26 +173,26 @@ void MX_GPIO_Init(void) #endif /* EXTI interrupt init*/ - HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI0_IRQn); - HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI1_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI1_IRQn); - HAL_NVIC_SetPriority(EXTI2_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI2_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI2_IRQn); - HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI3_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI3_IRQn); - HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI4_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI4_IRQn); - HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI9_5_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); - HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); + HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); diff --git a/Core/Src/main.c b/Core/Src/main.c index 2344b03..c52da32 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -23,6 +23,7 @@ #include "usart.h" #include "stdio.h" #include "ev1527.h" +#include "tim.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ // #include "i2c.h" @@ -31,6 +32,54 @@ // #include "sts_aq_o3.h" /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ +TIM_HandleTypeDef htim1; + +#if 1 +/* Captured Values */ +uint32_t uwIC2Value1 = 0; +uint32_t uwIC2Value2 = 0; +uint32_t uwDiffCapture = 0; + +/* Capture index */ +uint16_t uhCaptureIndex = 0; + +/* Frequency Value */ +uint32_t uwFrequency = 0; +#endif + +/* USER CODE BEGIN PV */ +#if 1 +/* Captured Value */ + uint32_t uwIC2Value = 0; +/* Duty Cycle Value */ + uint32_t uwDutyCycle = 0; +/* Frequency Value */ +// uint32_t uwFrequency = 0; +#endif + +#if 1 + uint32_t capture_Buf[3]={0}; // counter + uint8_t capture_Cnt=0; // state + uint32_t high_time, low_time; // high level duration, low level duration +#endif +//uint8_t rf_payload[3]={0xF8,0xCD,0x07}, rf_length=3; + +uint8_t rf_payload[3]={0x1F,0xB3,0xE0}, rf_length=3; +enum rf_cmd_enum +{ BUTTON_NONE=0, + BUTTON_ON, + BUTTON_OFF, + BUTTON_FIRST, + BUTTON_NEXT, + BUTTON_5S, + BUTTON_10S, + BUTTON_15S, + BUTTON_30S, + BUTTON_9,BUTTON_10,BUTTON_11,BUTTON_12,BUTTON_13,BUTTON_14,BUTTON_15, +}; + +uint8_t rf_cmd[16]={0x00, 0x8,0xC,0x4,0x6,0x1,0x9,0x2,0x3}; // cmd 1 = 1, cmd2=4, cmd3=3, cmd4=2 + void sts_rc_key(uint8_t key); void sts_rc_decoder(void); uint8_t sts_rc_decodedx(void); @@ -110,24 +159,118 @@ int main(void) - MX_LoRaWAN_Init(); + // MX_LoRaWAN_Init(); /* USER CODE BEGIN 2 */ MX_USART2_UART_Init(); MX_USART1_UART_Init(); + MX_TIM1_Init(); + + printf("start \r\n"); + + EV1527_Init(); + +#if 0 + /*## Start the Input Capture in interrupt mode ##########################*/ + if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK) + { + printf("tim1 ch2 start IT error \r\n"); + /* Starting Error */ + Error_Handler(); + } +#endif + + + +#if 0 + while (0) + { + HAL_Delay_Us(1000); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); + HAL_Delay_Us(1000); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + } +#endif + /* --------------------------------------------------------------------------- + TIM1 configuration: PWM Input mode + + In this example TIM1 input clock (TIM1CLK) is set to APB2 clock (PCLK2), + since APB2 prescaler is 1. + TIM1CLK = PCLK2 + PCLK2 = HCLK + => TIM1CLK = HCLK = SystemCoreClock + + External Signal Frequency = TIM1 counter clock / TIM1_CCR2 in Hz. + + External Signal DutyCycle = (TIM1_CCR1*100)/(TIM1_CCR2) in %. + + --------------------------------------------------------------------------- */ +#if 0 + /*## Start the Input Capture in interrupt mode ##########################*/ + if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2) != HAL_OK) + { + /* Starting Error */ + Error_Handler(); + } +#endif + /*## Start the Input Capture in interrupt mode ##########################*/ + if (HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1) != HAL_OK) + { + /* Starting Error */ + Error_Handler(); + } + + + + while(1) + { + switch(capture_Cnt) { + + case 0: + capture_Cnt ++; + printf("cc: %ld ", capture_Cnt); + TIM_SET_CAPTUREPOLARITY(&htim1, TIM_CHANNEL_2, TIM_INPUTCHANNELPOLARITY_RISING); + HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_2); // or _HAL_TIM_ENABLE(&htim1); + break; + + case 3: + high_time = capture_Buf[1] - capture_Buf[0]; // high time + printf("ht: %ld ", high_time); + // HAL_UART_Transmit(&huart2, (uint8_t*)high_time, 1, 0xffff); // print high time + HAL_Delay(1000); //delay 1 s + capture_Cnt = 0; // clear flag + break; + } + + } + + +while(1) +{ + // printf("uwF=%ld Hz\r\n", uwFrequency); + // STS_RF_Send_Multi_Times(payload, 3, 5); +} + + +#if 0 + RF_Read_TIM_init(); + + uint8_t vt=0; uint8_t codex=0; uint32_t k=0; +#endif - +#if 0 EV1527_Init(); while(1) { RF_Signal_Decode(); HAL_Delay(1/20); } +#endif #if 0 // for(i=0; i<16; i++) @@ -165,17 +308,20 @@ int main(void) #if 0 + uint8_t i; while (1) { - for(i=0; i<16; i++) + for(i=0; i<6; i++) { printf("\r\n Remote control Key down =%d \r\n", i); - //sts_rc_key(i); + sts_rc_key(i); + HAL_Delay(3000); - printf("\r\n Remote control decoded: "); - sts_rc_decoder(); + printf("\r\n Remote control decoded: %02x \r\n", codexx); + // sts_rc_decoder(); - HAL_Delay(1000); + HAL_Delay(3000); + codexx=0; } HAL_Delay(2000); @@ -199,8 +345,64 @@ int main(void) /* USER CODE END 3 */ } + +#if 0 +void RF_Read_TIM_init(void) +{ + TIM_Base_InitTypeDef TIM_Base_Init_Struct; + + NVIC_InitTypeDef NVIC_Init_Struct; + RF_Read_TIM_RCC; + TIM_Base_Init_Struct.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_Base_Init_Struct.TIM_CounterMode = TIM_CounterMode_Up; + // every int trigger time = [(Tim_Period+1)*(TIM_Prescaler+1)/(SystemCoreClock)] (s) + TIM_Base_Init_Struct.Tim_Prescalar = 48 -1; + TIM_Base_Init_Struct.Tim_Period = 0xffff -1; + TIM_Base_Init_Struct.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit(RF_Read_TIM_TIMx, &TIM_Init_Struct); + TIM_ITConfig(RF_Read_TIM_TIMx, TIM_IT_Update, ENABLE); +} +#endif + void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { + uint8_t single_button =0; + switch(GPIO_Pin) + { + case BUT1_Pin: + printf("Button 1 pressed, sending cmd #1 \r\n"); + //STS_RF_Send_AddressBit_and_CmdBit(rf_payload, rf_length); + // STS_RF_Send_Multi_Times(rf_payload, 3, 8); + single_button = rf_cmd[BUTTON_ON]; + STS_RF_Send_Button_Multi_Times(rf_payload, single_button, 3, 8); + break; + + case BUT2_Pin: + printf("Button 2 pressed, sending cmd #2 \r\n"); + single_button = rf_cmd[BUTTON_OFF]; + // STS_RF_Send_Multi_Times(rf_payload, 3, 5); + STS_RF_Send_Button_Multi_Times(rf_payload, single_button, 3, 8); + break; + + case BUT3_Pin: + printf("Button 3 pressed, sending cmd #3 \r\n"); + single_button = rf_cmd[BUTTON_NEXT]; + // STS_RF_Send_Multi_Times(rf_payload, 3, 5); + STS_RF_Send_Button_Multi_Times(rf_payload, single_button, 3, 8); + break; + + + case DATA_433_PIN: + + RF_Signal_Decode(); + break; + + default: + break; + } + +#if 0 + codexx =0; switch (GPIO_Pin) { case RC_D0_Pin: @@ -219,7 +421,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) codexx |= (HAL_GPIO_ReadPin(RC_D3_GPIO_Port, RC_D3_Pin)<<3); printf("[3]=%02x ",codexx); break; - +#if 0 case RC_D4_Pin: codexx |= (HAL_GPIO_ReadPin(RC_D4_GPIO_Port, RC_D4_Pin)<<4); printf("[4]=%02x ",codexx); @@ -236,6 +438,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) codexx |= (HAL_GPIO_ReadPin(RC_D7_GPIO_Port, RC_D7_Pin)<<7); printf("[7]=%02x ",codexx); break; +#endif case RC_VT_Pin: code_vt = (HAL_GPIO_ReadPin(RC_VT_GPIO_Port, RC_VT_Pin)); printf("[V]=%02x ",codexx); @@ -244,56 +447,66 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) default: break; } +#endif + } + +#if 0 void sts_rc_key(uint8_t key) { + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); + HAL_Delay(100); + switch (key) { case 0: - HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); break; case 1: - HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); - break; - case 2: HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); + break; + case 2: + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); break; case 3: - HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); break; case 4: - HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); break; case 5: - HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); break; case 6: - HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K0_GPIO_Port, RC_K0_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(RC_K1_GPIO_Port, RC_K1_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K2_GPIO_Port, RC_K2_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(RC_K3_GPIO_Port, RC_K3_Pin, GPIO_PIN_SET); break; case 7: @@ -327,7 +540,7 @@ void sts_rc_decoder(void) printf("decoded x= %02x \r\n", codex); } - +#endif /** * @brief System Clock Configuration * @retval None diff --git a/Core/Src/stm32wlxx_hal_msp.c b/Core/Src/stm32wlxx_hal_msp.c index b476669..7d0ab63 100644 --- a/Core/Src/stm32wlxx_hal_msp.c +++ b/Core/Src/stm32wlxx_hal_msp.c @@ -73,6 +73,83 @@ void HAL_MspInit(void) /* USER CODE END MspInit 1 */ } + +/** +* @brief TIM_Base MSP Initialization +* This function configures the hardware resources used in this example +* @param htim_base: TIM_Base handle pointer +* @retval None +*/ +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(htim_base->Instance==TIM1) + { + /* USER CODE BEGIN TIM1_MspInit 0 */ + + /* USER CODE END TIM1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**TIM1 GPIO Configuration + PA9 ------> TIM1_CH2 + */ + GPIO_InitStruct.Pin = GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* TIM1 interrupt Init */ + HAL_NVIC_SetPriority(TIM1_BRK_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_BRK_IRQn); + HAL_NVIC_SetPriority(TIM1_UP_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_UP_IRQn); + HAL_NVIC_SetPriority(TIM1_TRG_COM_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_TRG_COM_IRQn); + HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_CC_IRQn); + /* USER CODE BEGIN TIM1_MspInit 1 */ + + /* USER CODE END TIM1_MspInit 1 */ + } + +} + +/** +* @brief TIM_Base MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param htim_base: TIM_Base handle pointer +* @retval None +*/ +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) +{ + if(htim_base->Instance==TIM1) + { + /* USER CODE BEGIN TIM1_MspDeInit 0 */ + + /* USER CODE END TIM1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM1_CLK_DISABLE(); + + /**TIM1 GPIO Configuration + PA9 ------> TIM1_CH2 + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9); + + /* TIM1 interrupt DeInit */ + HAL_NVIC_DisableIRQ(TIM1_BRK_IRQn); + HAL_NVIC_DisableIRQ(TIM1_UP_IRQn); + HAL_NVIC_DisableIRQ(TIM1_TRG_COM_IRQn); + HAL_NVIC_DisableIRQ(TIM1_CC_IRQn); + /* USER CODE BEGIN TIM1_MspDeInit 1 */ + + /* USER CODE END TIM1_MspDeInit 1 */ + } + +} /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index 9c438b4..8d38229 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -20,6 +20,7 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32wlxx_it.h" +extern volatile uint32_t TIM1_cnt; // #include "app_tof_pin_conf.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -61,6 +62,9 @@ extern SUBGHZ_HandleTypeDef hsubghz; extern DMA_HandleTypeDef hdma_usart2_tx; extern UART_HandleTypeDef huart2; extern UART_HandleTypeDef huart1; + +extern TIM_HandleTypeDef htim1; + /* USER CODE BEGIN EV */ // extern DMA_HandleTypeDef hdma_i2c2_rx; @@ -220,7 +224,7 @@ void TAMP_STAMP_LSECSS_SSRU_IRQHandler(void) /* USER CODE END TAMP_STAMP_LSECSS_SSRU_IRQn 1 */ } - +#if 1 /** * @brief This function handles EXTI Line 0 Interrupt. */ @@ -243,18 +247,22 @@ void EXTI1_IRQHandler(void) /* USER CODE BEGIN EXTI1_IRQn 0 */ /* USER CODE END EXTI1_IRQn 0 */ - HAL_GPIO_EXTI_IRQHandler(RC_D0_Pin); + HAL_GPIO_EXTI_IRQHandler(BUT2_Pin); + // HAL_GPIO_EXTI_IRQHandler(RC_D0_Pin); + // __HAL_GPIO_EXTI_CLEAR_IT(RC_D0_Pin); /* USER CODE BEGIN EXTI1_IRQn 1 */ /* USER CODE END EXTI1_IRQn 1 */ } - +#endif +#if 0 void EXTI2_IRQHandler(void) { /* USER CODE BEGIN EXTI1_IRQn 0 */ /* USER CODE END EXTI1_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(RC_D1_Pin); + __HAL_GPIO_EXTI_CLEAR_IT(RC_D1_Pin); /* USER CODE BEGIN EXTI1_IRQn 1 */ /* USER CODE END EXTI1_IRQn 1 */ @@ -266,6 +274,7 @@ void EXTI3_IRQHandler(void) /* USER CODE END EXTI1_IRQn 0 */ HAL_GPIO_EXTI_IRQHandler(RC_D6_Pin); + __HAL_GPIO_EXTI_CLEAR_IT(RC_D6_Pin); /* USER CODE BEGIN EXTI1_IRQn 1 */ /* USER CODE END EXTI1_IRQn 1 */ @@ -281,11 +290,12 @@ void EXTI4_IRQHandler(void) /* USER CODE END EXTI1_IRQn 0 */ //HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); HAL_GPIO_EXTI_IRQHandler(RC_D2_Pin); + __HAL_GPIO_EXTI_CLEAR_IT(RC_D2_Pin); /* USER CODE BEGIN EXTI1_IRQn 1 */ /* USER CODE END EXTI1_IRQn 1 */ } - +#endif /** * @brief This function handles DMA1 Channel 4 Interrupt. */ @@ -341,7 +351,7 @@ void DMA1_Channel7_IRQHandler(void) /* USER CODE END DMA1_Channel7_IRQn 1 */ } - +#if 1 /** * @brief This function handles EXTI Lines [9:5] Interrupt. */ @@ -350,14 +360,26 @@ void EXTI9_5_IRQHandler(void) /* USER CODE BEGIN EXTI9_5_IRQn 0 */ /* USER CODE END EXTI9_5_IRQn 0 */ +#if 0 HAL_GPIO_EXTI_IRQHandler(RC_D4_Pin); HAL_GPIO_EXTI_IRQHandler(RC_D5_Pin); HAL_GPIO_EXTI_IRQHandler(DATA_433_PIN); + + __HAL_GPIO_EXTI_CLEAR_IT(RC_D4_Pin); + __HAL_GPIO_EXTI_CLEAR_IT(RC_D5_Pin); +#endif + + HAL_GPIO_EXTI_IRQHandler(BUT3_Pin); + + HAL_GPIO_EXTI_IRQHandler(DATA_433_PIN); + __HAL_GPIO_EXTI_CLEAR_IT(DATA_433_PIN); + /* USER CODE BEGIN EXTI9_5_IRQn 1 */ /* USER CODE END EXTI9_5_IRQn 1 */ } - +#endif +#if 0 /** * @brief This function handles EXTI Lines [15:10] Interrupt. */ @@ -369,12 +391,16 @@ void EXTI15_10_IRQHandler(void) HAL_GPIO_EXTI_IRQHandler(RC_D3_Pin); HAL_GPIO_EXTI_IRQHandler(RC_D7_Pin); HAL_GPIO_EXTI_IRQHandler(RC_VT_Pin); + + __HAL_GPIO_EXTI_CLEAR_IT(RC_D3_Pin); + __HAL_GPIO_EXTI_CLEAR_IT(RC_D7_Pin); + // __HAL_GPIO_EXTI_CLEAR_IT(RC_VT_Pin); // HAL_GPIO_EXTI_IRQHandler(TOF_INT_EXTI_PIN); /* USER CODE BEGIN EXTI15_10_IRQn 1 */ /* USER CODE END EXTI15_10_IRQn 1 */ } - +#endif /** * @brief This function handles USART2 Interrupt. */ @@ -434,4 +460,39 @@ void SUBGHZ_Radio_IRQHandler(void) /* USER CODE BEGIN 1 */ +void TIM1_IRQHandler(void) +{ + HAL_TIM_IRQHandler(&htim1); +} +/** + * @brief This function handles TIM1 Capture Compare Interrupt. + */ +void TIM1_CC_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_CC_IRQn 0 */ + + /* USER CODE END TIM1_CC_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + TIM1_cnt++; + /* USER CODE BEGIN TIM1_CC_IRQn 1 */ + + /* USER CODE END TIM1_CC_IRQn 1 */ +} + +/** + * @brief This function handles TIM1 Capture Compare Interrupt. + */ +void TIM1_IC_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_CC_IRQn 0 */ + + /* USER CODE END TIM1_CC_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + TIM1_cnt++; + /* USER CODE BEGIN TIM1_CC_IRQn 1 */ + + /* USER CODE END TIM1_CC_IRQn 1 */ +} + + /* USER CODE END 1 */ diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c index 41c09e0..1fc1cd1 100644 --- a/Core/Src/sys_app.c +++ b/Core/Src/sys_app.c @@ -383,5 +383,88 @@ void HAL_Delay(__IO uint32_t Delay) } /* USER CODE BEGIN Overload_HAL_weaks */ +/** + * @note This function overwrites the __weak one from HAL + */ +void HAL_Delay_Us(uint32_t uDelay) +{ +#if 0 + uint32_t startval, tickn, delays, wait; + startval = SysTick->VAL; + tickn = HAL_GetTick(); + delays = uDelay * 48; + if (delays > startval) + { + while (HAL_GetTick() == tickn) {} + wait = 48000 + startval -delays; + while (wait < SysTick->VAL) {}; + + }else { + wait = startval - delays; + while(wait < SysTick->VAL && HAL_GetTick() == tickn) + { + + } + } +#endif +#if 0 + uint32_t g_fac_us=48; + uint32_t ticks; + uint32_t told, tnow, tcnt =0; + uint32_t reload = SysTick->LOAD; + + ticks = uDelay * g_fac_us; + + told = SysTick->VAL; + + while(1) + { + tnow = SysTick->VAL; + if (tnow != told) + { + if (tnow < told) + { + tcnt += told -tnow; + } else { + tcnt += reload - tnow + told; + } + told = tnow; + if (tcnt >= ticks) + { + break; + } + } + } + +#endif + + +#if 1 + __IO uint32_t delay= uDelay*48/8; + do {__NOP();} while(delay --); +#endif +#if 0 + /* TIMER_IF can be based on other counter the SysTick e.g. RTC */ + /* USER CODE BEGIN HAL_Delay_1 */ +uint32_t startval, tickn, delays, wait; +startval = SysTick->VAL; +tickn = HAL_GetTick(); +// sysclock = 48000 +delays = uDelay*48; +if (delays > startval) +{ + while(HAL_GetTick() == tickn) ; + wait = 48000 + startval - delays; + while(wait < SysTick->VAL) ; +} else { + wait = startval - delays; + while (wait < SysTick->VAL && HAL_GetTick() == tickn) ; +} + /* USER CODE END HAL_Delay_1 */ +#endif + /* USER CODE BEGIN HAL_Delay_2 */ + + /* USER CODE END HAL_Delay_2 */ +} /* USER CODE END Overload_HAL_weaks */ diff --git a/STM32CubeIDE/.project b/STM32CubeIDE/.project index 122c4b9..239a058 100644 --- a/STM32CubeIDE/.project +++ b/STM32CubeIDE/.project @@ -502,6 +502,11 @@ <type>1</type> <locationURI>copy_PARENT/Core/Src/sys_sensors.c</locationURI> </link> + <link> + <name>Application/User/Core/tim.c</name> + <type>1</type> + <locationURI>PARENT-1-PROJECT_LOC/Core/Src/tim.c</locationURI> + </link> <link> <name>Application/User/Core/timer_if.c</name> <type>1</type> diff --git a/STM32CubeIDE/Release/Application/User/Core/subdir.mk b/STM32CubeIDE/Release/Application/User/Core/subdir.mk index 05bcc6d..69777cc 100644 --- a/STM32CubeIDE/Release/Application/User/Core/subdir.mk +++ b/STM32CubeIDE/Release/Application/User/Core/subdir.mk @@ -25,6 +25,7 @@ D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_N D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/sys_sensors.c \ ../Application/User/Core/syscalls.c \ ../Application/User/Core/sysmem.c \ +D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/tim.c \ D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/timer_if.c \ D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/usart.c \ D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/usart_if.c @@ -50,6 +51,7 @@ OBJS += \ ./Application/User/Core/sys_sensors.o \ ./Application/User/Core/syscalls.o \ ./Application/User/Core/sysmem.o \ +./Application/User/Core/tim.o \ ./Application/User/Core/timer_if.o \ ./Application/User/Core/usart.o \ ./Application/User/Core/usart_if.o @@ -75,6 +77,7 @@ C_DEPS += \ ./Application/User/Core/sys_sensors.d \ ./Application/User/Core/syscalls.d \ ./Application/User/Core/sysmem.d \ +./Application/User/Core/tim.d \ ./Application/User/Core/timer_if.d \ ./Application/User/Core/usart.d \ ./Application/User/Core/usart_if.d @@ -119,6 +122,8 @@ Application/User/Core/sys_sensors.o: D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55 arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DYUNHORN_STS_RANDOM -DRC -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WL55xx -c -I../../Core/Inc -I../../LoRaWAN/App -I../../TOF/Target -I../../TOF/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" Application/User/Core/%.o Application/User/Core/%.su Application/User/Core/%.cyclo: ../Application/User/Core/%.c Application/User/Core/subdir.mk arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DYUNHORN_STS_RANDOM -DRC -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WL55xx -c -I../../Core/Inc -I../../LoRaWAN/App -I../../TOF/Target -I../../TOF/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" +Application/User/Core/tim.o: D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/tim.c Application/User/Core/subdir.mk + arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DYUNHORN_STS_RANDOM -DRC -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WL55xx -c -I../../Core/Inc -I../../LoRaWAN/App -I../../TOF/Target -I../../TOF/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" Application/User/Core/timer_if.o: D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/timer_if.c Application/User/Core/subdir.mk arm-none-eabi-gcc "$<" -mcpu=cortex-m4 -std=gnu11 -DYUNHORN_STS_RANDOM -DRC -DCORE_CM4 -DUSE_HAL_DRIVER -DSTM32WL55xx -c -I../../Core/Inc -I../../LoRaWAN/App -I../../TOF/Target -I../../TOF/App -I../../LoRaWAN/Target -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc -I../../../../../../../Drivers/STM32WLxx_HAL_Driver/Inc/Legacy -I../../../../../../../Utilities/trace/adv_trace -I../../../../../../../Utilities/misc -I../../../../../../../Utilities/sequencer -I../../../../../../../Utilities/timer -I../../../../../../../Utilities/lpm/tiny_lpm -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler/Packages -I../../../../../../../Drivers/CMSIS/Device/ST/STM32WLxx/Include -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Crypto -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac/Region -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Mac -I../../../../../../../Middlewares/Third_Party/LoRaWAN/LmHandler -I../../../../../../../Middlewares/Third_Party/LoRaWAN/Utilities -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy -I../../../../../../../Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver -I../../../../../../../Drivers/CMSIS/Include -I../../../../../../../Drivers/BSP/STM32WLxx_Nucleo -I../../../../../../../Drivers/BSP/Components/vl53l8cx/porting -I../../../../../../../Drivers/BSP/Components/Common -I../../../../../../../Drivers/BSP/53L8A1 -I../../../../../../../Drivers/BSP/Components/vl53l8cx/modules -I../../../../../../../Drivers/BSP/Components/vl53l8cx -Os -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" --specs=nano.specs -mfloat-abi=soft -mthumb -o "$@" Application/User/Core/usart.o: D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/Applications/LoRaWAN/LoRaWAN_End_Node_55JC_AS923/Core/Src/usart.c Application/User/Core/subdir.mk @@ -129,7 +134,7 @@ Application/User/Core/usart_if.o: D:/ONEDRIVE/STM32WLV13/Projects/NUCLEO-WL55JC/ clean: clean-Application-2f-User-2f-Core clean-Application-2f-User-2f-Core: - -$(RM) ./Application/User/Core/adc.cyclo ./Application/User/Core/adc.d ./Application/User/Core/adc.o ./Application/User/Core/adc.su ./Application/User/Core/adc_if.cyclo ./Application/User/Core/adc_if.d ./Application/User/Core/adc_if.o ./Application/User/Core/adc_if.su ./Application/User/Core/dma.cyclo ./Application/User/Core/dma.d ./Application/User/Core/dma.o ./Application/User/Core/dma.su ./Application/User/Core/ev1527.cyclo ./Application/User/Core/ev1527.d ./Application/User/Core/ev1527.o ./Application/User/Core/ev1527.su ./Application/User/Core/flash_if.cyclo ./Application/User/Core/flash_if.d ./Application/User/Core/flash_if.o ./Application/User/Core/flash_if.su ./Application/User/Core/gpio.cyclo ./Application/User/Core/gpio.d ./Application/User/Core/gpio.o ./Application/User/Core/gpio.su ./Application/User/Core/main.cyclo ./Application/User/Core/main.d ./Application/User/Core/main.o ./Application/User/Core/main.su ./Application/User/Core/rtc.cyclo ./Application/User/Core/rtc.d ./Application/User/Core/rtc.o ./Application/User/Core/rtc.su ./Application/User/Core/sensirion_common.cyclo ./Application/User/Core/sensirion_common.d ./Application/User/Core/sensirion_common.o ./Application/User/Core/sensirion_common.su ./Application/User/Core/sht3x.cyclo ./Application/User/Core/sht3x.d ./Application/User/Core/sht3x.o ./Application/User/Core/sht3x.su ./Application/User/Core/stm32_lpm_if.cyclo ./Application/User/Core/stm32_lpm_if.d ./Application/User/Core/stm32_lpm_if.o ./Application/User/Core/stm32_lpm_if.su ./Application/User/Core/stm32wlxx_hal_msp.cyclo ./Application/User/Core/stm32wlxx_hal_msp.d ./Application/User/Core/stm32wlxx_hal_msp.o ./Application/User/Core/stm32wlxx_hal_msp.su ./Application/User/Core/stm32wlxx_it.cyclo ./Application/User/Core/stm32wlxx_it.d ./Application/User/Core/stm32wlxx_it.o ./Application/User/Core/stm32wlxx_it.su ./Application/User/Core/sts_aq_o3.cyclo ./Application/User/Core/sts_aq_o3.d ./Application/User/Core/sts_aq_o3.o ./Application/User/Core/sts_aq_o3.su ./Application/User/Core/subghz.cyclo ./Application/User/Core/subghz.d ./Application/User/Core/subghz.o ./Application/User/Core/subghz.su ./Application/User/Core/sys_app.cyclo ./Application/User/Core/sys_app.d ./Application/User/Core/sys_app.o ./Application/User/Core/sys_app.su ./Application/User/Core/sys_debug.cyclo ./Application/User/Core/sys_debug.d ./Application/User/Core/sys_debug.o ./Application/User/Core/sys_debug.su ./Application/User/Core/sys_sensors.cyclo ./Application/User/Core/sys_sensors.d ./Application/User/Core/sys_sensors.o ./Application/User/Core/sys_sensors.su ./Application/User/Core/syscalls.cyclo ./Application/User/Core/syscalls.d ./Application/User/Core/syscalls.o ./Application/User/Core/syscalls.su ./Application/User/Core/sysmem.cyclo ./Application/User/Core/sysmem.d ./Application/User/Core/sysmem.o ./Application/User/Core/sysmem.su ./Application/User/Core/timer_if.cyclo ./Application/User/Core/timer_if.d ./Application/User/Core/timer_if.o ./Application/User/Core/timer_if.su ./Application/User/Core/usart.cyclo ./Application/User/Core/usart.d ./Application/User/Core/usart.o ./Application/User/Core/usart.su ./Application/User/Core/usart_if.cyclo ./Application/User/Core/usart_if.d ./Application/User/Core/usart_if.o ./Application/User/Core/usart_if.su + -$(RM) ./Application/User/Core/adc.cyclo ./Application/User/Core/adc.d ./Application/User/Core/adc.o ./Application/User/Core/adc.su ./Application/User/Core/adc_if.cyclo ./Application/User/Core/adc_if.d ./Application/User/Core/adc_if.o ./Application/User/Core/adc_if.su ./Application/User/Core/dma.cyclo ./Application/User/Core/dma.d ./Application/User/Core/dma.o ./Application/User/Core/dma.su ./Application/User/Core/ev1527.cyclo ./Application/User/Core/ev1527.d ./Application/User/Core/ev1527.o ./Application/User/Core/ev1527.su ./Application/User/Core/flash_if.cyclo ./Application/User/Core/flash_if.d ./Application/User/Core/flash_if.o ./Application/User/Core/flash_if.su ./Application/User/Core/gpio.cyclo ./Application/User/Core/gpio.d ./Application/User/Core/gpio.o ./Application/User/Core/gpio.su ./Application/User/Core/main.cyclo ./Application/User/Core/main.d ./Application/User/Core/main.o ./Application/User/Core/main.su ./Application/User/Core/rtc.cyclo ./Application/User/Core/rtc.d ./Application/User/Core/rtc.o ./Application/User/Core/rtc.su ./Application/User/Core/sensirion_common.cyclo ./Application/User/Core/sensirion_common.d ./Application/User/Core/sensirion_common.o ./Application/User/Core/sensirion_common.su ./Application/User/Core/sht3x.cyclo ./Application/User/Core/sht3x.d ./Application/User/Core/sht3x.o ./Application/User/Core/sht3x.su ./Application/User/Core/stm32_lpm_if.cyclo ./Application/User/Core/stm32_lpm_if.d ./Application/User/Core/stm32_lpm_if.o ./Application/User/Core/stm32_lpm_if.su ./Application/User/Core/stm32wlxx_hal_msp.cyclo ./Application/User/Core/stm32wlxx_hal_msp.d ./Application/User/Core/stm32wlxx_hal_msp.o ./Application/User/Core/stm32wlxx_hal_msp.su ./Application/User/Core/stm32wlxx_it.cyclo ./Application/User/Core/stm32wlxx_it.d ./Application/User/Core/stm32wlxx_it.o ./Application/User/Core/stm32wlxx_it.su ./Application/User/Core/sts_aq_o3.cyclo ./Application/User/Core/sts_aq_o3.d ./Application/User/Core/sts_aq_o3.o ./Application/User/Core/sts_aq_o3.su ./Application/User/Core/subghz.cyclo ./Application/User/Core/subghz.d ./Application/User/Core/subghz.o ./Application/User/Core/subghz.su ./Application/User/Core/sys_app.cyclo ./Application/User/Core/sys_app.d ./Application/User/Core/sys_app.o ./Application/User/Core/sys_app.su ./Application/User/Core/sys_debug.cyclo ./Application/User/Core/sys_debug.d ./Application/User/Core/sys_debug.o ./Application/User/Core/sys_debug.su ./Application/User/Core/sys_sensors.cyclo ./Application/User/Core/sys_sensors.d ./Application/User/Core/sys_sensors.o ./Application/User/Core/sys_sensors.su ./Application/User/Core/syscalls.cyclo ./Application/User/Core/syscalls.d ./Application/User/Core/syscalls.o ./Application/User/Core/syscalls.su ./Application/User/Core/sysmem.cyclo ./Application/User/Core/sysmem.d ./Application/User/Core/sysmem.o ./Application/User/Core/sysmem.su ./Application/User/Core/tim.cyclo ./Application/User/Core/tim.d ./Application/User/Core/tim.o ./Application/User/Core/tim.su ./Application/User/Core/timer_if.cyclo ./Application/User/Core/timer_if.d ./Application/User/Core/timer_if.o ./Application/User/Core/timer_if.su ./Application/User/Core/usart.cyclo ./Application/User/Core/usart.d ./Application/User/Core/usart.o ./Application/User/Core/usart.su ./Application/User/Core/usart_if.cyclo ./Application/User/Core/usart_if.d ./Application/User/Core/usart_if.o ./Application/User/Core/usart_if.su .PHONY: clean-Application-2f-User-2f-Core diff --git a/STM32CubeIDE/Release/WL55JC_AS923.elf b/STM32CubeIDE/Release/WL55JC_AS923.elf index c164c91..aa7371c 100644 Binary files a/STM32CubeIDE/Release/WL55JC_AS923.elf and b/STM32CubeIDE/Release/WL55JC_AS923.elf differ diff --git a/STM32CubeIDE/Release/objects.list b/STM32CubeIDE/Release/objects.list index 0fc1b3a..429760c 100644 --- a/STM32CubeIDE/Release/objects.list +++ b/STM32CubeIDE/Release/objects.list @@ -18,6 +18,7 @@ "./Application/User/Core/sys_sensors.o" "./Application/User/Core/syscalls.o" "./Application/User/Core/sysmem.o" +"./Application/User/Core/tim.o" "./Application/User/Core/timer_if.o" "./Application/User/Core/usart.o" "./Application/User/Core/usart_if.o"