DEVEL activate button B1, correct some line endings

This commit is contained in:
Tom Kuschel 2022-05-27 21:29:56 +02:00
parent 136191111f
commit efdf1e0764
7 changed files with 990 additions and 908 deletions

View File

@ -57,6 +57,8 @@ void Error_Handler(void);
/* USER CODE END EFP */ /* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/
#define B1_Pin GPIO_PIN_13
#define B1_GPIO_Port GPIOC
#define LD3_Pin GPIO_PIN_14 #define LD3_Pin GPIO_PIN_14
#define LD3_GPIO_Port GPIOB #define LD3_GPIO_Port GPIOB
#define USB_OverCurrent_Pin GPIO_PIN_5 #define USB_OverCurrent_Pin GPIO_PIN_5

View File

@ -152,7 +152,6 @@ char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize,
int si5351_write_data(si5351_inst_t inst, void * data); int si5351_write_data(si5351_inst_t inst, void * data);
int si5351_read_data(si5351_inst_t inst, void * data); int si5351_read_data(si5351_inst_t inst, void * data);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View File

@ -152,7 +152,7 @@
#endif /* LSE_VALUE */ #endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT) #if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 50000U /*!< Time out for LSE start up, in ms */ #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */ #endif /* HSE_STARTUP_TIMEOUT */
/** /**

View File

@ -82,7 +82,7 @@ const osSemaphoreAttr_t si5351_attributes = {
.name = "si5351" .name = "si5351"
}; };
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
int leds_on = 1;
/* USER CODE END PV */ /* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
@ -286,7 +286,7 @@ void SystemClock_Config(void)
/** Configure LSE Drive Capability /** Configure LSE Drive Capability
*/ */
HAL_PWR_EnableBkUpAccess(); HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH); __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Initializes the RCC Oscillators according to the specified parameters /** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure. * in the RCC_OscInitTypeDef structure.
@ -315,11 +315,11 @@ void SystemClock_Config(void)
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV8;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
} }
@ -342,7 +342,7 @@ static void MX_I2C1_Init(void)
/* USER CODE END I2C1_Init 1 */ /* USER CODE END I2C1_Init 1 */
hi2c1.Instance = I2C1; hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x00505B89; hi2c1.Init.Timing = 0x00000001;
hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
@ -513,17 +513,11 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pins : PC13 PC0 PC1 PC2 /*Configure GPIO pin : B1_Pin */
PC3 PC4 PC5 PC6 GPIO_InitStruct.Pin = B1_Pin;
PC8 PC9 PC10 PC11 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
PC12 */ GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2 HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PF0 PF1 PF2 PF3 /*Configure GPIO pins : PF0 PF1 PF2 PF3
PF4 PF5 PF6 PF7 PF4 PF5 PF6 PF7
@ -543,6 +537,16 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
/*Configure GPIO pins : PC0 PC1 PC2 PC3
PC4 PC5 PC6 PC8
PC9 PC10 PC11 PC12 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PA0 PA1 PA2 PA3 /*Configure GPIO pins : PA0 PA1 PA2 PA3
PA4 PA5 PA6 PA7 PA4 PA5 PA6 PA7
PA15 */ PA15 */
@ -656,11 +660,12 @@ void make_di_dah(si5351_inst_t inst, unsigned int dah, uint32_t delay, uint8_t c
#define SEMAPHORE 0 #define SEMAPHORE 0
/* inner function, no need to check inst, clk, nor delay */ /* inner function, no need to check inst, clk, nor delay */
#if 1 #if 1
if (clk==0) if (leds_on) {
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET); if (clk==0)
else HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET); else
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
}
#endif #endif
#if SEMAPHORE #if SEMAPHORE
osSemaphoreAcquire(si5351Handle, osWaitForever); osSemaphoreAcquire(si5351Handle, osWaitForever);
@ -781,17 +786,24 @@ void morse(si5351_inst_t inst, char * s, uint32_t delay, uint8_t clk) {
/* USER CODE END Header_StartDefaultTask */ /* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument) void StartDefaultTask(void *argument)
{ {
/* USER CODE BEGIN 5 */ /* USER CODE BEGIN 5 */
(void) argument; //unused argument (void) argument; //unused argument
int sw, sw_last = GPIO_PIN_RESET;
/* Infinite loop */ /* Infinite loop */
for(;;) { for(;;) {
// HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin); // HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
osDelay(5); osDelay(5);
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
osDelay(2000); sw = HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
if (sw_last == GPIO_PIN_RESET && sw == GPIO_PIN_SET) {
leds_on = !leds_on;
}
sw_last = sw;
osDelay(2000);
} }
/* USER CODE END 5 */ /* USER CODE END 5 */
} }
/* USER CODE BEGIN Header_start_terminal_task */ /* USER CODE BEGIN Header_start_terminal_task */
@ -834,7 +846,7 @@ void start_terminal_task(void *argument)
void start_morse_task(void *argument) void start_morse_task(void *argument)
{ {
/* USER CODE BEGIN start_morse_task */ /* USER CODE BEGIN start_morse_task */
static const uint32_t delay = 10; static const uint32_t delay = 100;
static const uint8_t clk = 0; static const uint8_t clk = 0;
si5351_inst_t inst = argument; si5351_inst_t inst = argument;
int i = 0; int i = 0;
@ -866,7 +878,7 @@ void start_morse_task(void *argument)
void start_clk2_task(void *argument) void start_clk2_task(void *argument)
{ {
/* USER CODE BEGIN start_clk2_task */ /* USER CODE BEGIN start_clk2_task */
static const uint32_t delay = 10; static const uint32_t delay = 100;
static const uint8_t clk =2; static const uint8_t clk =2;
si5351_inst_t inst = argument; si5351_inst_t inst = argument;
int i = 0; int i = 0;

View File

@ -1,8 +1,8 @@
/** /**
****************************************************************************** ******************************************************************************
* @file stm32_si5351.c * @file stm32_si5351.c
* @brief STM32 library/driver for the Si5351 clock chip * @brief STM32 library/driver for the Si5351 clock chip
from Skyworks Solutions, Inc. (former SiLabs) from Skyworks Solutions, Inc. (former SiLabs)
****************************************************************************** ******************************************************************************
* @author: Thomas Kuschel KW4NZ * @author: Thomas Kuschel KW4NZ
* created 2022-05-11 * created 2022-05-11
@ -130,7 +130,7 @@ int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk);
/** @brief Give better error numbers based on the Linux error_no.h /** @brief Give better error numbers based on the Linux error_no.h
* @param i2c_handle the handle of the I2C bus from HAL function, e.g. hi2c1 * @param i2c_handle the handle of the I2C bus from HAL function, e.g. hi2c1
* @param xtal_frequency either the XTAL frequency (25/27 MHz) or CLock-In * @param xtal_frequency either the XTAL frequency (25/27 MHz) or CLock-In
* from 10 MHz to 100 MHz entered in Hz * from 10 MHz to 100 MHz entered in Hz
* @param i2c_address I2C bus address of the device from datasheet typically 0x60 (or 0x61) * @param i2c_address I2C bus address of the device from datasheet typically 0x60 (or 0x61)
* @param datasize reserve an extra area of data space in bytes, access with function si5351_read_data() and si5351_write_data() * @param datasize reserve an extra area of data space in bytes, access with function si5351_read_data() and si5351_write_data()
* @return si5351_handle Pointer to the si5351 handle, NULL if error, see si5351_errno * @return si5351_handle Pointer to the si5351 handle, NULL if error, see si5351_errno
@ -221,7 +221,7 @@ si5351_HandleTypeDef *si5351_initialize(void * i2c_handle) {
/** @brief Initialize the device Si5351 with the main parameters /** @brief Initialize the device Si5351 with the main parameters
* @param i2c_handle the handle of the I2C bus from HAL function, e.g. hi2c1 * @param i2c_handle the handle of the I2C bus from HAL function, e.g. hi2c1
* @param xtal_frequency either the XTAL frequency (25/27 MHz) or CLock-In * @param xtal_frequency either the XTAL frequency (25/27 MHz) or CLock-In
* from 10 MHz to 100 MHz entered in Hz * from 10 MHz to 100 MHz entered in Hz
* @param i2c_address I2C bus address of the device from datasheet typically 0x60 (or 0x61) * @param i2c_address I2C bus address of the device from datasheet typically 0x60 (or 0x61)
* @param datasize reserve an extra area of data space in bytes, access with function si5351_read_data() and si5351_write_data() * @param datasize reserve an extra area of data space in bytes, access with function si5351_read_data() and si5351_write_data()
* @return si5351_handle Pointer to the si5351 handle, NULL if error, see si5351_errno * @return si5351_handle Pointer to the si5351 handle, NULL if error, see si5351_errno
@ -423,21 +423,22 @@ int si5351_program(si5351_inst_t inst) {
*/ */
int band_select(uint32_t frequency, band_t *band) { int band_select(uint32_t frequency, band_t *band) {
static const band_t sband[] = { { "80", 3000000, 4500000, 200, 0}, static const band_t sband[] = {
{ "40", 5625000, 7500000, 120, 0}, { "80", 3000000, 4500000, 200, 0},
{ "30", 7500000,11250000, 80, 0}, { "40", 5625000, 7500000, 120, 0},
{ "20",11250000,15000000, 60, 0}, { "30", 7500000,11250000, 80, 0},
{ "15",15000000,22500000, 40, 0}, { "20",11250000,15000000, 60, 0},
{ "10",22500000,32142000, 28, 0}, { "15",15000000,22500000, 40, 0},
{ "8",32142000,45000000, 20, 0}, { "10",22500000,32142000, 28, 0},
{ "6",45000000,64285000, 14, 0}, { "8",32142000,45000000, 20, 0},
{ "4",64285000,76000000, 10, 0}, { "6",45000000,64285000, 14, 0},
{ "3",76000000,11250000, 8, 0}, { "4",64285000,76000000, 10, 0},
{ "2",11250000,15000000, 6, 0}, { "3",76000000,11250000, 8, 0},
{"180", 1500000, 2250000, 400, 0}, { "2",11250000,15000000, 6, 0},
{"120", 2250000, 3000000, 300, 0}, {"180", 1500000, 2250000, 400, 0},
{ "60", 4500000, 5625000, 160, 0}, {"120", 2250000, 3000000, 300, 0},
}; { "60", 4500000, 5625000, 160, 0},
};
for (uint32_t i = 0; i < (sizeof(sband) / sizeof(sband[0])); i++) { for (uint32_t i = 0; i < (sizeof(sband) / sizeof(sband[0])); i++) {
if (frequency > sband[i].qrg_min && frequency <= sband[i].qrg_max) { if (frequency > sband[i].qrg_min && frequency <= sband[i].qrg_max) {
@ -477,39 +478,39 @@ int calculation(uint32_t frequency, uint32_t xtal, synthesis_t *synth) {
return 0; return 0;
} }
synth->out_r_divider = 0; synth->out_r_divider = 0;
if (frequency < 81000000) { if (frequency < 81000000) {
// Valid for frequ in 0.5..112.5 MHz range 9000 // Valid for frequ in 0.5..112.5 MHz range 9000
// However an error is > 6 Hz above 81 MHz // However an error is > 6 Hz above 81 MHz
// synth->pll_multiplier = 36; // PLL runs @ 900 MHz with XTAL 25 MHz, more flexible using the formular: // synth->pll_multiplier = 36; // PLL runs @ 900 MHz with XTAL 25 MHz, more flexible using the formular:
// making an even integer multiplier with // making an even integer multiplier with
synth->pll_multiplier = (900000000 / xtal); synth->pll_multiplier = (900000000 / xtal);
synth->pll_multiplier &= ~0x01u; // make it even synth->pll_multiplier &= ~0x01u; // make it even
synth->pll_numerator = 0; synth->pll_numerator = 0;
synth->pll_denominator = 1; synth->pll_denominator = 1;
uint32_t Fpll = synth->pll_multiplier * xtal; // this was set to 900000000 uint32_t Fpll = synth->pll_multiplier * xtal; // this was set to 900000000
synth->out_multiplier = Fpll / frequency; synth->out_multiplier = Fpll / frequency;
t = (frequency >> 20) + 1; t = (frequency >> 20) + 1;
synth->out_numerator = (Fpll % frequency) / t; synth->out_numerator = (Fpll % frequency) / t;
synth->out_denominator = frequency / t; synth->out_denominator = frequency / t;
} else { } else {
// Valid for Fclk in 75..160 MHz range // Valid for Fclk in 75..160 MHz range
if(frequency >= 150000000) { if(frequency >= 150000000) {
synth->out_multiplier = 4; synth->out_multiplier = 4;
} else if (frequency >= 100000000) { } else if (frequency >= 100000000) {
synth->out_multiplier = 6; synth->out_multiplier = 6;
} else { } else {
synth->out_multiplier = 8; synth->out_multiplier = 8;
} }
synth->out_numerator = 0; synth->out_numerator = 0;
synth->out_denominator = 1; synth->out_denominator = 1;
uint32_t numerator = synth->out_multiplier*frequency; uint32_t numerator = synth->out_multiplier*frequency;
synth->pll_multiplier = numerator / xtal; synth->pll_multiplier = numerator / xtal;
t = (xtal >> 20) + 1; t = (xtal >> 20) + 1;
synth->pll_numerator = (numerator % xtal) / t; synth->pll_numerator = (numerator % xtal) / t;
synth->pll_denominator = xtal / t; synth->pll_denominator = xtal / t;
} }
return 0; return 0;
} }
/** @brief Enables the CLK output of the si5351 (after programming and setting the synthesis) /** @brief Enables the CLK output of the si5351 (after programming and setting the synthesis)
@ -579,8 +580,8 @@ int si5351_set_clk0(si5351_inst_t inst, uint32_t frequency) {
do { do {
if(!inst->programmed) { if(!inst->programmed) {
rv = si5351_program(inst); rv = si5351_program(inst);
if (!rv) if (!rv)
break; break;
} }
(void)calculation(frequency, inst->xtal_frequency, &synth); (void)calculation(frequency, inst->xtal_frequency, &synth);
rv = si5351_set_synthesis(inst, &synth, 0); rv = si5351_set_synthesis(inst, &synth, 0);
@ -615,8 +616,8 @@ int si5351_set_clk(si5351_inst_t inst, uint32_t frequency, uint8_t clk, si5351_p
do { do {
if(!inst->programmed) { if(!inst->programmed) {
rv = si5351_program(inst); rv = si5351_program(inst);
if (rv) if (rv)
break; break;
} }
(void)calculation(frequency, inst->xtal_frequency, &synth); (void)calculation(frequency, inst->xtal_frequency, &synth);
rv = si5351_set_synthesis(inst, &synth, clk); rv = si5351_set_synthesis(inst, &synth, clk);
@ -624,8 +625,16 @@ int si5351_set_clk(si5351_inst_t inst, uint32_t frequency, uint8_t clk, si5351_p
return rv; return rv;
} }
/** @brief Sets the MSNx and MSx parameter registers of the Si5351
* @param si5351_instance Given si5351 device handle
* @param synth synthesis_t struct
* @param clk The CLK ouput to drive and disable 0...CLK0, 1...CLK1, 2...CLK2, ...
* @return 0 on success
* @retval -EINVAL when given a NULL handle
* @retval -ETIMEDOUT when HAL_TIMEOUT
* @retval -EIO when HAL_ERROR
* @retval -EBUSY when HAL_BUSY
*/
int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk) { int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk) {
uint32_t MSNx_P1, MSNx_P2, MSNx_P3; uint32_t MSNx_P1, MSNx_P2, MSNx_P3;
@ -680,7 +689,7 @@ int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk) {
/* write MSNx registers dependent of SI5351_PLLA or SI5351_PLLB */ /* write MSNx registers dependent of SI5351_PLLA or SI5351_PLLB */
regaddr = (inst->clk_is_pllb & (1u << clk)) ? SI5351_MULTISYNTH_NB_PARAMETER_3_HI : SI5351_MULTISYNTH_NA_PARAMETER_3_HI; regaddr = (inst->clk_is_pllb & (1u << clk)) ? SI5351_MULTISYNTH_NB_PARAMETER_3_HI : SI5351_MULTISYNTH_NA_PARAMETER_3_HI;
rv = si5351_write(inst, regaddr, ms_data, sizeof(ms_data) / sizeof(ms_data[0])); rv = si5351_write(inst, regaddr, ms_data, sizeof(ms_data) / sizeof(ms_data[0]));
if (rv != 0) if (rv)
return rv; return rv;
/* write MSx registers dependent of CLK # */ /* write MSx registers dependent of CLK # */
ms_data[0] = (uint8_t) (MSx_P3 >> 8); ms_data[0] = (uint8_t) (MSx_P3 >> 8);
@ -693,7 +702,7 @@ int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk) {
ms_data[7] = (uint8_t) MSx_P2; ms_data[7] = (uint8_t) MSx_P2;
regaddr = SI5351_MULTISYNTH0_PARAMETER_3_HI + (uint8_t)(clk * sizeof(ms_data) / sizeof(ms_data[0])); regaddr = SI5351_MULTISYNTH0_PARAMETER_3_HI + (uint8_t)(clk * sizeof(ms_data) / sizeof(ms_data[0]));
rv = si5351_write(inst, regaddr, ms_data, sizeof(ms_data) / sizeof(ms_data[0])); rv = si5351_write(inst, regaddr, ms_data, sizeof(ms_data) / sizeof(ms_data[0]));
if (rv != 0) if (rv)
return rv; return rv;
if ((synth->out_numerator == 0) && ((synth->out_multiplier & 0x01) == 0)) if ((synth->out_numerator == 0) && ((synth->out_multiplier & 0x01) == 0))
@ -704,12 +713,12 @@ int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk) {
ms_data[0] = (uint8_t)(MSx_INT << 6 | MSx_SRC << 5 | SI5351_CLK_SRC_MS0 | SI5351_CLK_8_MA); //SI5351_CLK_6_MA; //SI5351_CLK_4_MA; ms_data[0] = (uint8_t)(MSx_INT << 6 | MSx_SRC << 5 | SI5351_CLK_SRC_MS0 | SI5351_CLK_8_MA); //SI5351_CLK_6_MA; //SI5351_CLK_4_MA;
regaddr = SI5351_CLK0_CONTROL + clk; regaddr = SI5351_CLK0_CONTROL + clk;
rv = si5351_write(inst, regaddr, ms_data, 1); rv = si5351_write(inst, regaddr, ms_data, 1);
if (rv!=0) if (rv)
return rv; return rv;
ms_data[0] = SI5351_PLL_RESET_VALUE; ms_data[0] = SI5351_PLL_RESET_VALUE;
rv = si5351_write(inst, SI5351_PLL_RESET, ms_data, 1); rv = si5351_write(inst, SI5351_PLL_RESET, ms_data, 1);
if (rv != 0) if (rv)
return rv; return rv;
#if AUTOMATICALLY_ENABLE_OUTPUT #if AUTOMATICALLY_ENABLE_OUTPUT
@ -719,6 +728,12 @@ int si5351_set_synthesis(si5351_inst_t inst, synthesis_t *synth, uint8_t clk) {
return rv; return rv;
} }
#if SI5351_DEBUG
/** @brief With this function, you can read the debug message for test purposes
* @param si5351_instance Given si5351 device handle
* @return * char as message for printing
* @retval NULL when not found
*/
char * si5351_read_debug_msg(si5351_inst_t inst) { char * si5351_read_debug_msg(si5351_inst_t inst) {
if (!inst && !(inst=first_handle)) if (!inst && !(inst=first_handle))
@ -746,7 +761,7 @@ int si5351_read_data(si5351_inst_t inst, void * data) {
memcpy(data, inst->data, inst->datasize); memcpy(data, inst->data, inst->datasize);
return (int)inst->datasize; return (int)inst->datasize;
} }
#endif
/*! /*!
* @brief Output the value in binary representation and in groups of * @brief Output the value in binary representation and in groups of
@ -779,6 +794,14 @@ int __snprintb(char *buf, size_t n, void *value, size_t size)
return cx; return cx;
} }
/** @brief Function to read any register with binary and hex representation
* @param si5351_instance Given si5351 device handle
* @param buffer for printing typically 33 bytes char
* @param size of the buffer for printing typically 33 bytes
* @param register address
* @return * char as message for printing
* @retval NULL when not found
*/
char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize, uint8_t regaddr) { char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize, uint8_t regaddr) {
uint8_t data; uint8_t data;

View File

@ -21,7 +21,6 @@
#include "main.h" #include "main.h"
#include "stm32l4xx_it.h" #include "stm32l4xx_it.h"
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
#include <stdio.h>
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
/* USER CODE END Includes */ /* USER CODE END Includes */

View File

@ -7,8 +7,11 @@ FREERTOS.configTOTAL_HEAP_SIZE=30000
FREERTOS.configUSE_NEWLIB_REENTRANT=1 FREERTOS.configUSE_NEWLIB_REENTRANT=1
File.Version=6 File.Version=6
GPIO.groupedBy=Group By Peripherals GPIO.groupedBy=Group By Peripherals
I2C1.IPParameters=Timing I2C1.I2C_Fall_Time=10
I2C1.Timing=0x00505B89 I2C1.I2C_Rise_Time=10
I2C1.I2C_Speed_Mode=I2C_Fast
I2C1.IPParameters=Timing,I2C_Speed_Mode,I2C_Rise_Time,I2C_Fall_Time
I2C1.Timing=0x00000001
KeepUserPlacement=false KeepUserPlacement=false
LPUART1.AutoBaudRateEnableParam=UART_ADVFEATURE_AUTOBAUDRATE_DISABLE LPUART1.AutoBaudRateEnableParam=UART_ADVFEATURE_AUTOBAUDRATE_DISABLE
LPUART1.BaudRate=115200 LPUART1.BaudRate=115200
@ -37,32 +40,33 @@ Mcu.IP6=SYS
Mcu.IPNb=7 Mcu.IPNb=7
Mcu.Name=STM32L4A6ZGTx Mcu.Name=STM32L4A6ZGTx
Mcu.Package=LQFP144 Mcu.Package=LQFP144
Mcu.Pin0=PC14-OSC32_IN (PC14) Mcu.Pin0=PC13
Mcu.Pin1=PC15-OSC32_OUT (PC15) Mcu.Pin1=PC14-OSC32_IN (PC14)
Mcu.Pin10=PA8 Mcu.Pin10=PC7
Mcu.Pin11=PA9 Mcu.Pin11=PA8
Mcu.Pin12=PA10 Mcu.Pin12=PA9
Mcu.Pin13=PA11 Mcu.Pin13=PA10
Mcu.Pin14=PA12 Mcu.Pin14=PA11
Mcu.Pin15=PA13 (JTMS/SWDIO) Mcu.Pin15=PA12
Mcu.Pin16=PA14 (JTCK/SWCLK) Mcu.Pin16=PA13 (JTMS/SWDIO)
Mcu.Pin17=PB3 (JTDO/TRACESWO) Mcu.Pin17=PA14 (JTCK/SWCLK)
Mcu.Pin18=PB7 Mcu.Pin18=PB3 (JTDO/TRACESWO)
Mcu.Pin19=PB8 Mcu.Pin19=PB7
Mcu.Pin2=PH1-OSC_OUT (PH1) Mcu.Pin2=PC15-OSC32_OUT (PC15)
Mcu.Pin20=PB9 Mcu.Pin20=PB8
Mcu.Pin21=VP_FREERTOS_VS_CMSIS_V2 Mcu.Pin21=PB9
Mcu.Pin22=VP_RTC_VS_RTC_Activate Mcu.Pin22=VP_FREERTOS_VS_CMSIS_V2
Mcu.Pin23=VP_RTC_VS_RTC_Calendar Mcu.Pin23=VP_RTC_VS_RTC_Activate
Mcu.Pin24=VP_SYS_VS_tim6 Mcu.Pin24=VP_RTC_VS_RTC_Calendar
Mcu.Pin3=PA2 Mcu.Pin25=VP_SYS_VS_tim6
Mcu.Pin4=PB14 Mcu.Pin3=PH1-OSC_OUT (PH1)
Mcu.Pin5=PG5 Mcu.Pin4=PA2
Mcu.Pin6=PG6 Mcu.Pin5=PB14
Mcu.Pin7=PG7 Mcu.Pin6=PG5
Mcu.Pin8=PG8 Mcu.Pin7=PG6
Mcu.Pin9=PC7 Mcu.Pin8=PG7
Mcu.PinsNb=25 Mcu.Pin9=PG8
Mcu.PinsNb=26
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32L4A6ZGTx Mcu.UserName=STM32L4A6ZGTx
@ -140,6 +144,11 @@ PB9.GPIO_Pu=GPIO_PULLUP
PB9.Locked=true PB9.Locked=true
PB9.Mode=I2C PB9.Mode=I2C
PB9.Signal=I2C1_SDA PB9.Signal=I2C1_SDA
PC13.GPIOParameters=GPIO_PuPd,GPIO_Label
PC13.GPIO_Label=B1
PC13.GPIO_PuPd=GPIO_PULLDOWN
PC13.Locked=true
PC13.Signal=GPIO_Input
PC14-OSC32_IN\ (PC14).Locked=true PC14-OSC32_IN\ (PC14).Locked=true
PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator
PC14-OSC32_IN\ (PC14).Signal=RCC_OSC32_IN PC14-OSC32_IN\ (PC14).Signal=RCC_OSC32_IN
@ -150,6 +159,44 @@ PC7.GPIOParameters=GPIO_Label
PC7.GPIO_Label=LD1 [Green] PC7.GPIO_Label=LD1 [Green]
PC7.Locked=true PC7.Locked=true
PC7.Signal=GPIO_Output PC7.Signal=GPIO_Output
PCC.Checker=true
PCC.Line=STM32L4x6
PCC.MCU=STM32L4A6ZGTx
PCC.PartNumber=STM32L4A6ZGTx
PCC.Seq0=2
PCC.Seq0.Step0.Average_Current=2.12 mA
PCC.Seq0.Step0.CPU_Frequency=16 MHz
PCC.Seq0.Step0.Category=In DS Table
PCC.Seq0.Step0.DMIPS=20.0
PCC.Seq0.Step0.Duration=0.1 ms
PCC.Seq0.Step0.Frequency=16 MHz
PCC.Seq0.Step0.Memory=SRAM2
PCC.Seq0.Step0.Mode=RUN
PCC.Seq0.Step0.Oscillator=HSE BYP Flash-PowerDown
PCC.Seq0.Step0.Peripherals=
PCC.Seq0.Step0.TaMax=104.8
PCC.Seq0.Step0.User's_Consumption=0 mA
PCC.Seq0.Step0.Vcore=Range1-High
PCC.Seq0.Step0.Vdd=3.0
PCC.Seq0.Step0.Voltage_Source=Battery
PCC.Seq0.Step1.Average_Current=131 \u00B5A
PCC.Seq0.Step1.CPU_Frequency=32.768 kHz
PCC.Seq0.Step1.Category=In DS Table
PCC.Seq0.Step1.DMIPS=0.0
PCC.Seq0.Step1.Duration=0.9 ms
PCC.Seq0.Step1.Frequency=32.768 kHz
PCC.Seq0.Step1.Memory=n/a
PCC.Seq0.Step1.Mode=STOP0
PCC.Seq0.Step1.Oscillator=LSE BYP Flash-PowerDown
PCC.Seq0.Step1.Peripherals=
PCC.Seq0.Step1.TaMax=104.99
PCC.Seq0.Step1.User's_Consumption=0 mA
PCC.Seq0.Step1.Vcore=NoRange
PCC.Seq0.Step1.Vdd=3.0
PCC.Seq0.Step1.Voltage_Source=Battery
PCC.Series=STM32L4
PCC.Temperature=25
PCC.Vdd=3.0
PG5.GPIOParameters=GPIO_Label PG5.GPIOParameters=GPIO_Label
PG5.GPIO_Label=USB_OverCurrent [STMPS2151STR_FAULT] PG5.GPIO_Label=USB_OverCurrent [STMPS2151STR_FAULT]
PG5.Locked=true PG5.Locked=true
@ -202,32 +249,32 @@ ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_RTC_Init-RTC-false-HAL-true ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_RTC_Init-RTC-false-HAL-true
RCC.ADCFreq_Value=48000000 RCC.ADCFreq_Value=48000000
RCC.AHBFreq_Value=47333333.333333336 RCC.AHBCLKDivider=RCC_SYSCLK_DIV8
RCC.AHBFreq_Value=5916666.666666667
RCC.APB1CLKDivider=RCC_HCLK_DIV2 RCC.APB1CLKDivider=RCC_HCLK_DIV2
RCC.APB1Freq_Value=23666666.666666668 RCC.APB1Freq_Value=2958333.3333333335
RCC.APB1TimFreq_Value=47333333.333333336 RCC.APB1TimFreq_Value=5916666.666666667
RCC.APB2Freq_Value=47333333.333333336 RCC.APB2CLKDivider=RCC_HCLK_DIV4
RCC.APB2TimFreq_Value=47333333.333333336 RCC.APB2Freq_Value=1479166.6666666667
RCC.CortexFreq_Value=47333333.333333336 RCC.APB2TimFreq_Value=2958333.3333333335
RCC.DFSDMFreq_Value=23666666.666666668 RCC.CortexFreq_Value=5916666.666666667
RCC.FCLKCortexFreq_Value=47333333.333333336 RCC.DFSDMFreq_Value=2958333.3333333335
RCC.FCLKCortexFreq_Value=5916666.666666667
RCC.FamilyName=M RCC.FamilyName=M
RCC.HCLKFreq_Value=47333333.333333336 RCC.HCLKFreq_Value=5916666.666666667
RCC.HSE_VALUE=8000000 RCC.HSE_VALUE=8000000
RCC.HSI48_VALUE=48000000 RCC.HSI48_VALUE=48000000
RCC.HSI_VALUE=16000000 RCC.HSI_VALUE=16000000
RCC.I2C1Freq_Value=23666666.666666668 RCC.I2C1Freq_Value=2958333.3333333335
RCC.I2C2Freq_Value=23666666.666666668 RCC.I2C2Freq_Value=2958333.3333333335
RCC.I2C3Freq_Value=23666666.666666668 RCC.I2C3Freq_Value=2958333.3333333335
RCC.I2C4Freq_Value=23666666.666666668 RCC.I2C4Freq_Value=2958333.3333333335
RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,DFSDMFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,LCDFreq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_Drive_Capability,LSE_Timout,LSI_VALUE,MCO1PinFreq_Value,MSI_VALUE,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLR,PLLRCLKFreq_Value,PLLSAI1N,PLLSAI1PoutputFreq_Value,PLLSAI1QoutputFreq_Value,PLLSAI1RoutputFreq_Value,PLLSAI2PoutputFreq_Value,PLLSAI2RoutputFreq_Value,PWRFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMCFreq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAI1OutputFreq_Value,VCOSAI2OutputFreq_Value RCC.IPParameters=ADCFreq_Value,AHBCLKDivider,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,DFSDMFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,LCDFreq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSI_VALUE,MCO1PinFreq_Value,MSI_VALUE,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLR,PLLRCLKFreq_Value,PLLSAI1N,PLLSAI1PoutputFreq_Value,PLLSAI1QoutputFreq_Value,PLLSAI1RoutputFreq_Value,PLLSAI2PoutputFreq_Value,PLLSAI2RoutputFreq_Value,PWRFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMCFreq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAI1OutputFreq_Value,VCOSAI2OutputFreq_Value
RCC.LCDFreq_Value=32768 RCC.LCDFreq_Value=32768
RCC.LPTIM1Freq_Value=23666666.666666668 RCC.LPTIM1Freq_Value=2958333.3333333335
RCC.LPTIM2Freq_Value=23666666.666666668 RCC.LPTIM2Freq_Value=2958333.3333333335
RCC.LPUART1Freq_Value=23666666.666666668 RCC.LPUART1Freq_Value=2958333.3333333335
RCC.LSCOPinFreq_Value=32000 RCC.LSCOPinFreq_Value=32000
RCC.LSE_Drive_Capability=RCC_LSEDRIVE_HIGH
RCC.LSE_Timout=50000
RCC.LSI_VALUE=32000 RCC.LSI_VALUE=32000
RCC.MCO1PinFreq_Value=47333333.333333336 RCC.MCO1PinFreq_Value=47333333.333333336
RCC.MSI_VALUE=4000000 RCC.MSI_VALUE=4000000
@ -249,14 +296,14 @@ RCC.RTCFreq_Value=32768
RCC.SAI1Freq_Value=48000000 RCC.SAI1Freq_Value=48000000
RCC.SAI2Freq_Value=48000000 RCC.SAI2Freq_Value=48000000
RCC.SDMMCFreq_Value=48000000 RCC.SDMMCFreq_Value=48000000
RCC.SWPMI1Freq_Value=23666666.666666668 RCC.SWPMI1Freq_Value=2958333.3333333335
RCC.SYSCLKFreq_VALUE=47333333.333333336 RCC.SYSCLKFreq_VALUE=47333333.333333336
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.UART4Freq_Value=23666666.666666668 RCC.UART4Freq_Value=2958333.3333333335
RCC.UART5Freq_Value=23666666.666666668 RCC.UART5Freq_Value=2958333.3333333335
RCC.USART1Freq_Value=47333333.333333336 RCC.USART1Freq_Value=1479166.6666666667
RCC.USART2Freq_Value=23666666.666666668 RCC.USART2Freq_Value=2958333.3333333335
RCC.USART3Freq_Value=23666666.666666668 RCC.USART3Freq_Value=2958333.3333333335
RCC.USBFreq_Value=48000000 RCC.USBFreq_Value=48000000
RCC.VCOInputFreq_Value=4000000 RCC.VCOInputFreq_Value=4000000
RCC.VCOOutputFreq_Value=284000000 RCC.VCOOutputFreq_Value=284000000
@ -279,4 +326,4 @@ VP_SYS_VS_tim6.Mode=TIM6
VP_SYS_VS_tim6.Signal=SYS_VS_tim6 VP_SYS_VS_tim6.Signal=SYS_VS_tim6
board=NUCLEO-L4A6ZG board=NUCLEO-L4A6ZG
boardIOC=true boardIOC=true
isbadioc=false isbadioc=true