From 9b435f3b7e8b224edd4340686313fc11adf83e78 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 10:10:53 -0700 Subject: [PATCH 1/8] Configure APB3 for appropriate clock sources during start-up. --- firmware/common/hackrf_core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index dc4c4708..c06452d4 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -261,6 +261,9 @@ void cpu_clock_init(void) /* use IRC as clock source for APB1 (including I2C0) */ CGU_BASE_APB1_CLK = CGU_BASE_APB1_CLK_CLK_SEL(CGU_SRC_IRC); + /* use IRC as clock source for APB3 */ + CGU_BASE_APB3_CLK = CGU_BASE_APB3_CLK_CLK_SEL(CGU_SRC_IRC); + i2c0_init(15); si5351c_disable_all_outputs(); @@ -365,6 +368,10 @@ void cpu_clock_init(void) CGU_BASE_APB1_CLK = CGU_BASE_APB1_CLK_AUTOBLOCK(1) | CGU_BASE_APB1_CLK_CLK_SEL(CGU_SRC_XTAL); + /* use XTAL_OSC as clock source for APB3 */ + CGU_BASE_APB3_CLK = CGU_BASE_APB3_CLK_AUTOBLOCK(1) + | CGU_BASE_APB3_CLK_CLK_SEL(CGU_SRC_XTAL); + cpu_clock_pll1_low_speed(); /* use PLL1 as clock source for BASE_M4_CLK (CPU) */ @@ -400,6 +407,10 @@ void cpu_clock_init(void) /* Switch APB1 clock over to use PLL1 (204MHz) */ CGU_BASE_APB1_CLK = CGU_BASE_APB1_CLK_AUTOBLOCK(1) | CGU_BASE_APB1_CLK_CLK_SEL(CGU_SRC_PLL1); + + /* Switch APB3 clock over to use PLL1 (204MHz) */ + CGU_BASE_APB3_CLK = CGU_BASE_APB3_CLK_AUTOBLOCK(1) + | CGU_BASE_APB3_CLK_CLK_SEL(CGU_SRC_PLL1); } From 739dc1acd962fe62ab814ad51049acdc6879a123 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 10:13:25 -0700 Subject: [PATCH 2/8] Add GCC "used" attribute to prevent hard_fault_handler_c() from being removed. It trips up -flto. --- firmware/common/fault_handler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/common/fault_handler.c b/firmware/common/fault_handler.c index 50331335..c43a2f50 100644 --- a/firmware/common/fault_handler.c +++ b/firmware/common/fault_handler.c @@ -47,7 +47,7 @@ void hard_fault_handler(void) { volatile hard_fault_stack_t* hard_fault_stack_pt; -void hard_fault_handler_c(uint32_t* args) +__attribute__((used)) void hard_fault_handler_c(uint32_t* args) { /* hard_fault_stack_pt contains registers saved before the hard fault */ hard_fault_stack_pt = (hard_fault_stack_t*)args; From 2abdebfb2af087da19f832c9ff2d8f8b19aed9ea Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 10:17:49 -0700 Subject: [PATCH 3/8] Add parentheses to silence ambiguous expression warning. --- firmware/common/tuning.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/common/tuning.c b/firmware/common/tuning.c index 050a0602..921c1916 100644 --- a/firmware/common/tuning.c +++ b/firmware/common/tuning.c @@ -114,7 +114,7 @@ bool set_freq_explicit(const uint64_t if_freq_hz, const uint64_t lo_freq_hz, } if ((path != RF_PATH_FILTER_BYPASS) && - (lo_freq_hz < MIN_LO_FREQ_HZ) || (lo_freq_hz > MAX_LO_FREQ_HZ)) { + ((lo_freq_hz < MIN_LO_FREQ_HZ) || (lo_freq_hz > MAX_LO_FREQ_HZ))) { return false; } From fe9b4b8ca8a6b6173fd51f07955b0053ed7bc89e Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 11:56:17 -0700 Subject: [PATCH 4/8] Remove RF power enable from blinky -- it's not necessary. --- firmware/blinky/blinky.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/firmware/blinky/blinky.c b/firmware/blinky/blinky.c index 77be8339..0201cff4 100644 --- a/firmware/blinky/blinky.c +++ b/firmware/blinky/blinky.c @@ -33,9 +33,6 @@ int main(void) /* enable all power supplies */ enable_1v8_power(); -#ifdef HACKRF_ONE - enable_rf_power(); -#endif /* Blink LED1/2/3 on the board and Read BOOT0/1/2/3 pins. */ while (1) From 25387851657022cfca24806b5e1925469fd4326e Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 11:57:42 -0700 Subject: [PATCH 5/8] Replace GPIO control of 1V8 supply with official function enable_1v8_power(). --- firmware/mixertx/mixertx.c | 2 +- firmware/simpletx/simpletx.c | 2 +- firmware/spiflash/spiflash.c | 3 +-- firmware/startup/startup.c | 2 +- firmware/startup_systick/startup_systick.c | 2 +- firmware/startup_systick_perfo/startup_systick.c | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/firmware/mixertx/mixertx.c b/firmware/mixertx/mixertx.c index 18415944..b3896cfa 100644 --- a/firmware/mixertx/mixertx.c +++ b/firmware/mixertx/mixertx.c @@ -33,7 +33,7 @@ int main(void) const uint32_t freq = 2441000000U; pin_setup(); - gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */ + enable_1v8_power(); cpu_clock_init(); ssp1_init(); diff --git a/firmware/simpletx/simpletx.c b/firmware/simpletx/simpletx.c index e50fbf54..0153f4df 100644 --- a/firmware/simpletx/simpletx.c +++ b/firmware/simpletx/simpletx.c @@ -32,7 +32,7 @@ int main(void) const uint32_t freq = 2441000000U; pin_setup(); - gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */ + enable_1v8_power(); cpu_clock_init(); ssp1_init(); diff --git a/firmware/spiflash/spiflash.c b/firmware/spiflash/spiflash.c index 0e8546e4..e1ae772e 100644 --- a/firmware/spiflash/spiflash.c +++ b/firmware/spiflash/spiflash.c @@ -32,8 +32,7 @@ int main(void) pin_setup(); - /* Set 1V8 */ - gpio_set(PORT_EN1V8, PIN_EN1V8); + enable_1v8_power(); cpu_clock_init(); diff --git a/firmware/startup/startup.c b/firmware/startup/startup.c index 71a62010..b6d0be65 100644 --- a/firmware/startup/startup.c +++ b/firmware/startup/startup.c @@ -31,7 +31,7 @@ int main(void) pin_setup(); - gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */ + enable_1v8_power(); cpu_clock_init(); diff --git a/firmware/startup_systick/startup_systick.c b/firmware/startup_systick/startup_systick.c index 5a38d2e6..d4c8517e 100644 --- a/firmware/startup_systick/startup_systick.c +++ b/firmware/startup_systick/startup_systick.c @@ -131,7 +131,7 @@ int main(void) { pin_setup(); - gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */ + enable_1v8_power(); cpu_clock_init(); diff --git a/firmware/startup_systick_perfo/startup_systick.c b/firmware/startup_systick_perfo/startup_systick.c index 3aea48fd..26c1fcc0 100644 --- a/firmware/startup_systick_perfo/startup_systick.c +++ b/firmware/startup_systick_perfo/startup_systick.c @@ -144,7 +144,7 @@ int main(void) { pin_setup(); - gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */ + enable_1v8_power(); cpu_clock_init(); From 54ef8c19cfcd879822f4214389b22055e79d1d38 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 12:00:32 -0700 Subject: [PATCH 6/8] Add HackRF One RF power enable for samples that RX or TX. --- firmware/mixertx/mixertx.c | 3 +++ firmware/sgpio-rx/sgpio-rx.c | 3 +++ firmware/simpletx/simpletx.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/firmware/mixertx/mixertx.c b/firmware/mixertx/mixertx.c index b3896cfa..363859f5 100644 --- a/firmware/mixertx/mixertx.c +++ b/firmware/mixertx/mixertx.c @@ -34,6 +34,9 @@ int main(void) pin_setup(); enable_1v8_power(); +#ifdef HACKRF_ONE + enable_rf_power(); +#endif cpu_clock_init(); ssp1_init(); diff --git a/firmware/sgpio-rx/sgpio-rx.c b/firmware/sgpio-rx/sgpio-rx.c index a5fb1e86..dbee1d3f 100644 --- a/firmware/sgpio-rx/sgpio-rx.c +++ b/firmware/sgpio-rx/sgpio-rx.c @@ -92,6 +92,9 @@ int main(void) { pin_setup(); enable_1v8_power(); +#ifdef HACKRF_ONE + enable_rf_power(); +#endif cpu_clock_init(); ssp1_init(); rf_path_init(); diff --git a/firmware/simpletx/simpletx.c b/firmware/simpletx/simpletx.c index 0153f4df..04efb686 100644 --- a/firmware/simpletx/simpletx.c +++ b/firmware/simpletx/simpletx.c @@ -33,6 +33,9 @@ int main(void) pin_setup(); enable_1v8_power(); +#ifdef HACKRF_ONE + enable_rf_power(); +#endif cpu_clock_init(); ssp1_init(); From 16709505fc9e184332184a871a8974a9c04f4ee4 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 12:35:59 -0700 Subject: [PATCH 7/8] USB0 and USB1 LEDs are only on Jellybean and Jawbreaker. --- firmware/common/hackrf_core.c | 2 ++ firmware/common/hackrf_core.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index c06452d4..53918c9c 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -595,8 +595,10 @@ void pin_setup(void) { scu_pinmux(SCU_PINMUX_BOOT3, SCU_GPIO_FAST); /* Configure USB indicators */ +#if (defined JELLYBEAN || defined JAWBREAKER) scu_pinmux(SCU_PINMUX_USB_LED0, SCU_CONF_FUNCTION3); scu_pinmux(SCU_PINMUX_USB_LED1, SCU_CONF_FUNCTION3); +#endif /* Configure all GPIO as Input (safe state) */ GPIO0_DIR = 0; diff --git a/firmware/common/hackrf_core.h b/firmware/common/hackrf_core.h index 0b9a833b..8ce6c943 100644 --- a/firmware/common/hackrf_core.h +++ b/firmware/common/hackrf_core.h @@ -67,8 +67,10 @@ extern "C" #define SCU_PINMUX_BOOT3 (P2_9) /* GPIO1[10] on P2_9 */ /* USB peripheral */ +#if (defined JELLYBEAN || defined JAWBREAKER) #define SCU_PINMUX_USB_LED0 (P6_8) #define SCU_PINMUX_USB_LED1 (P6_7) +#endif /* SSP1 Peripheral PinMux */ #define SCU_SSP1_MISO (P1_3) /* P1_3 */ From 245aa1f11eec16e0bbfcf2bcdc34207e17bd3e34 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 15 Jun 2014 12:36:42 -0700 Subject: [PATCH 8/8] Do not configure BOOT[3:0] pins in SCU, as they should be idle/input/hi-Z on HackRF. --- firmware/common/hackrf_core.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index 53918c9c..b862ba4f 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -589,11 +589,6 @@ void pin_setup(void) { scu_pinmux(SCU_PINMUX_EN1V8, SCU_GPIO_NOPULL); - scu_pinmux(SCU_PINMUX_BOOT0, SCU_GPIO_FAST); - scu_pinmux(SCU_PINMUX_BOOT1, SCU_GPIO_FAST); - scu_pinmux(SCU_PINMUX_BOOT2, SCU_GPIO_FAST); - scu_pinmux(SCU_PINMUX_BOOT3, SCU_GPIO_FAST); - /* Configure USB indicators */ #if (defined JELLYBEAN || defined JAWBREAKER) scu_pinmux(SCU_PINMUX_USB_LED0, SCU_CONF_FUNCTION3);