From: drowe67 Date: Tue, 7 Jun 2016 08:06:00 +0000 (+0000) Subject: si5351 UT working, need to clean up printfs X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=bb106eb939fb263c18394db79ff0d8f7981ec760;p=freetel-svn-tracking.git si5351 UT working, need to clean up printfs git-svn-id: https://svn.code.sf.net/p/freetel/code@2816 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 098cd6cb..f3a1fe9b 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -809,6 +809,7 @@ fm_loduc_play.elf: $(FM_LODUC_PLAY_SRCS) src/stm32f4_dacloduc.o # --------------------------------------------------------------------------------- SI5351_UT_SRCS=\ +gdb_stdio.c \ src/si5351_ut.c \ src/new_i2c.c \ src/si53xx.c \ @@ -816,8 +817,8 @@ src/system_stm32f4xx.c \ src/startup_stm32f4xx.s \ src/init.c \ -si5351_ut.elf: $(SI5351_UT_SRCS:.c=.O3.o) libstm32f4.a - $(CC) $(CFLAGS) -O3 $^ -o $@ $(LIBPATHS) $(LIBS) +si5351_ut.elf: $(SI5351_UT_SRCS:.c=.o) libstm32f4.a + $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) # --------------------------------------------------------------------------------- diff --git a/codec2-dev/stm32/src/new_i2c.c b/codec2-dev/stm32/src/new_i2c.c index 0f678f4f..abc5170b 100644 --- a/codec2-dev/stm32/src/new_i2c.c +++ b/codec2-dev/stm32/src/new_i2c.c @@ -10,7 +10,7 @@ /* - Copyright (C) 2016 David Rowe + Copyright (C) 2016 Leon All rights reserved. @@ -264,19 +264,19 @@ uint32_t I2C_NewReadRegister(uint8_t Addr,uint8_t Register) { } (void) I2C_DEVICE->SR2; Timeout = I2C_STIMEOUT; - while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_TXE)) { + while (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_TXE)) { if ((Timeout--) == 0) return I2C_timeout(0x104); } I2C_SendData(I2C_DEVICE, Register); Timeout = I2C_STIMEOUT; while ( (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_TXE)) || - (!I2C_GetFlagStatus(I2C1, I2C_FLAG_BTF)) + (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_BTF)) ) { if ((Timeout--) == 0) return I2C_timeout(0x105); } I2C_GenerateSTART(I2C_DEVICE, ENABLE); Timeout = I2C_STIMEOUT; - while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB)) { + while (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_SB)) { if ((Timeout--) == 0) return I2C_timeout(0x106); } I2C_Send7bitAddress(I2C_DEVICE, Addr, I2C_Direction_Receiver); @@ -285,7 +285,7 @@ uint32_t I2C_NewReadRegister(uint8_t Addr,uint8_t Register) { if ((Timeout--) == 0) return I2C_timeout(0x107); } (void) I2C_DEVICE->SR2; - while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE)) { + while (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_RXNE)) { if ((Timeout--) == 0) return I2C_timeout(0x108); } I2C_GenerateSTOP(I2C_DEVICE, ENABLE); @@ -381,19 +381,19 @@ uint32_t I2C_NewReadRegisterN(uint8_t Addr,uint8_t Register,uint8_t *buffer, uin } (void) I2C_DEVICE->SR2; Timeout = I2C_STIMEOUT; - while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_TXE)) { + while (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_TXE)) { if ((Timeout--) == 0) return I2C_timeout(0x104); } I2C_SendData(I2C_DEVICE, Register); Timeout = I2C_STIMEOUT; while ( (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_TXE)) || - (!I2C_GetFlagStatus(I2C1, I2C_FLAG_BTF)) + (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_BTF)) ) { if ((Timeout--) == 0) return I2C_timeout(0x105); } I2C_GenerateSTART(I2C_DEVICE, ENABLE); Timeout = I2C_STIMEOUT; - while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB)) { + while (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_SB)) { if ((Timeout--) == 0) return I2C_timeout(0x106); } I2C_Send7bitAddress(I2C_DEVICE, Addr, I2C_Direction_Receiver); @@ -405,12 +405,12 @@ uint32_t I2C_NewReadRegisterN(uint8_t Addr,uint8_t Register,uint8_t *buffer, uin for (cnt=0; cnt= N) { // ACK disable - I2C_AcknowledgeConfig(I2C1, DISABLE); + I2C_AcknowledgeConfig(I2C_DEVICE, DISABLE); // Stop-Sequenz - I2C_GenerateSTOP(I2C1, ENABLE); + I2C_GenerateSTOP(I2C_DEVICE, ENABLE); } Timeout = I2C_STIMEOUT; - while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE)) { + while (!I2C_GetFlagStatus(I2C_DEVICE, I2C_FLAG_RXNE)) { if ((Timeout--) == 0) return I2C_timeout(0x108); } result=I2C_ReceiveData(I2C_DEVICE); diff --git a/codec2-dev/stm32/src/si5351_ut.c b/codec2-dev/stm32/src/si5351_ut.c index 0b5187dd..953c6237 100644 --- a/codec2-dev/stm32/src/si5351_ut.c +++ b/codec2-dev/stm32/src/si5351_ut.c @@ -29,10 +29,19 @@ #include #include "new_i2c.h" #include "si53xx.h" +#include "gdb_stdio.h" + +#define printf gdb_stdio_printf int main(void) { + int ret; + + printf("starting\n"); I2C_Setup(); - si5351_init(0x60, 5, 25000000); - si5351_set_freq(10000000, 0, SI5351_CLK0); + si5351_init(0, SI5351_CRYSTAL_LOAD_6PF, 0); + + ret = si5351_set_freq(1000000000ULL, 0, SI5351_CLK0); + printf(" ret = %d\n", ret); + while(1); } diff --git a/codec2-dev/stm32/src/si53xx.c b/codec2-dev/stm32/src/si53xx.c index 79e634b9..2876c188 100644 --- a/codec2-dev/stm32/src/si53xx.c +++ b/codec2-dev/stm32/src/si53xx.c @@ -42,11 +42,19 @@ #include "math.h" #include "si53xx.h" +#include "gdb_stdio.h" +#define printf gdb_stdio_printf + void si5351_write(uint8_t REGaddr, uint8_t data) { // ignoring errors // Waiting for the bite Si5351_Config.I2C_ErrorCode=I2C_NewWriteRegister(Si5351_Config.I2C_add, REGaddr, data); + printf(" si5351_write: REGaddr: 0x%02x data...: 0x%02x", REGaddr, data); + if (Si5351_Config.I2C_ErrorCode > 0xff) + printf(" ErrorCode: 0x%02x\n", Si5351_Config.I2C_ErrorCode); + else + printf("\n"); } void si5351_write_bulk(uint8_t REGaddr, uint8_t bytes, uint8_t *data) { @@ -57,11 +65,14 @@ void si5351_write_bulk(uint8_t REGaddr, uint8_t bytes, uint8_t *data) { uint8_t si5351_read(uint8_t REGaddr) { uint8_t reg_val; Si5351_Config.I2C_ErrorCode=I2C_NewReadRegister(Si5351_Config.I2C_add,REGaddr); + printf(" si5351_read.: REGaddr: 0x%02x", REGaddr); if (Si5351_Config.I2C_ErrorCode>0xff) { reg_val=0; + printf(" ErrorCode: 0x%02x\n", Si5351_Config.I2C_ErrorCode); } else { reg_val=(uint8_t)(Si5351_Config.I2C_ErrorCode & 0xff); Si5351_Config.I2C_ErrorCode=0; + printf(" reg_val: 0x%02x\n", reg_val); } return reg_val; } @@ -82,6 +93,8 @@ uint8_t si5351_read(uint8_t REGaddr) { *------------------------------------------------------------------------------ */ void si5351_init(uint8_t I2C_Address, uint8_t xtal_load_c, uint32_t ref_osc_freq) { + printf("si5351_init\n"); + Si5351_Config.clk0_freq=0; Si5351_Config.lock_plla = SI5351_CLKNONE; Si5351_Config.lock_pllb = SI5351_CLKNONE; @@ -100,6 +113,11 @@ void si5351_init(uint8_t I2C_Address, uint8_t xtal_load_c, uint32_t ref_osc_freq uint8_t reg_val = 0x12; // 0b010010 reserved value bits reg_val |= xtal_load_c; si5351_write(SI5351_CRYSTAL_LOAD, reg_val); + + // DR: test of I2C + reg_val = si5351_read(SI5351_CRYSTAL_LOAD); + printf("reg_val: 0x%02x\n", reg_val); + // Change the ref osc freq if different from default // Divide down if greater than 30 MHz if (ref_osc_freq != 0) { @@ -160,6 +178,8 @@ uint8_t si5351_set_freq(uint64_t freq, uint64_t pll_freq, enum si5351_clock clk) uint8_t int_mode = 0; uint8_t div_by_4 = 0; + printf("si5351_set_freq:\n"); + // PLL bounds checking if(pll_freq != 0) { if ((pll_freq < SI5351_PLL_VCO_MIN * SI5351_FREQ_MULT) @@ -168,6 +188,8 @@ uint8_t si5351_set_freq(uint64_t freq, uint64_t pll_freq, enum si5351_clock clk) } } + printf("freq: 0x%0x 0x%0x\n", (uint32_t)(freq >> 32), (uint32_t)(freq & 0xffffffff)); + // Lower bounds check if(freq < SI5351_CLKOUT_MIN_FREQ * SI5351_FREQ_MULT) { freq = SI5351_CLKOUT_MIN_FREQ * SI5351_FREQ_MULT; @@ -178,6 +200,8 @@ uint8_t si5351_set_freq(uint64_t freq, uint64_t pll_freq, enum si5351_clock clk) freq = SI5351_MULTISYNTH_MAX_FREQ * SI5351_FREQ_MULT; } + printf("freq: 0x%0x 0x%0x\n", (uint32_t)(freq >> 32), (uint32_t)(freq & 0xffffffff)); + // Select the proper R div value r_div = si5351_select_r_div(&freq); @@ -217,11 +241,15 @@ uint8_t si5351_set_freq(uint64_t freq, uint64_t pll_freq, enum si5351_clock clk) // Only good for Si5351A3 variant at the moment switch(clk) { case SI5351_CLK0: + printf("case SI5351_CLK0\n"); pll_freq = si5351_multisynth_calc(freq, 0, &ms_reg); target_pll = SI5351_PLLA; write_pll = 1; si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA); + printf("pll_freq: 0x%0x 0x%0x\n", (uint32_t)(pll_freq >> 32), (uint32_t)(pll_freq & 0xffffffff)); + printf("freq: 0x%0x 0x%0x\n", (uint32_t)(freq >> 32), (uint32_t)(freq & 0xffffffff)); + Si5351_Config.plla_freq = pll_freq; Si5351_Config.clk0_freq = freq; break;