diff --git a/Downstream/Drivers/CMSIS/Include/core_cm4.h b/Downstream/Drivers/CMSIS/Include/core_cm4.h index 827dc38..d62032c 100644 --- a/Downstream/Drivers/CMSIS/Include/core_cm4.h +++ b/Downstream/Drivers/CMSIS/Include/core_cm4.h @@ -1706,7 +1706,7 @@ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ SysTick->LOAD = ticks - 1; /* set reload register */ - NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */ + //NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */ SysTick->VAL = 0; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | diff --git a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c index 35d9379..8e1c314 100644 --- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c +++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c @@ -266,7 +266,7 @@ __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); /*Configure the SysTick IRQ priority */ - HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); + //HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); /* Return function status */ return HAL_OK; diff --git a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c index 46b4d6d..803979c 100644 --- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c +++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c @@ -280,10 +280,10 @@ __weak HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruc if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSE) ||\ ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSE))) { - if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF)) - { +// if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF)) +// { return HAL_ERROR; - } +// } } else { diff --git a/Downstream/Inc/board_config.h b/Downstream/Inc/board_config.h new file mode 100644 index 0000000..5b2c897 --- /dev/null +++ b/Downstream/Inc/board_config.h @@ -0,0 +1,52 @@ +/* + * board_config.h + * + * Created on: 25/03/2015 + * Author: Robert Fisk + */ + +#ifndef INC_BOARD_CONFIG_H_ +#define INC_BOARD_CONFIG_H_ + + +#define BSRR_SHIFT_HIGH 0 +#define BSRR_SHIFT_LOW 16 + +#define PA_JTMS GPIO_PIN_13 +#define PA_JTCK GPIO_PIN_14 +#define PA_JTDI GPIO_PIN_15 +#define PB_JTDO GPIO_PIN_3 +#define PB_NJTRST GPIO_PIN_4 + +#define USB_FS_VBUS_PIN GPIO_PIN_9 +#define USB_FS_VBUS_PORT GPIOA +#define USB_FS_VBUSON_PIN GPIO_PIN_10 +#define USB_FS_VBUSON_PORT GPIOA +#define USB_FS_FAULT_PIN GPIO_PIN_6 +#define USB_FS_FAULT_PORT GPIOB + +#define USB_HS_VBUS_PIN GPIO_PIN_13 +#define USB_HS_VBUS_PORT GPIOB +#define USB_HS_VBUSON_PIN GPIO_PIN_8 +#define USB_HS_VBUSON_PORT GPIOA + +#define STAT_LED_PIN GPIO_PIN_13 +#define STAT_LED_PORT GPIOC +#define STAT_LED_ON (STAT_LED_PORT->BSRR = (STAT_LED_PIN << BSRR_SHIFT_LOW)) //Stat LED is active-low +#define STAT_LED_OFF (STAT_LED_PORT->BSRR = (STAT_LED_PIN << BSRR_SHIFT_HIGH)) + +//#define SPI_DMA_ACTIVE_PIN GPIO_PIN_5 /////////Temporary indicator of SPI & DMA activity +//#define SPI_DMA_ACTIVE_PORT GPIOB +//#define SPI_DMA_ACTIVE_ON SPI_DMA_ACTIVE_PORT->BSRR = (SPI_DMA_ACTIVE_PIN << BSRR_SHIFT_LOW) +//#define SPI_DMA_ACTIVE_OFF SPI_DMA_ACTIVE_PORT->BSRR = (SPI_DMA_ACTIVE_PIN << BSRR_SHIFT_HIGH) + +#define SPI1_NSS_PIN GPIO_PIN_4 +#define SPI1_NSS_PORT GPIOA + +#define UPSTREAM_TX_REQUEST_PIN GPIO_PIN_3 +#define UPSTREAM_TX_REQUEST_PORT GPIOA +#define UPSTREAM_TX_REQUEST_ASSERT (UPSTREAM_TX_REQUEST_PORT->BSRR = (UPSTREAM_TX_REQUEST_PIN << BSRR_SHIFT_LOW)) +#define UPSTREAM_TX_REQUEST_DEASSERT (UPSTREAM_TX_REQUEST_PORT->BSRR = (UPSTREAM_TX_REQUEST_PIN << BSRR_SHIFT_HIGH)) + + +#endif /* INC_BOARD_CONFIG_H_ */ diff --git a/Downstream/Inc/interrupts.h b/Downstream/Inc/interrupts.h index 862d2df..3d94804 100644 --- a/Downstream/Inc/interrupts.h +++ b/Downstream/Inc/interrupts.h @@ -42,7 +42,13 @@ /* Includes ------------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ + +#define INT_PRIORITY_SYSTICK 2 +#define INT_PRIORITY_SPI_DMA 10 //SPI interacts heavily with USB_OTG, +#define INT_PRIORITY_OTG_FS 10 //so set them at the same priority. + + + /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void SysTick_Handler(void); diff --git a/Downstream/Src/hal_msp.c b/Downstream/Src/hal_msp.c index cb71dbf..dbead96 100644 --- a/Downstream/Src/hal_msp.c +++ b/Downstream/Src/hal_msp.c @@ -33,45 +33,27 @@ */ /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal.h" +#include "interrupts.h" -extern DMA_HandleTypeDef hdma_spi1_rx; +extern DMA_HandleTypeDef hdma_spi1_rx; extern DMA_HandleTypeDef hdma_spi1_tx; -/* USER CODE BEGIN 0 */ -/* USER CODE END 0 */ -/** - * Initializes the Global MSP. - */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ - - /* USER CODE END MspInit 0 */ - HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); - - /* System interrupt init*/ -/* SysTick_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ + HAL_NVIC_SetPriority(SysTick_IRQn, INT_PRIORITY_SYSTICK, 0); } + void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { GPIO_InitTypeDef GPIO_InitStruct; if(hspi->Instance==SPI1) { - /* USER CODE BEGIN SPI1_MspInit 0 */ - - /* USER CODE END SPI1_MspInit 0 */ - /* Peripheral clock enable */ __SPI1_CLK_ENABLE(); /**SPI1 GPIO Configuration @@ -82,12 +64,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 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_HIGH; + GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ - hdma_spi1_rx.Instance = DMA2_Stream2; hdma_spi1_rx.Init.Channel = DMA_CHANNEL_3; hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; @@ -122,9 +103,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) __HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx); - /* USER CODE BEGIN SPI1_MspInit 1 */ - - /* USER CODE END SPI1_MspInit 1 */ } } @@ -134,10 +112,6 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) if(hspi->Instance==SPI1) { - /* USER CODE BEGIN SPI1_MspDeInit 0 */ - - /* USER CODE END SPI1_MspDeInit 0 */ - /* Peripheral clock disable */ __SPI1_CLK_DISABLE(); /**SPI1 GPIO Configuration @@ -151,19 +125,9 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) HAL_DMA_DeInit(hspi->hdmarx); HAL_DMA_DeInit(hspi->hdmatx); } - /* USER CODE BEGIN SPI1_MspDeInit 1 */ - - /* USER CODE END SPI1_MspDeInit 1 */ } -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * @} - */ /** * @} diff --git a/Downstream/Src/interrupts.c b/Downstream/Src/interrupts.c index 36194b0..914b71c 100644 --- a/Downstream/Src/interrupts.c +++ b/Downstream/Src/interrupts.c @@ -35,9 +35,6 @@ #include "stm32f4xx.h" #include "interrupts.h" -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ extern HCD_HandleTypeDef hhcd_USB_OTG_FS; @@ -53,14 +50,7 @@ extern DMA_HandleTypeDef hdma_spi1_tx; */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); - HAL_SYSTICK_IRQHandler(); - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -75,13 +65,7 @@ void SysTick_Handler(void) */ void DMA2_Stream2_IRQHandler(void) { - /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */ - - /* USER CODE END DMA2_Stream2_IRQn 0 */ HAL_DMA_IRQHandler(&hdma_spi1_rx); - /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */ - - /* USER CODE END DMA2_Stream2_IRQn 1 */ } /** @@ -89,13 +73,7 @@ void DMA2_Stream2_IRQHandler(void) */ void DMA2_Stream3_IRQHandler(void) { - /* USER CODE BEGIN DMA2_Stream3_IRQn 0 */ - - /* USER CODE END DMA2_Stream3_IRQn 0 */ HAL_DMA_IRQHandler(&hdma_spi1_tx); - /* USER CODE BEGIN DMA2_Stream3_IRQn 1 */ - - /* USER CODE END DMA2_Stream3_IRQn 1 */ } /** @@ -103,16 +81,8 @@ void DMA2_Stream3_IRQHandler(void) */ void OTG_FS_IRQHandler(void) { - /* USER CODE BEGIN OTG_FS_IRQn 0 */ - - /* USER CODE END OTG_FS_IRQn 0 */ HAL_HCD_IRQHandler(&hhcd_USB_OTG_FS); - /* USER CODE BEGIN OTG_FS_IRQn 1 */ - - /* USER CODE END OTG_FS_IRQn 1 */ } -/* USER CODE BEGIN 1 */ -/* USER CODE END 1 */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Downstream/Src/main.c b/Downstream/Src/main.c index 618af68..e37e5a9 100644 --- a/Downstream/Src/main.c +++ b/Downstream/Src/main.c @@ -33,20 +33,15 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal.h" #include "usb_host.h" +#include "board_config.h" -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ SPI_HandleTypeDef hspi1; DMA_HandleTypeDef hdma_spi1_rx; DMA_HandleTypeDef hdma_spi1_tx; -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ -/* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); @@ -55,54 +50,33 @@ static void MX_DMA_Init(void); static void MX_SPI1_Init(void); void MX_USB_HOST_Process(void); -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* USER CODE BEGIN 0 */ -/* USER CODE END 0 */ int main(void) { - - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - /* MCU Configuration----------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* Configure the system clock */ - SystemClock_Config(); - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_SPI1_Init(); - MX_USB_HOST_Init(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN 2 */ + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE END 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_DMA_Init(); + MX_SPI1_Init(); + MX_USB_HOST_Init(); - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ - MX_USB_HOST_Process(); - /* USER CODE BEGIN 3 */ - - } - /* USER CODE END 3 */ + while (1) + { + MX_USB_HOST_Process(); + } } + /** System Clock Configuration */ void SystemClock_Config(void) @@ -123,7 +97,7 @@ void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; RCC_OscInitStruct.PLL.PLLQ = 7; - HAL_RCC_OscConfig(&RCC_OscInitStruct); + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) while (1); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1 |RCC_CLOCKTYPE_PCLK2; @@ -131,18 +105,15 @@ void SystemClock_Config(void) RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); - - HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) while (1); HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); - } + /* SPI1 init function */ void MX_SPI1_Init(void) { - hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_SLAVE; hspi1.Init.Direction = SPI_DIRECTION_2LINES; @@ -156,9 +127,9 @@ void MX_SPI1_Init(void) hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; hspi1.Init.CRCPolynomial = 10; HAL_SPI_Init(&hspi1); - } + /** * Enable DMA controller clock */ @@ -184,12 +155,58 @@ void MX_DMA_Init(void) */ void MX_GPIO_Init(void) { - - /* GPIO Ports Clock Enable */ - __GPIOH_CLK_ENABLE(); - __GPIOA_CLK_ENABLE(); - __GPIOB_CLK_ENABLE(); - + GPIO_InitTypeDef GPIO_InitStruct; + + /* GPIO Ports Clock Enable */ + //__GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOG_CLK_ENABLE(); + + //Bulk initialise all ports as inputs with pullups active, + //excluding JTAG pins which must remain as AF0! + GPIO_InitStruct.Pin = (GPIO_PIN_All & ~(PA_JTMS | PA_JTCK | PA_JTDI)); + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + GPIO_InitStruct.Alternate = 0; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = (GPIO_PIN_All & ~(PB_JTDO | PB_NJTRST)); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_All; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + //USB VBUS pins are analog input + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pin = USB_FS_VBUS_PIN; + HAL_GPIO_Init(USB_FS_VBUS_PORT, &GPIO_InitStruct); + GPIO_InitStruct.Pin = USB_HS_VBUS_PIN; + HAL_GPIO_Init(USB_HS_VBUS_PORT, &GPIO_InitStruct); + + //Enable USB_FS power + USB_FS_VBUSON_PORT->BSRR = (USB_FS_VBUSON_PIN << BSRR_SHIFT_HIGH); + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pin = USB_FS_VBUSON_PIN; + HAL_GPIO_Init(USB_FS_VBUSON_PORT, &GPIO_InitStruct); + + //Disable USB_HS power + USB_HS_VBUSON_PORT->BSRR = (USB_HS_VBUSON_PIN << BSRR_SHIFT_LOW); + GPIO_InitStruct.Pin = USB_HS_VBUSON_PIN; + HAL_GPIO_Init(USB_HS_VBUSON_PORT, &GPIO_InitStruct); + + //STAT_LED is output + STAT_LED_OFF; + GPIO_InitStruct.Pin = STAT_LED_PIN; + HAL_GPIO_Init(STAT_LED_PORT, &GPIO_InitStruct); } /* USER CODE BEGIN 4 */ diff --git a/Upstream/Inc/board_config.h b/Upstream/Inc/board_config.h index 6b904bb..2c848d1 100644 --- a/Upstream/Inc/board_config.h +++ b/Upstream/Inc/board_config.h @@ -23,8 +23,8 @@ #define STAT_LED_PIN GPIO_PIN_12 #define STAT_LED_PORT GPIOC -#define STAT_LED_ON STAT_LED_PORT->BSRR = (STAT_LED_PIN << BSRR_SHIFT_LOW) //Stat LED is active-low -#define STAT_LED_OFF STAT_LED_PORT->BSRR = (STAT_LED_PIN << BSRR_SHIFT_HIGH) +#define STAT_LED_ON (STAT_LED_PORT->BSRR = (STAT_LED_PIN << BSRR_SHIFT_LOW)) //Stat LED is active-low +#define STAT_LED_OFF (STAT_LED_PORT->BSRR = (STAT_LED_PIN << BSRR_SHIFT_HIGH)) #define SPI_DMA_ACTIVE_PIN GPIO_PIN_5 /////////Temporary indicator of SPI & DMA activity #define SPI_DMA_ACTIVE_PORT GPIOB diff --git a/Upstream/Inc/interrupts.h b/Upstream/Inc/interrupts.h index a937955..1fd97e9 100755 --- a/Upstream/Inc/interrupts.h +++ b/Upstream/Inc/interrupts.h @@ -58,6 +58,10 @@ void OTG_FS_IRQHandler(void); void SysTick_Handler(void); +void DMA2_Stream2_IRQHandler(void); +void DMA2_Stream3_IRQHandler(void); +void EXTI3_IRQHandler(void); + #ifdef __cplusplus } diff --git a/Upstream/Src/hal_msp.c b/Upstream/Src/hal_msp.c index ab69075..e3696a4 100755 --- a/Upstream/Src/hal_msp.c +++ b/Upstream/Src/hal_msp.c @@ -78,10 +78,19 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + SPI1_NSS_DEASSERT; GPIO_InitStruct.Pin = SPI1_NSS_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - SPI1_NSS_DEASSERT; + HAL_GPIO_Init(SPI1_NSS_PORT, &GPIO_InitStruct); + + //Configure downstream request pin and interrupt + GPIO_InitStruct.Pin = DOWNSTREAM_TX_OK_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT | GPIO_MODE_IT_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(DOWNSTREAM_TX_OK_PORT, &GPIO_InitStruct); + HAL_NVIC_SetPriority(EXTI3_IRQn, INT_PRIORITY_SPI_DMA, 0); + HAL_NVIC_EnableIRQ(EXTI3_IRQn); //Prepare Tx DMA stream hspi->hdmatx = &spiTxDmaHandle; @@ -116,17 +125,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) HAL_DMA_Init(&spiRxDmaHandle); HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, INT_PRIORITY_SPI_DMA, 0); HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); - - //Configure downstream request pin and interrupt - GPIO_InitStruct.Pin = DOWNSTREAM_TX_OK_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT | GPIO_MODE_IT_FALLING; - - //GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; ////////////////////////////////////////////////! - - HAL_GPIO_Init(DOWNSTREAM_TX_OK_PORT, &GPIO_InitStruct); - HAL_NVIC_SetPriority(EXTI3_IRQn, INT_PRIORITY_SPI_DMA, 0); - HAL_NVIC_EnableIRQ(EXTI3_IRQn); } } diff --git a/Upstream/Src/main.c b/Upstream/Src/main.c index f2227e4..5bc1c31 100755 --- a/Upstream/Src/main.c +++ b/Upstream/Src/main.c @@ -54,12 +54,12 @@ int main(void) { /* MCU Configuration----------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - /* Configure the system clock */ SystemClock_Config(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + /* Initialize all configured peripherals */ GPIO_Init(); USB_Device_Init(); @@ -67,7 +67,6 @@ int main(void) Downstream_InitInterface(); - while (1) { @@ -95,7 +94,7 @@ void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; RCC_OscInitStruct.PLL.PLLQ = 7; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct)) while (1); + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) while (1); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1 |RCC_CLOCKTYPE_PCLK2; @@ -104,6 +103,8 @@ void SystemClock_Config(void) RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2)) while(1); + + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); }