Skip to content

Commit

Permalink
add: STM32F4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
luftaquila committed May 26, 2024
1 parent 71d3beb commit 7c3e3a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion devices/stm32f4/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main(void)
MX_TIM1_Init();
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
/* USER CODE END 2 */

/* Infinite loop */
Expand Down
13 changes: 12 additions & 1 deletion devices/stm32f4/USB_DEVICE/App/usbd_cdc_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "usbd_cdc_if.h"

/* USER CODE BEGIN INCLUDE */

#include "tim.h"
/* USER CODE END INCLUDE */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -261,6 +261,17 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
/* TIM1 clock (APB2 timer clock) = 32 MHz
* PWM frequency = 1 kHz
* Period = 1100 for easy pulse calculation
* pulse = 1000 => PWM output 3V (pulse 1100 => 3.3V)
* pulse = (10 * cpu usage).
* Prescaler = 28 for 1 kHz PWM. (exact 28.09)
* Received Buf is 4 byte little endian float cpu usage percent
*/
int value = (int)(*(float *)Buf * 10.0);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, value);

USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
Expand Down

0 comments on commit 7c3e3a1

Please sign in to comment.