From 17f31be661e3b15635644bfdc2a36544a80cae0d Mon Sep 17 00:00:00 2001 From: kyz Date: Fri, 1 Nov 2024 10:09:26 +0800 Subject: [PATCH] =?utf8?q?=E6=96=B0=E7=89=88=E7=A1=AC=E4=BB=B6=E9=A9=B1?= =?utf8?q?=E5=8A=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1. pt100模块max31865 数据脚映射修改 2. 修改ADC设置 两路风扇两路PTC 3. 增加4è·¯4-20mA电流DAC输出 4. 增加第二路风扇控制引脚 5. spiflash切换到SPI1 控制 6. WK2204扩展串口切换到SPI3控制 --- STM32/code/MAX31865/max31865.c | 4 +- STM32/code/MAX31865/max31865.h | 2 +- STM32/code/app/App_ADC.c | 3 +- STM32/code/app/App_ADC.h | 22 ++++++++ STM32/code/app/App_DAC.c | 76 +++++++++++++++++++++++++ STM32/code/app/App_DAC.h | 30 ++++++++++ STM32/code/app/main_task.c | 2 + STM32/code/flat/SpiFlash.c | 74 ++++++++++++------------ STM32/code/flat/adc.c | 87 ++++++++++++++++++++++++++++- STM32/code/flat/gpio.c | 3 +- STM32/code/flat/gpio.h | 1 + STM32/code/flat/spi.c | 72 +++++++++++++++++++++++- STM32/code/flat/spi.h | 2 + STM32/code/include/device_tree.h | 10 ++++ STM32/code/wk2204/wk2204_spi_hard.c | 54 ++++++++---------- STM32/code/wk2204/wk2204_spi_hard.h | 2 +- 16 files changed, 366 insertions(+), 78 deletions(-) create mode 100644 STM32/code/app/App_DAC.c create mode 100644 STM32/code/app/App_DAC.h diff --git a/STM32/code/MAX31865/max31865.c b/STM32/code/MAX31865/max31865.c index 5c0e9ae6..5ab21451 100644 --- a/STM32/code/MAX31865/max31865.c +++ b/STM32/code/MAX31865/max31865.c @@ -60,14 +60,14 @@ void MAX31865_SPI_Init(void) GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); //SCKºÍMOSIÒý½Å³õʼ»¯ - GPIO_InitStructure.Pin = GPIO_PIN_11|GPIO_PIN_13; + GPIO_InitStructure.Pin = GPIO_PIN_11|GPIO_PIN_12; GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP ; //ÍÆÍìÊä³ö GPIO_InitStructure.Pull = GPIO_PULLUP; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); //MISOÒý½Å³õʼ»¯ - GPIO_InitStructure.Pin = GPIO_PIN_12; + GPIO_InitStructure.Pin = GPIO_PIN_13; GPIO_InitStructure.Mode = GPIO_MODE_INPUT ; //¸¡¿ÕÊäÈë HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); diff --git a/STM32/code/MAX31865/max31865.h b/STM32/code/MAX31865/max31865.h index bbaa5aa9..c3e11363 100644 --- a/STM32/code/MAX31865/max31865.h +++ b/STM32/code/MAX31865/max31865.h @@ -19,7 +19,7 @@ typedef struct #define SCK_H HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11,GPIO_PIN_SET) /* SCK = 1 */ #define SCK_L HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11,GPIO_PIN_RESET) /* SCK = 0 */ -#if 0 +#if 1 #define MOSI_H HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_SET) /* MOSI = 1 */ #define MOSI_L HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12,GPIO_PIN_RESET) /* MOSI = 0 */ diff --git a/STM32/code/app/App_ADC.c b/STM32/code/app/App_ADC.c index 989e33fd..fbd76d0e 100644 --- a/STM32/code/app/App_ADC.c +++ b/STM32/code/app/App_ADC.c @@ -301,7 +301,7 @@ static void PT100_Adc_Daemon() */ static void Power_Adc_Daemon() { - +#if 0 DWORD ADC_LVDIN_V, AC_check_V,now_timer; static DWORD start_power_off_timer = 0; @@ -339,6 +339,7 @@ static void Power_Adc_Daemon() if((now_timer-start_power_off_timer)>=DC_POWEROFF_MAX_TIME) MyGpioWrite(PIN_OUT_POWER_SW, LOW); /* µç³Ø¹©µç¶Ï¿ª */ } +#endif } diff --git a/STM32/code/app/App_ADC.h b/STM32/code/app/App_ADC.h index 9460e750..57dc261c 100644 --- a/STM32/code/app/App_ADC.h +++ b/STM32/code/app/App_ADC.h @@ -3,6 +3,15 @@ ADCÓ¦Óòã */ +/* +adc123_in2 -- PA2 ADC123_IN2 -- ·ç»ú2 ¹ÊÕϼì²â +adc20 -- PA3 ADC123_IN3 -- ·ç»ú1 ¹ÊÕϼì²â + +adc_ptc1 pin34 --PC5 ADC12_IN15 +adc_ptc2 pin33 --PC4 ADC12_IN14 + +*/ + #ifndef App_ADC_h #define App_ADC_h @@ -24,6 +33,18 @@ enum enum { +#if 1 + ADC_CH_TEMP, + ADC_CH_VBAT, + ADC_CH_FAN_1, + ADC_CH_FAN_2, + ADC_CH_PTC_1, + ADC_CH_PTC_2, + ADC_CH_MAX, + ADC_CH_PT100_MAX = 4, + ADC_CH_FUN = ADC_CH_FAN_1, + +#else ADC_CH_PT100_1 = 0, ADC_CH_PT100_2, ADC_CH_PT100_3, @@ -35,6 +56,7 @@ enum ADC_CH_VBAT, ADC_CH_FUN, ADC_CH_MAX, +#endif }; /* adc»¬¶¯Æ½¾ùÀÛ¼Óµã¸öÊý */ diff --git a/STM32/code/app/App_DAC.c b/STM32/code/app/App_DAC.c new file mode 100644 index 00000000..e2dea525 --- /dev/null +++ b/STM32/code/app/App_DAC.c @@ -0,0 +1,76 @@ +/* + App_ADC.c + ADCת»»Ó¦Óò㴦Àí + */ + +#include "def.h" +#include "config.h" +#include "i2c.h" +#include "gpio.h" +#include "App_DAC.h" +#include "tim.h" +#include "system.h" +#include "App_para.h" +#include "runflag.h" +#include "alarm.h" +#include "mcu_com.h" +#include "Get_EquipmentData.h" + +#define DAC_RS 200 + +//7bitµØÖ·: 1 0 1 1 A2 A1 A0 +#define GP_ADDR( n ) ((0x58|n)<<1) + +static uint8_t g_dac_out_ma[DAC_CH_N] = { 6, 12, 18, 24 }; +static uint8_t gp8202as_addr[DAC_CH_N] = { GP_ADDR(0), GP_ADDR(2), GP_ADDR(4), GP_ADDR(6) }; + +static int32_t gp8202as_write( uint8_t addr, uint8_t *data, uint8_t sz ) +{ + if((data == NULL)||(sz == 0)){ + return -1; + } + +} + +static int gp8202as_out( uint8_t ch, uint8_t ma ) +{ + //i2c3 write + uint16_t data; + uint8_t wr_data[3]; + + //IOUT = 5V/RS * data/0xFFF, data = Iout *RS* 0xFFF /5V + data = ma * 200 * 0xfff /5000; + + wr_data[0] = 2; + wr_data[1] = (data<<4)&0xff; + wr_data[2] = (data>>4)&0xff; + + if( I2C_Dev_Write(SOFT_I2C_BUS_3, gp8202as_addr[ch], NULL, 0, wr_data, 3 ) == FALSE ){ + return -1; + }else{ + return 0; + } +} + +void dac_set( uint8_t ch, uint8_t ma ) +{ + g_dac_out_ma[ch] = ma; +} + +/*ADCÏà¹ØÈÎÎñ*/ +void Task_DAC() +{ + static DWORD last_adc_tim = 0; + DWORD now; + int i; + + now = HAL_GetTick(); + if((DWORD)(now - last_adc_tim) >= 2000) //2s + { + last_adc_tim = now; + for( i=DAC_CH_1; i> 16; tx[2] = addr >> 8; tx[3] = addr; tx[4] = 0x00; - HAL_SPI_Transmit(&hspi2, tx, 5, 5); - HAL_SPI_Receive(&hspi2, data, length, 1 * length); + HAL_SPI_Transmit(&hspi1, tx, 5, 5); + HAL_SPI_Receive(&hspi1, data, length, 1 * length); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); return TRUE; @@ -179,7 +179,7 @@ BOOL SpiFlashWrite(DWORD addr, BYTE *data, DWORD length) { return FALSE; } - HAL_SPI_Set_MODE(&hspi2, SPI_FLASH_SPI_MODE); + HAL_SPI_Set_MODE(&hspi1, SPI_FLASH_SPI_MODE); leftByte = length; StartPage = addr >> 8; StartByte = (BYTE)addr; @@ -197,8 +197,8 @@ BOOL SpiFlashWrite(DWORD addr, BYTE *data, DWORD length) tx[1] = address >> 16; tx[2] = address >> 8; tx[3] = address; - HAL_SPI_Transmit(&hspi2, tx, 4, 4); - HAL_SPI_Transmit(&hspi2, data, WriteBytes, 1 * WriteBytes); + HAL_SPI_Transmit(&hspi1, tx, 4, 4); + HAL_SPI_Transmit(&hspi1, data, WriteBytes, 1 * WriteBytes); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); SpiFlashWaitComplete(5); leftByte -= WriteBytes; @@ -224,7 +224,7 @@ BOOL SpiFlashEraseSector4K_Nowait(BYTE Blocknum, BYTE Sectornum) DWORD EraseAddr; BYTE tx[4]; EraseAddr = Blocknum * SPIFLASH_BLOCK_SIZE /*65536*/ + Sectornum * SPIFLASH_SECTOR_SIZE; // 4096 - HAL_SPI_Set_MODE(&hspi2, SPI_FLASH_SPI_MODE); + HAL_SPI_Set_MODE(&hspi1, SPI_FLASH_SPI_MODE); // дʹÄÜ SpiFlashWriteEnable(); @@ -235,7 +235,7 @@ BOOL SpiFlashEraseSector4K_Nowait(BYTE Blocknum, BYTE Sectornum) tx[1] = EraseAddr >> 16; tx[2] = EraseAddr >> 8; tx[3] = EraseAddr; - HAL_SPI_Transmit(&hspi2, tx, 4, 4); + HAL_SPI_Transmit(&hspi1, tx, 4, 4); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); return TRUE; @@ -247,7 +247,7 @@ BOOL SpiFlashEraseSector4K(BYTE Blocknum, BYTE Sectornum) DWORD EraseAddr; BYTE tx[4]; EraseAddr = Blocknum * SPIFLASH_BLOCK_SIZE /*65536*/ + Sectornum * SPIFLASH_SECTOR_SIZE; // 4096 - HAL_SPI_Set_MODE(&hspi2, SPI_FLASH_SPI_MODE); + HAL_SPI_Set_MODE(&hspi1, SPI_FLASH_SPI_MODE); // дʹÄÜ SpiFlashWriteEnable(); @@ -258,7 +258,7 @@ BOOL SpiFlashEraseSector4K(BYTE Blocknum, BYTE Sectornum) tx[1] = EraseAddr >> 16; tx[2] = EraseAddr >> 8; tx[3] = EraseAddr; - HAL_SPI_Transmit(&hspi2, tx, 4, 4); + HAL_SPI_Transmit(&hspi1, tx, 4, 4); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); // µÈ´ýÍê³É //8msx10 @@ -270,7 +270,7 @@ BOOL SpiFlashEraseSector4K(BYTE Blocknum, BYTE Sectornum) BOOL SpiFlashEraseSector4K_ByAddr(DWORD EraseAddr) { BYTE tx[4]; - HAL_SPI_Set_MODE(&hspi2, SPI_FLASH_SPI_MODE); + HAL_SPI_Set_MODE(&hspi1, SPI_FLASH_SPI_MODE); // дʹÄÜ SpiFlashWriteEnable(); @@ -281,7 +281,7 @@ BOOL SpiFlashEraseSector4K_ByAddr(DWORD EraseAddr) tx[1] = EraseAddr >> 16; tx[2] = EraseAddr >> 8; tx[3] = EraseAddr; - HAL_SPI_Transmit(&hspi2, tx, 4, 4); + HAL_SPI_Transmit(&hspi1, tx, 4, 4); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); // µÈ´ýÍê³É //8msx10 @@ -296,7 +296,7 @@ BOOL SpiFlashEraseHalfBlock32K(BYTE Blocknum, BYTE half) DWORD EraseAddr; BYTE tx[4]; EraseAddr = (Blocknum * SPIFLASH_BLOCK_SIZE /*65536*/) + ((DWORD)half * (SPIFLASH_BLOCK_SIZE >> 1)); /*65536*/ - HAL_SPI_Set_MODE(&hspi2, SPI_FLASH_SPI_MODE); + HAL_SPI_Set_MODE(&hspi1, SPI_FLASH_SPI_MODE); // дʹÄÜ SpiFlashWriteEnable(); @@ -307,7 +307,7 @@ BOOL SpiFlashEraseHalfBlock32K(BYTE Blocknum, BYTE half) tx[1] = EraseAddr >> 16; tx[2] = EraseAddr >> 8; tx[3] = EraseAddr; - HAL_SPI_Transmit(&hspi2, tx, 4, 4); + HAL_SPI_Transmit(&hspi1, tx, 4, 4); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); // µÈ´ýÍê³É //15msx10 @@ -322,7 +322,7 @@ BOOL SpiFlashEraseBlock64K(BYTE Blocknum) DWORD EraseAddr; BYTE tx[4]; EraseAddr = Blocknum * SPIFLASH_BLOCK_SIZE; /*65536*/ - HAL_SPI_Set_MODE(&hspi2, SPI_FLASH_SPI_MODE); + HAL_SPI_Set_MODE(&hspi1, SPI_FLASH_SPI_MODE); // дʹÄÜ SpiFlashWriteEnable(); @@ -333,7 +333,7 @@ BOOL SpiFlashEraseBlock64K(BYTE Blocknum) tx[1] = EraseAddr >> 16; tx[2] = EraseAddr >> 8; tx[3] = EraseAddr; - HAL_SPI_Transmit(&hspi2, tx, 4, 4); + HAL_SPI_Transmit(&hspi1, tx, 4, 4); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); // µÈ´ýÍê³É //15msx10 @@ -352,7 +352,7 @@ BOOL SpiFlashEraseChip() // ²Á³ýоƬ MyGpioWrite(PIN_OUT_SPI_FLASH_CS, LOW); tx[0] = SpiFlash_Erase_Chip; - HAL_SPI_Transmit(&hspi2, tx, 1, 1); + HAL_SPI_Transmit(&hspi1, tx, 1, 1); MyGpioWrite(PIN_OUT_SPI_FLASH_CS, HIGH); // µÈ´ýÍê³É//500msx10 diff --git a/STM32/code/flat/adc.c b/STM32/code/flat/adc.c index b3dc1c78..a3a45dcb 100644 --- a/STM32/code/flat/adc.c +++ b/STM32/code/flat/adc.c @@ -51,13 +51,65 @@ void MX_ADC1_Init(void) hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T8_TRGO; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.NbrOfConversion = 9; +// hadc1.Init.NbrOfConversion = 9; + hadc1.Init.NbrOfConversion = 6; hadc1.Init.DMAContinuousRequests = ENABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } +#if 1 + + /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. + */ + sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; + sConfig.Rank = 1; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. + */ + sConfig.Channel = ADC_CHANNEL_VBAT; + sConfig.Rank = 2; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + sConfig.Channel = ADC_CHANNEL_2; + sConfig.Rank = 3; + sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + sConfig.Channel = ADC_CHANNEL_3; + sConfig.Rank = 4; + sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + sConfig.Channel = ADC_CHANNEL_14; + sConfig.Rank = 5; + sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + + sConfig.Channel = ADC_CHANNEL_15; + sConfig.Rank = 6; + sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + +#else /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_6; @@ -133,6 +185,8 @@ void MX_ADC1_Init(void) { Error_Handler(); } +#endif + } void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle) @@ -158,6 +212,26 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle) PB0 ------> ADC1_IN8 PB1 ------> ADC1_IN9 */ + +#if 1 + /* + PA2 -- ADC123_IN2 + PA3 -- ADC123_IN3 + PC4 -- ADC12_IN14 + PC5 -- ADC12_IN15 + */ + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + + GPIO_InitStruct.Pin = ADC_FAN1_Pin; + HAL_GPIO_Init(ADC_FAN1_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = ADC_FAN2_Pin; + HAL_GPIO_Init(ADC_FAN2_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = ADC_PTC1_Pin; + HAL_GPIO_Init(ADC_PTC1_GPIO_Port, &GPIO_InitStruct); + GPIO_InitStruct.Pin = ADC_PTC2_Pin; + HAL_GPIO_Init(ADC_PTC2_GPIO_Port, &GPIO_InitStruct); +#else GPIO_InitStruct.Pin = ADC_PT100_1_Pin | ADC_PT100_2_Pin | ADC_PT100_3_Pin | ADC_PT100_4_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; @@ -167,12 +241,11 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle) GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - GPIO_InitStruct.Pin = ADC_POWER_Pin | ADC_POWEROFF_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - +#endif /* ADC1 DMA Init */ /* ADC1 Init */ hdma_adc1.Instance = DMA2_Stream0; @@ -220,10 +293,18 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef *adcHandle) */ HAL_GPIO_DeInit(GPIOA, ADC_PT100_1_Pin | ADC_PT100_2_Pin | ADC_PT100_3_Pin | ADC_PT100_4_Pin); +#if 1 + HAL_GPIO_DeInit(ADC_FAN1_GPIO_Port, ADC_FAN1_Pin); + HAL_GPIO_DeInit(ADC_FAN2_GPIO_Port, ADC_FAN2_Pin); + HAL_GPIO_DeInit(ADC_PTC1_GPIO_Port, ADC_PTC1_Pin); + HAL_GPIO_DeInit(ADC_PTC2_GPIO_Port, ADC_PTC2_Pin); +#else + HAL_GPIO_DeInit(GPIOA, ADC_FAN_Pin); HAL_GPIO_DeInit(GPIOB, ADC_POWER_Pin | ADC_POWEROFF_Pin); +#endif /* ADC1 DMA DeInit */ HAL_DMA_DeInit(adcHandle->DMA_Handle); /* USER CODE BEGIN ADC1_MspDeInit 1 */ diff --git a/STM32/code/flat/gpio.c b/STM32/code/flat/gpio.c index 4d941bbd..7f8971b9 100644 --- a/STM32/code/flat/gpio.c +++ b/STM32/code/flat/gpio.c @@ -29,7 +29,8 @@ static const tGPIO_Init_LIST gpio_init_list[] = {GPIOE, PIN(4), GPIO_MODE_OUTPUT_PP, NULL, LOW}, /* PIN_OUT_RN8302_RST */ {GPIOE, PIN(5), GPIO_MODE_OUTPUT_PP, NULL, HIGH}, /* PIN_OUT_RN8302_SPI_CS */ {GPIOE, PIN(6), GPIO_MODE_OUTPUT_PP, NULL, LOW}, /* PIN_OUT_FAN_CTRL */ - {GPIOC, PIN(0), GPIO_MODE_OUTPUT_PP, NULL, HIGH}, /* PIN_OUT_SPI_FLASH_CS */ + {GPIOC, PIN(0), GPIO_MODE_OUTPUT_PP, NULL, HIGH}, /* PIN_OUT_FAN2_CTRL*/ + {GPIOA, PIN(4), GPIO_MODE_OUTPUT_PP, NULL, HIGH}, /* PIN_OUT_SPI_FLASH_CS */ {GPIOC, PIN(14), GPIO_MODE_OUTPUT_PP, NULL, LOW}, /* PIN_OUT_EEP_WP */ {GPIOB, PIN(2), GPIO_MODE_OUTPUT_PP, NULL, LOW}, /* PIN_OUT_BEEP */ {GPIOC, PIN(13), GPIO_MODE_OUTPUT_PP, NULL, LOW}, /* PIN_OUT_LCD_BL */ diff --git a/STM32/code/flat/gpio.h b/STM32/code/flat/gpio.h index d16f9baf..c6834756 100644 --- a/STM32/code/flat/gpio.h +++ b/STM32/code/flat/gpio.h @@ -54,6 +54,7 @@ typedef struct PIN_OUT_RN8302_RST, PIN_OUT_RN8302_SPI_CS, PIN_OUT_FAN_CTRL, + PIN_OUT_FAN2_CTRL, PIN_OUT_SPI_FLASH_CS, PIN_OUT_EEP_WP, PIN_OUT_BEEP, diff --git a/STM32/code/flat/spi.c b/STM32/code/flat/spi.c index db4894eb..d8122167 100644 --- a/STM32/code/flat/spi.c +++ b/STM32/code/flat/spi.c @@ -26,8 +26,32 @@ /* USER CODE END 0 */ +SPI_HandleTypeDef hspi1; SPI_HandleTypeDef hspi2; +/* SPI1 init function */ +void MX_SPI1_Init(void) +{ + + hspi1.Instance = SPI1; + hspi1.Init.Mode = SPI_MODE_MASTER; + hspi1.Init.Direction = SPI_DIRECTION_2LINES; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; + hspi1.Init.NSS = SPI_NSS_SOFT; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi1.Init.CRCPolynomial = 10; + hspi1.LastSpiDevMode = 0xFF; + if (HAL_SPI_Init(&hspi1) != HAL_OK) + { + Error_Handler(); + } +} + /* SPI2 init function */ void MX_SPI2_Init(void) { @@ -55,7 +79,32 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *spiHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (spiHandle->Instance == SPI2) + if (spiHandle->Instance == SPI1) + { + /* USER CODE BEGIN SPI1_MspInit 0 */ + + /* USER CODE END SPI1_MspInit 0 */ + /* SPI1 clock enable */ + __HAL_RCC_SPI1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**SPI1 GPIO Configuration + PA6 ------> SPI1_MISO + PA7 ------> SPI1_MOSI + PA5 ------> SPI1_SCK + */ + GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI1_MspInit 1 */ + + /* USER CODE END SPI1_MspInit 1 */ + } + else if (spiHandle->Instance == SPI2) { /* USER CODE BEGIN SPI2_MspInit 0 */ @@ -97,6 +146,25 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *spiHandle) void HAL_SPI_MspDeInit(SPI_HandleTypeDef *spiHandle) { + if (spiHandle->Instance == SPI1) + { + /* USER CODE BEGIN SPI1_MspDeInit 0 */ + + /* USER CODE END SPI1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI1_CLK_DISABLE(); + + /**SPI1 GPIO Configuration + PA6 ------> SPI1_MISO + PA7 ------> SPI1_MOSI + PA5 ------> SPI1_SCK + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 ); + + /* USER CODE BEGIN SPI1_MspDeInit 1 */ + + /* USER CODE END SPI1_MspDeInit 1 */ + } if (spiHandle->Instance == SPI2) { /* USER CODE BEGIN SPI2_MspDeInit 0 */ @@ -118,7 +186,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef *spiHandle) /* USER CODE END SPI2_MspDeInit 1 */ } - else if (spiHandle->Instance == SPI1) + else if (spiHandle->Instance == SPI3) { HAL_SPI_MspDeInit_w2204(); } diff --git a/STM32/code/flat/spi.h b/STM32/code/flat/spi.h index 0baccc9c..56729140 100644 --- a/STM32/code/flat/spi.h +++ b/STM32/code/flat/spi.h @@ -31,12 +31,14 @@ extern "C" /* USER CODE END Includes */ + extern SPI_HandleTypeDef hspi1; extern SPI_HandleTypeDef hspi2; /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ + void MX_SPI1_Init(void); void MX_SPI2_Init(void); /* USER CODE BEGIN Prototypes */ diff --git a/STM32/code/include/device_tree.h b/STM32/code/include/device_tree.h index 00d3b8df..e880eeb2 100644 --- a/STM32/code/include/device_tree.h +++ b/STM32/code/include/device_tree.h @@ -180,4 +180,14 @@ ETH #define RX8025T_INT_Pin GPIO_PIN_4 #define RX8025T_INT_GPIO_Port GPIOB +//ADC +#define ADC_FAN1_Pin GPIO_PIN_3 +#define ADC_FAN1_GPIO_Port GPIOA +#define ADC_FAN2_Pin GPIO_PIN_2 +#define ADC_FAN2_GPIO_Port GPIOA +#define ADC_PTC1_Pin GPIO_PIN_5 +#define ADC_PTC1_GPIO_Port GPIOC +#define ADC_PTC2_Pin GPIO_PIN_4 +#define ADC_PTC2_GPIO_Port GPIOC + #endif diff --git a/STM32/code/wk2204/wk2204_spi_hard.c b/STM32/code/wk2204/wk2204_spi_hard.c index ebaa4c84..ca4d6a5b 100644 --- a/STM32/code/wk2204/wk2204_spi_hard.c +++ b/STM32/code/wk2204/wk2204_spi_hard.c @@ -24,25 +24,25 @@ /* USER CODE END 0 */ -SPI_HandleTypeDef hspi1; +SPI_HandleTypeDef hspi3; /* SPI1 init function */ -void MX_SPI1_Init(void) +void MX_SPI3_Init(void) { - hspi1.Instance = SPI1; - hspi1.Init.Mode = SPI_MODE_MASTER; - hspi1.Init.Direction = SPI_DIRECTION_2LINES; - hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; - hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi1.Init.TIMode = SPI_TIMODE_DISABLE; - hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi1.Init.CRCPolynomial = 10; - if (HAL_SPI_Init(&hspi1) != HAL_OK) + hspi3.Instance = SPI3; + hspi3.Init.Mode = SPI_MODE_MASTER; + hspi3.Init.Direction = SPI_DIRECTION_2LINES; + hspi3.Init.DataSize = SPI_DATASIZE_8BIT; + hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi3.Init.NSS = SPI_NSS_SOFT; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; + hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi3.Init.TIMode = SPI_TIMODE_DISABLE; + hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi3.Init.CRCPolynomial = 10; + if (HAL_SPI_Init(&hspi3) != HAL_OK) { // Error_Handler(); } @@ -53,30 +53,24 @@ void HAL_SPI_MspInit_wk2440(SPI_HandleTypeDef* spiHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(spiHandle->Instance==SPI1) + if(spiHandle->Instance==SPI3) { - /* USER CODE BEGIN SPI1_MspInit 0 */ - - /* USER CODE END SPI1_MspInit 0 */ - /* SPI1 clock enable */ - __HAL_RCC_SPI1_CLK_ENABLE(); + /* SPI3 clock enable */ + __HAL_RCC_SPI3_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); - /**SPI1 GPIO Configuration - PB3 ------> SPI1_SCK - PB4 ------> SPI1_MISO - PB5 ------> SPI1_MOSI + /**SPI3 GPIO Configuration + PB3 ------> SPI3_SCK + PB4 ------> SPI3_MISO + PB5 ------> SPI3_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /* USER CODE BEGIN SPI1_MspInit 1 */ - - /* USER CODE END SPI1_MspInit 1 */ } } @@ -87,7 +81,7 @@ void HAL_SPI_MspDeInit_w2204(void) // if(spiHandle->Instance==SPI1) { - __HAL_RCC_SPI1_CLK_DISABLE(); + __HAL_RCC_SPI3_CLK_DISABLE(); /**SPI1 GPIO Configuration PB3 ------> SPI1_SCK diff --git a/STM32/code/wk2204/wk2204_spi_hard.h b/STM32/code/wk2204/wk2204_spi_hard.h index a4b3bcbc..5dc13a8e 100644 --- a/STM32/code/wk2204/wk2204_spi_hard.h +++ b/STM32/code/wk2204/wk2204_spi_hard.h @@ -30,7 +30,7 @@ /* USER CODE END Includes */ -extern SPI_HandleTypeDef hspi1; +extern SPI_HandleTypeDef hspi3; /* USER CODE BEGIN Private defines */ -- 2.34.1