mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
更换串口为USB
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
// includes
|
||||
// sys
|
||||
#include "usart.h"
|
||||
#include "tim.h"
|
||||
#include "stm32f4xx_it.h"
|
||||
#include "adc.h"
|
||||
@@ -16,7 +15,6 @@
|
||||
#include "lcd.h"
|
||||
#include "lcd_init.h"
|
||||
#include "gate.h"
|
||||
#include "data_queue.h"
|
||||
#include "fusb302_dev.h"
|
||||
#include "BL24C02.h" // settings
|
||||
|
||||
@@ -45,32 +43,12 @@ void HardwareInitTask(void *argument)
|
||||
{
|
||||
vTaskSuspendAll();
|
||||
|
||||
// uart start
|
||||
HAL_UART_Receive_DMA(&huart6, (uint8_t*)uart_receive_buf, USART_RX_BUFFER_SIZE);
|
||||
__HAL_UART_ENABLE_IT(&huart6, UART_IT_IDLE);
|
||||
//
|
||||
UART6_TX_Send((uint8_t *)"power-pico\r\n", 13);
|
||||
|
||||
// queue for voltage and current
|
||||
global_voltage_queue = queue_create(32);
|
||||
global_current_queue = queue_create(32);
|
||||
for(int i = 0; i < 32; i++) {
|
||||
queue_push(global_voltage_queue, 0.0);
|
||||
queue_push(global_current_queue, 0.0);
|
||||
}
|
||||
|
||||
// adc packet init
|
||||
adc_packet.header[0] = 0x55;
|
||||
adc_packet.header[1] = 0xAA;
|
||||
// 填充模式位
|
||||
adc_packet.header[2] = 0x03;
|
||||
|
||||
// gate, for current flow route selection, high current by default
|
||||
Gate_Port_Init();
|
||||
flow_route_selection(HIGH_CUR);
|
||||
|
||||
// ADC sample start
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_packet.data, ADC_TIMES * ADC_CHANELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_raw_buffer, ADC_TIMES*2 * ADC_CHANNELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
||||
HAL_TIM_Base_Start(&htim2); /*开启定时器,用溢出时间来触发ADC*/
|
||||
|
||||
// PWM Start for LCD backlight
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//includes
|
||||
#include "user_TasksInit.h"
|
||||
#include "user_MessageTask.h"
|
||||
#include "usart.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "BL24C02.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -23,21 +23,15 @@ void MessageTask(void *argument)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if(uart_receive_flag == 1) {
|
||||
if(get_update_request()) {
|
||||
|
||||
// clear the flag
|
||||
uart_receive_flag = 0;
|
||||
// check the received message is "update\r\n" ?
|
||||
if(strcmp((const char *)uart_receive_buf, "update\r\n") == 0) {
|
||||
// send response
|
||||
UART6_TX_Send((uint8_t *)"start update\r\n", 14);
|
||||
EEPROM_UpdateCommand_Write(true);
|
||||
HAL_Delay(100);
|
||||
// reset
|
||||
NVIC_SystemReset();
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
set_update_request(false);
|
||||
// set the EEPROM flag
|
||||
EEPROM_UpdateCommand_Write(true);
|
||||
HAL_Delay(100);
|
||||
// reset
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
osDelay(500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user