From 25ff5319175382152030f1bf5435886138379a5e Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sat, 14 Nov 2015 11:20:43 +1300 Subject: [PATCH] Tweaks to 1.0 firmware. Not completely working yet :( --- Downstream/Inc/board_config.h | 22 ++------- Downstream/Inc/hal_config.h | 2 +- Downstream/Src/main.c | 89 +++++++++++++--------------------- Upstream/Inc/board_config.h | 17 +++---- Upstream/Src/interrupts.c | 8 +-- Upstream/Src/main.c | 81 +++++++++++++++---------------- Upstream/Upstream Debug.launch | 2 +- 7 files changed, 91 insertions(+), 130 deletions(-) diff --git a/Downstream/Inc/board_config.h b/Downstream/Inc/board_config.h index e004731..c898d76 100644 --- a/Downstream/Inc/board_config.h +++ b/Downstream/Inc/board_config.h @@ -23,18 +23,6 @@ #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 FAULT_LED_PIN GPIO_PIN_13 #define FAULT_LED_PORT GPIOC #define FAULT_LED_ON (FAULT_LED_PORT->BSRR = (FAULT_LED_PIN << BSRR_SHIFT_LOW)) //Fault LED is active-low @@ -57,13 +45,13 @@ #define UPSTREAM_TX_REQUEST_DEASSERT (UPSTREAM_TX_REQUEST_PORT->BSRR = (UPSTREAM_TX_REQUEST_PIN << BSRR_SHIFT_HIGH)) #define DBGMCU_IDCODE_DEV_ID_405_407_415_417 0x413 -#define DBGMCU_IDCODE_DEV_ID_401xB_xC 0x423 +#define DBGMCU_IDCODE_DEV_ID_401xB_xC 0x423 -#define BOARD_REV_PIN_MASK 0x07 -#define BOARD_ID_PIN_MASK 0x08 -#define BOARD_REV_ID_PORT GPIOC +#define BOARD_REV_PIN_MASK 0x07 +#define BOARD_ID_PIN_MASK 0x08 +#define BOARD_REV_ID_PORT GPIOC -#define BOARD_REV_1_0_BETA 0 +#define BOARD_REV_1_0_BETA 0 #endif /* INC_BOARD_CONFIG_H_ */ diff --git a/Downstream/Inc/hal_config.h b/Downstream/Inc/hal_config.h index ef92b14..4c5b8c0 100644 --- a/Downstream/Inc/hal_config.h +++ b/Downstream/Inc/hal_config.h @@ -99,7 +99,7 @@ * (when HSE is used as system clock source, directly or through the PLL). */ #if !defined (HSE_VALUE) - #define HSE_VALUE ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */ + #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSE_STARTUP_TIMEOUT) diff --git a/Downstream/Src/main.c b/Downstream/Src/main.c index 40263ae..ab6d140 100644 --- a/Downstream/Src/main.c +++ b/Downstream/Src/main.c @@ -79,31 +79,31 @@ int main(void) void CheckFirmwareMatchesHardware(void) { //Check we are running on the expected hardware: - //STM32F407 on an Olimex dev board + //STM32F401RC on USG v1.0 beta GPIO_InitTypeDef GPIO_InitStruct; - if ((*(uint32_t*)DBGMCU_BASE & DBGMCU_IDCODE_DEV_ID) == DBGMCU_IDCODE_DEV_ID_401xB_xC) - { - //Read in board revision and ID on port C - __HAL_RCC_GPIOC_CLK_ENABLE(); - GPIO_InitStruct.Pin = BOARD_REV_PIN_MASK | BOARD_ID_PIN_MASK; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - GPIO_InitStruct.Alternate = 0; - HAL_GPIO_Init(BOARD_REV_ID_PORT, &GPIO_InitStruct); - - //Correct board revision? - if ((BOARD_REV_ID_PORT->IDR & BOARD_REV_PIN_MASK) == BOARD_REV_1_0_BETA) - { - //Correct board ID: downstream? - if (!(BOARD_REV_ID_PORT->IDR & BOARD_ID_PIN_MASK)) - { - return; - } - } - } + if ((*(uint32_t*)DBGMCU_BASE & DBGMCU_IDCODE_DEV_ID) == DBGMCU_IDCODE_DEV_ID_401xB_xC) + { + //Read in board revision and ID on port C + __HAL_RCC_GPIOC_CLK_ENABLE(); + GPIO_InitStruct.Pin = BOARD_REV_PIN_MASK | BOARD_ID_PIN_MASK; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + GPIO_InitStruct.Alternate = 0; + HAL_GPIO_Init(BOARD_REV_ID_PORT, &GPIO_InitStruct); + + //Correct board revision? + if ((BOARD_REV_ID_PORT->IDR & BOARD_REV_PIN_MASK) == BOARD_REV_1_0_BETA) + { + //Correct board ID: downstream? + if (!(BOARD_REV_ID_PORT->IDR & BOARD_ID_PIN_MASK)) + { + return; + } + } + } //This is not the hardware we expected, so turn on our fault LED(s) and die in a heap. GPIO_InitStruct.Pin = FAULT_LED_PIN | H405_FAULT_LED_PIN; @@ -159,13 +159,12 @@ void GPIO_Init(void) 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(); + /* 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(); //Bulk initialise all ports as inputs with pullups active, //excluding JTAG pins which must remain as AF0! @@ -180,36 +179,18 @@ void GPIO_Init(void) GPIO_InitStruct.Pin = GPIO_PIN_All; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - HAL_GPIO_Init(GPIOE, &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); + //Fault LED is output + GPIO_InitStruct.Pin = FAULT_LED_PIN; 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 - FAULT_LED_OFF; - GPIO_InitStruct.Pin = FAULT_LED_PIN; HAL_GPIO_Init(FAULT_LED_PORT, &GPIO_InitStruct); + FAULT_LED_OFF; - //SPI_INT_ACTIVE indicator - GPIO_InitStruct.Pin = INT_ACTIVE_PIN; - HAL_GPIO_Init(INT_ACTIVE_PORT, &GPIO_InitStruct); - INT_ACTIVE_OFF; +// //SPI_INT_ACTIVE indicator +// GPIO_InitStruct.Pin = INT_ACTIVE_PIN; +// HAL_GPIO_Init(INT_ACTIVE_PORT, &GPIO_InitStruct); +// INT_ACTIVE_OFF; } diff --git a/Upstream/Inc/board_config.h b/Upstream/Inc/board_config.h index 244df44..183f29a 100644 --- a/Upstream/Inc/board_config.h +++ b/Upstream/Inc/board_config.h @@ -22,16 +22,13 @@ #define PB_JTDO GPIO_PIN_3 #define PB_NJTRST GPIO_PIN_4 -#define USB_P_PIN GPIO_PIN_4 -#define USB_P_PORT GPIOC - #define FAULT_LED_PIN GPIO_PIN_13 #define FAULT_LED_PORT GPIOC #define FAULT_LED_ON (FAULT_LED_PORT->BSRR = (FAULT_LED_PIN << BSRR_SHIFT_LOW)) //Fault LED is active-low #define FAULT_LED_OFF (FAULT_LED_PORT->BSRR = (FAULT_LED_PIN << BSRR_SHIFT_HIGH)) -#define H405_FAULT_LED_PIN GPIO_PIN_12 //Fault LED on Olimex H405 board -#define H405_FAULT_LED_ON (FAULT_LED_PORT->BSRR = (H405_FAULT_LED_PIN << BSRR_SHIFT_LOW)) +#define H405_FAULT_LED_PIN GPIO_PIN_12 //Fault LED on Olimex H405 board +#define H405_FAULT_LED_ON (FAULT_LED_PORT->BSRR = (H405_FAULT_LED_PIN << BSRR_SHIFT_LOW)) #define INT_ACTIVE_PIN GPIO_PIN_5 //Temporary indicator of SPI (or whatever) activity #define INT_ACTIVE_PORT GPIOB @@ -48,13 +45,13 @@ #define DOWNSTREAM_TX_OK_ACTIVE (!(DOWNSTREAM_TX_OK_PORT->IDR & DOWNSTREAM_TX_OK_PIN)) #define DBGMCU_IDCODE_DEV_ID_405_407_415_417 0x413 -#define DBGMCU_IDCODE_DEV_ID_401xB_xC 0x423 +#define DBGMCU_IDCODE_DEV_ID_401xB_xC 0x423 -#define BOARD_REV_PIN_MASK 0x07 -#define BOARD_ID_PIN_MASK 0x08 -#define BOARD_REV_ID_PORT GPIOC +#define BOARD_REV_PIN_MASK 0x07 +#define BOARD_ID_PIN_MASK 0x08 +#define BOARD_REV_ID_PORT GPIOC -#define BOARD_REV_1_0_BETA 0 +#define BOARD_REV_1_0_BETA 0 #endif /* INC_BOARD_CONFIG_H_ */ diff --git a/Upstream/Src/interrupts.c b/Upstream/Src/interrupts.c index 82ac923..a74544c 100755 --- a/Upstream/Src/interrupts.c +++ b/Upstream/Src/interrupts.c @@ -74,16 +74,16 @@ void OTG_FS_IRQHandler(void) void DMA2_Stream2_IRQHandler(void) { - INT_ACTIVE_ON; +// INT_ACTIVE_ON; HAL_DMA_IRQHandler(&spiRxDmaHandle); - INT_ACTIVE_OFF; +// INT_ACTIVE_OFF; } void DMA2_Stream3_IRQHandler(void) { - INT_ACTIVE_ON; +// INT_ACTIVE_ON; HAL_DMA_IRQHandler(&spiTxDmaHandle); - INT_ACTIVE_OFF; +// INT_ACTIVE_OFF; } void EXTI3_IRQHandler(void) diff --git a/Upstream/Src/main.c b/Upstream/Src/main.c index c9b8faf..dcac50e 100755 --- a/Upstream/Src/main.c +++ b/Upstream/Src/main.c @@ -84,40 +84,40 @@ int main(void) void CheckFirmwareMatchesHardware(void) { //Check we are running on the expected hardware: - //STM32F405 on an Olimex dev board + //STM32F401RC on USG v1.0 beta GPIO_InitTypeDef GPIO_InitStruct; - if ((*(uint32_t*)DBGMCU_BASE & DBGMCU_IDCODE_DEV_ID) == DBGMCU_IDCODE_DEV_ID_401xB_xC) - { - //Read in board revision and ID on port C - __HAL_RCC_GPIOC_CLK_ENABLE(); - GPIO_InitStruct.Pin = BOARD_REV_PIN_MASK | BOARD_ID_PIN_MASK; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - GPIO_InitStruct.Alternate = 0; - HAL_GPIO_Init(BOARD_REV_ID_PORT, &GPIO_InitStruct); - - //Correct board revision? - if ((BOARD_REV_ID_PORT->IDR & BOARD_REV_PIN_MASK) == BOARD_REV_1_0_BETA) - { - //Correct board ID: upstream? - if ((BOARD_REV_ID_PORT->IDR & BOARD_ID_PIN_MASK)) - { - return; - } - } - } - - //This is not the hardware we expected, so turn on our fault LED(s) and die in a heap. - GPIO_InitStruct.Pin = FAULT_LED_PIN | H405_FAULT_LED_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(FAULT_LED_PORT, &GPIO_InitStruct); - FAULT_LED_ON; - H405_FAULT_LED_ON; - while (1); + if ((*(uint32_t*)DBGMCU_BASE & DBGMCU_IDCODE_DEV_ID) == DBGMCU_IDCODE_DEV_ID_401xB_xC) + { + //Read in board revision and ID on port C + __HAL_RCC_GPIOC_CLK_ENABLE(); + GPIO_InitStruct.Pin = BOARD_REV_PIN_MASK | BOARD_ID_PIN_MASK; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + GPIO_InitStruct.Alternate = 0; + HAL_GPIO_Init(BOARD_REV_ID_PORT, &GPIO_InitStruct); + + //Correct board revision? + if ((BOARD_REV_ID_PORT->IDR & BOARD_REV_PIN_MASK) == BOARD_REV_1_0_BETA) + { + //Correct board ID: upstream? + if ((BOARD_REV_ID_PORT->IDR & BOARD_ID_PIN_MASK)) + { + return; + } + } + } + + //This is not the hardware we expected, so turn on our fault LED(s) and die in a heap. + GPIO_InitStruct.Pin = FAULT_LED_PIN | H405_FAULT_LED_PIN; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(FAULT_LED_PORT, &GPIO_InitStruct); + FAULT_LED_ON; + H405_FAULT_LED_ON; + while (1); } @@ -191,24 +191,19 @@ void GPIO_Init(void) HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - //USB_P is analog input - GPIO_InitStruct.Pin = USB_P_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - HAL_GPIO_Init(USB_P_PORT, &GPIO_InitStruct); - - //STAT_LED is output + //Fault LED is output GPIO_InitStruct.Pin = FAULT_LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(FAULT_LED_PORT, &GPIO_InitStruct); FAULT_LED_OFF; - //SPI_INT_ACTIVE indicator - GPIO_InitStruct.Pin = INT_ACTIVE_PIN; - //GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - //GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(INT_ACTIVE_PORT, &GPIO_InitStruct); - INT_ACTIVE_OFF; +// //SPI_INT_ACTIVE indicator +// GPIO_InitStruct.Pin = INT_ACTIVE_PIN; +// //GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; +// //GPIO_InitStruct.Pull = GPIO_NOPULL; +// HAL_GPIO_Init(INT_ACTIVE_PORT, &GPIO_InitStruct); +// INT_ACTIVE_OFF; } /* USER CODE BEGIN 4 */ diff --git a/Upstream/Upstream Debug.launch b/Upstream/Upstream Debug.launch index e8f5790..3cb0dd2 100644 --- a/Upstream/Upstream Debug.launch +++ b/Upstream/Upstream Debug.launch @@ -1,6 +1,6 @@ - +