testing 2nd instance of si5351 driver
This commit is contained in:
404
Core/Src/main.c
404
Core/Src/main.c
@ -46,6 +46,8 @@
|
||||
|
||||
UART_HandleTypeDef hlpuart1;
|
||||
|
||||
RTC_HandleTypeDef hrtc;
|
||||
|
||||
PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
|
||||
/* Definitions for defaultTask */
|
||||
@ -62,12 +64,29 @@ const osThreadAttr_t terminalTask_attributes = {
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityBelowNormal,
|
||||
};
|
||||
/* Definitions for idTask */
|
||||
osThreadId_t idTaskHandle;
|
||||
const osThreadAttr_t idTask_attributes = {
|
||||
.name = "idTask",
|
||||
/* Definitions for morseTask */
|
||||
osThreadId_t morseTaskHandle;
|
||||
const osThreadAttr_t morseTask_attributes = {
|
||||
.name = "morseTask",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityLow,
|
||||
.priority = (osPriority_t) osPriorityNormal,
|
||||
};
|
||||
/* Definitions for clk2Task */
|
||||
osThreadId_t clk2TaskHandle;
|
||||
const osThreadAttr_t clk2Task_attributes = {
|
||||
.name = "clk2Task",
|
||||
.stack_size = 128 * 4,
|
||||
.priority = (osPriority_t) osPriorityHigh,
|
||||
};
|
||||
/* Definitions for morseQueue */
|
||||
osMessageQueueId_t morseQueueHandle;
|
||||
const osMessageQueueAttr_t morseQueue_attributes = {
|
||||
.name = "morseQueue"
|
||||
};
|
||||
/* Definitions for data_access */
|
||||
osSemaphoreId_t data_accessHandle;
|
||||
const osSemaphoreAttr_t data_access_attributes = {
|
||||
.name = "data_access"
|
||||
};
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
@ -79,9 +98,11 @@ static void MX_GPIO_Init(void);
|
||||
static void MX_LPUART1_UART_Init(void);
|
||||
static void MX_USB_OTG_FS_PCD_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
static void MX_RTC_Init(void);
|
||||
void StartDefaultTask(void *argument);
|
||||
void start_terminal_task(void *argument);
|
||||
void start_id_task(void *argument);
|
||||
void start_morse_task(void *argument);
|
||||
void start_clk2_task(void *argument);
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
// redirect the output of the printf function to the USART print function
|
||||
@ -125,16 +146,20 @@ int main(void)
|
||||
MX_LPUART1_UART_Init();
|
||||
MX_USB_OTG_FS_PCD_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_RTC_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
si5351_inst_t instance_si5351[3] = {0};
|
||||
si5351_inst_t si5351_inst;
|
||||
|
||||
// 1st SI5351 chip and with an A0 = 0:
|
||||
instance_si5351[0] = si5351_init(&hi2c1, 27000000, 0x61);
|
||||
/*instance_si5351[0] = si5351_init(&hi2c1, 27000000, 0x61, 0);*/
|
||||
// 2nd SI5351 chip on the same I2C bus "hi2c1" but address line A0 = 1
|
||||
instance_si5351[1] = si5351_init(&hi2c1, 27000000, 0x60);
|
||||
instance_si5351[1] = si5351_init(&hi2c1, 25000000, 0x60, 3 * sizeof(uint32_t));
|
||||
// 3rd SI5351 chip on another IC2 bus with handle "hi2c2" *\/
|
||||
instance_si5351[2] = si5351_init(&hi2c1, 25000000, 0x60);
|
||||
instance_si5351[2] = si5351_init(&hi2c1, 25000000, 0x60, 0);
|
||||
|
||||
si5351_inst = instance_si5351[1];
|
||||
|
||||
for (int i=0; i<3 ;i++) {
|
||||
int ready;
|
||||
@ -149,13 +174,44 @@ int main(void)
|
||||
puts(si5351_read_register_debug(instance_si5351[1], buf, sizeof(buf), i));
|
||||
}
|
||||
|
||||
status = si5351_program(instance_si5351[1]);
|
||||
// status = si5351_program(instance_si5351[1]);
|
||||
printf("Device #1 gets status %d\n", status);
|
||||
printf("Debug:\n%s", si5351_read_debug_msg(instance_si5351[1]));
|
||||
|
||||
//si5351_set_clk0(instance_si5351[1], 3579545);
|
||||
// si5351_set_clk0(instance_si5351[1], 3580000);
|
||||
// si5351_set_clk0(instance_si5351[1], 4000000);
|
||||
si5351_set_clk0(instance_si5351[1], 3510000);
|
||||
si5351_enable_output(instance_si5351[1],0);
|
||||
HAL_Delay(1000);
|
||||
si5351_set_clk0(instance_si5351[1], 6055000);
|
||||
si5351_enable_output(instance_si5351[1],0);
|
||||
HAL_Delay(1000);
|
||||
si5351_set_clk0(instance_si5351[1], 99900000);
|
||||
si5351_enable_output(instance_si5351[1],0);
|
||||
HAL_Delay(5000);
|
||||
si5351_set_clk0(instance_si5351[1], 144500000);
|
||||
si5351_enable_output(instance_si5351[1],0);
|
||||
HAL_Delay(10000);
|
||||
|
||||
|
||||
/* World Youth ARDF Championship Romania 2022 */
|
||||
/* 80 m . RF power 3 W, QRG MOE-MO5: 3550 MHz, MO: 3600 MHz, Antenna 8m
|
||||
* 80 m Sprint pwr 1 W, TX 1-5: MOE-MO5: 3530 MHz, S: 3550 MHz, TX 1F-5F MOE-MO5: 3570 MHz
|
||||
* MO: 3600 MHz, Antenna: 8m
|
||||
* 2 m RF power 1 W, MOE-MO5: 144.500, MO: 144.900 MHz, crossed dipole
|
||||
*/
|
||||
si5351_set_clk0(si5351_inst, 3550000);
|
||||
|
||||
si5351_set_clk(si5351_inst, 3570000, 2, SI5351_PLLB);
|
||||
si5351_enable_output(NULL,2);
|
||||
|
||||
|
||||
/*
|
||||
for (int i=2; i>=0; i--) {
|
||||
si5351_deinit(instance_si5351[i]);
|
||||
}
|
||||
*/
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Init scheduler */
|
||||
@ -165,6 +221,10 @@ int main(void)
|
||||
/* add mutexes, ... */
|
||||
/* USER CODE END RTOS_MUTEX */
|
||||
|
||||
/* Create the semaphores(s) */
|
||||
/* creation of data_access */
|
||||
data_accessHandle = osSemaphoreNew(1, 1, &data_access_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||
/* add semaphores, ... */
|
||||
/* USER CODE END RTOS_SEMAPHORES */
|
||||
@ -173,6 +233,10 @@ int main(void)
|
||||
/* start timers, add new ones, ... */
|
||||
/* USER CODE END RTOS_TIMERS */
|
||||
|
||||
/* Create the queue(s) */
|
||||
/* creation of morseQueue */
|
||||
morseQueueHandle = osMessageQueueNew (16, sizeof(uint16_t), &morseQueue_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_QUEUES */
|
||||
/* add queues, ... */
|
||||
/* USER CODE END RTOS_QUEUES */
|
||||
@ -184,8 +248,11 @@ int main(void)
|
||||
/* creation of terminalTask */
|
||||
terminalTaskHandle = osThreadNew(start_terminal_task, NULL, &terminalTask_attributes);
|
||||
|
||||
/* creation of idTask */
|
||||
// idTaskHandle = osThreadNew(start_id_task, NULL, &idTask_attributes);
|
||||
/* creation of morseTask */
|
||||
morseTaskHandle = osThreadNew(start_morse_task, (void*) si5351_inst, &morseTask_attributes);
|
||||
|
||||
/* creation of clk2Task */
|
||||
clk2TaskHandle = osThreadNew(start_clk2_task, (void*) si5351_inst, &clk2Task_attributes);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
@ -230,13 +297,15 @@ void SystemClock_Config(void)
|
||||
/** Configure LSE Drive Capability
|
||||
*/
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
||||
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_LSE
|
||||
|RCC_OSCILLATORTYPE_MSI;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
||||
RCC_OscInitStruct.MSICalibrationValue = 0;
|
||||
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
|
||||
@ -265,6 +334,7 @@ void SystemClock_Config(void)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
HAL_RCCEx_EnableLSCO(RCC_LSCOSOURCE_LSI);
|
||||
|
||||
/** Enable MSI Auto calibration
|
||||
*/
|
||||
@ -353,6 +423,70 @@ static void MX_LPUART1_UART_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RTC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_RTC_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 0 */
|
||||
|
||||
/* USER CODE END RTC_Init 0 */
|
||||
|
||||
RTC_TimeTypeDef sTime = {0};
|
||||
RTC_DateTypeDef sDate = {0};
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 1 */
|
||||
|
||||
/* USER CODE END RTC_Init 1 */
|
||||
|
||||
/** Initialize RTC Only
|
||||
*/
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
||||
hrtc.Init.AsynchPrediv = 127;
|
||||
hrtc.Init.SynchPrediv = 255;
|
||||
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||||
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
|
||||
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||||
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Check_RTC_BKUP */
|
||||
|
||||
/* USER CODE END Check_RTC_BKUP */
|
||||
|
||||
/** Initialize RTC and set the Time and Date
|
||||
*/
|
||||
sTime.Hours = 0x12;
|
||||
sTime.Minutes = 0x30;
|
||||
sTime.Seconds = 0x0;
|
||||
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
sDate.Month = RTC_MONTH_MAY;
|
||||
sDate.Date = 0x23;
|
||||
sDate.Year = 0x22;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN RTC_Init 2 */
|
||||
|
||||
/* USER CODE END RTC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_FS Initialization Function
|
||||
* @param None
|
||||
@ -429,11 +563,17 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : B1_Pin */
|
||||
GPIO_InitStruct.Pin = B1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
/*Configure GPIO pins : PC13 PC0 PC1 PC2
|
||||
PC3 PC4 PC5 PC6
|
||||
PC8 PC9 PC10 PC11
|
||||
PC12 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13|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(B1_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PF0 PF1 PF2 PF3
|
||||
PF4 PF5 PF6 PF7
|
||||
@ -453,16 +593,6 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
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
|
||||
PA4 PA5 PA6 PA7
|
||||
PA15 */
|
||||
@ -548,6 +678,91 @@ PUTCHAR_PROTOTYPE
|
||||
return ch;
|
||||
}
|
||||
|
||||
void make_di_dah(si5351_inst_t inst, uint8_t clk, unsigned int dah, uint32_t delay) {
|
||||
|
||||
/* inner function, no need to check inst */
|
||||
if(!delay)
|
||||
return;
|
||||
|
||||
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
|
||||
(void) si5351_enable_output(inst, clk);
|
||||
osDelay(dah ? 3*delay : delay); // dit: 1 unit; dah 3 units length
|
||||
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
|
||||
(void) si5351_disable_output(inst, clk);
|
||||
osDelay(delay); // one unit of inter character space (gap b/w dits and dahs within a character)
|
||||
}
|
||||
|
||||
|
||||
void morse(si5351_inst_t inst, uint8_t clk, char * s) {
|
||||
|
||||
const uint8_t mcode[] = {0x0d,0x57,0x77,0x17,0x01,0x75,0x1f,0x55,0x05,0xfd,
|
||||
0x37,0x5d,0x0f,0x07,0x3f,0x7d,0xdf,0x1d,0x15,0x03,
|
||||
0x35,0xd5,0x3d,0xd7,0xf7,0x5f,
|
||||
0xf0,0xe0,0xc0,0x80,0x00,0x08,0x18,0x38,0x78,0xF8,
|
||||
0xAA};
|
||||
uint32_t delay[3];
|
||||
uint8_t ch;
|
||||
if(clk >= 3)
|
||||
return;
|
||||
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
(void) si5351_read_data(inst, delay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
|
||||
while ((ch = *s++)) {
|
||||
/* ascii code: numbers b/w 0x30 - 0x39 chars b/w 0x41 - 0x5A and 0x61 - 0x7A */
|
||||
if ((ch > 0x40 && ch < 0x5B) || (ch > 0x60 && ch < 0x7A)) {
|
||||
ch &= 0xDF; // make uppercase
|
||||
ch -= 0x41; // index 0 for 'A'
|
||||
} else if (ch > 0x2F && ch < 0x3A) {
|
||||
ch -= 49-26;
|
||||
}
|
||||
|
||||
if (ch != 0x20 && ch < sizeof(mcode)) { //when space add an additional pause (do nothing)
|
||||
|
||||
switch(ch) {
|
||||
case '.': ch = 0x37;
|
||||
break;
|
||||
default:
|
||||
ch = mcode[ch]; //from the given array morse code
|
||||
}
|
||||
if (ch & 0x01) { // character coding
|
||||
for (int i=4; i>0; i--) {
|
||||
switch ((ch & 0x03)) {
|
||||
case 0: /* the end */
|
||||
i = 0;
|
||||
break;
|
||||
case 1: /* did */
|
||||
make_di_dah(inst, clk, 0, delay[clk]);
|
||||
break;
|
||||
case 3: /* dah */
|
||||
make_di_dah(inst, clk, 1, delay[clk]);
|
||||
break;
|
||||
case 2: /* failure */
|
||||
default:
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
ch >>= 2;
|
||||
}
|
||||
} else if ((ch & 0x07) == 0) { // number coding
|
||||
ch >>= 3;
|
||||
for (int i= 5; i>0; i--) {
|
||||
make_di_dah(inst, clk, ch & 0x01, delay[clk]);
|
||||
ch >>= 1;
|
||||
}
|
||||
} else if ((ch & 0x03) == 2) { // special characters
|
||||
ch >>= 2;
|
||||
for (int i=6; i>0; i--) {
|
||||
make_di_dah(inst, clk, ch & 0x01, delay[clk]);
|
||||
ch >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
osDelay(3 * delay[clk]); //word inter character space (gap b/w the characters of a word) 3 units
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||
@ -559,17 +774,17 @@ PUTCHAR_PROTOTYPE
|
||||
/* USER CODE END Header_StartDefaultTask */
|
||||
void StartDefaultTask(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN 5 */
|
||||
/* USER CODE BEGIN 5 */
|
||||
(void) argument; //unused argument
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
// HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
|
||||
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
|
||||
osDelay(1);
|
||||
osDelay(10);
|
||||
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
|
||||
osDelay(1999);
|
||||
osDelay(1000);
|
||||
}
|
||||
/* USER CODE END 5 */
|
||||
/* USER CODE END 5 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_start_terminal_task */
|
||||
@ -581,48 +796,122 @@ void StartDefaultTask(void *argument)
|
||||
/* USER CODE END Header_start_terminal_task */
|
||||
void start_terminal_task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN start_terminal_task */
|
||||
/* USER CODE BEGIN start_terminal_task */
|
||||
(void)argument;
|
||||
|
||||
HAL_StatusTypeDef status;
|
||||
RTC_TimeTypeDef time;
|
||||
RTC_DateTypeDef date;
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
osDelay(1);
|
||||
status = HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN);
|
||||
if (status != HAL_OK)
|
||||
puts("HAL_RTC_GetTime problem...");
|
||||
status = HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN);
|
||||
printf("Date/Time: %02d%02d-%02d-%02d %02d:%02d:%02d\n", (date.Year < 22) ? 21 : 20, date.Year, date.Month, date.Date, time.Hours, time.Minutes, time.Seconds);
|
||||
osDelay(999);
|
||||
}
|
||||
/* USER CODE END start_terminal_task */
|
||||
/* USER CODE END start_terminal_task */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_start_id_task */
|
||||
/* USER CODE BEGIN Header_start_morse_task */
|
||||
/**
|
||||
* @brief Function implementing the idTask thread.
|
||||
* @brief Function implementing the morseTask thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_start_id_task */
|
||||
void start_id_task(void *argument)
|
||||
/* USER CODE END Header_start_morse_task */
|
||||
void start_morse_task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN start_id_task */
|
||||
(void)argument; //unused argument
|
||||
//uint8_t tx_buf[80];
|
||||
//int tx_buf_len;
|
||||
/* check if the SI5351 is present */
|
||||
int status = HAL_I2C_IsDeviceReady(&hi2c1, SI5351_I2C_ADDR, 3, 10 /*HAL_MAX_DELAY*/ ); // HAL_MAX_DELAY is blocking, use 10 ms
|
||||
/* USER CODE BEGIN start_morse_task */
|
||||
static const uint32_t delay = 120;
|
||||
static const uint8_t clk = 0;
|
||||
si5351_inst_t inst = argument;
|
||||
int i = 0;
|
||||
uint32_t morsedelay[3]; // words per minute ?
|
||||
|
||||
si5351_set_clk0(inst, 3550000);
|
||||
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
si5351_read_data(inst, morsedelay);
|
||||
morsedelay[clk] = delay;
|
||||
si5351_write_data(inst, morsedelay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;) {
|
||||
printf("\n" PROGRAM_ID "\n");
|
||||
printf(AUTHOR_STRING "\n");
|
||||
if (status == HAL_OK)
|
||||
printf("Si5351 device found.\n");
|
||||
else
|
||||
printf("Error: Could not detect Si5351 device.\n");
|
||||
for (;;) {
|
||||
// check clock RTC for e.g. cycle of 1 minutes TX with 4 minutes pause period
|
||||
morse(inst, 0, "MO");
|
||||
osDelay(7*morsedelay[clk]);
|
||||
if((++i % 8)==0) {
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
si5351_read_data(inst, morsedelay);
|
||||
morsedelay[clk] = delay/4;
|
||||
si5351_write_data(inst, morsedelay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
morse(inst, clk, " f0x.at1 de oe3tkt ");
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
si5351_read_data(inst, morsedelay);
|
||||
morsedelay[clk] = delay;
|
||||
si5351_write_data(inst, morsedelay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
osDelay(7*morsedelay[clk]);
|
||||
}
|
||||
}
|
||||
/* USER CODE END start_morse_task */
|
||||
}
|
||||
|
||||
osDelay(30*60);
|
||||
}
|
||||
/* USER CODE END start_id_task */
|
||||
/* USER CODE BEGIN Header_start_clk2_task */
|
||||
/**
|
||||
* @brief Function implementing the clk2Task thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_start_clk2_task */
|
||||
void start_clk2_task(void *argument)
|
||||
{
|
||||
/* USER CODE BEGIN start_clk2_task */
|
||||
static const uint32_t delay = 100;
|
||||
static const uint8_t clk =2;
|
||||
si5351_inst_t inst = argument;
|
||||
int i = 0;
|
||||
uint32_t morsedelay[3]; // words per minute ?
|
||||
|
||||
si5351_set_clk(inst, 3570000, clk, SI5351_PLLB);
|
||||
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
si5351_read_data(inst, morsedelay);
|
||||
morsedelay[clk] = delay;
|
||||
si5351_write_data(inst, morsedelay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
// check clock RTC for e.g. cycle of 1 minutes TX with 4 minutes pause period
|
||||
morse(inst, 0, "MOs");
|
||||
osDelay(7*morsedelay[clk]);
|
||||
if((++i % 8)==0) {
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
si5351_read_data(inst, morsedelay);
|
||||
morsedelay[clk] = delay/4;
|
||||
si5351_write_data(inst, morsedelay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
morse(inst, clk, " f0x.at1 de oe3tkt ");
|
||||
osSemaphoreAcquire(data_accessHandle,osWaitForever);
|
||||
si5351_read_data(inst, morsedelay);
|
||||
morsedelay[clk] = delay;
|
||||
si5351_write_data(inst, morsedelay);
|
||||
osSemaphoreRelease(data_accessHandle);
|
||||
osDelay(7*morsedelay[clk]);
|
||||
}
|
||||
}
|
||||
/* USER CODE END start_clk2_task */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM16 interrupt took place, inside
|
||||
* @note This function is called when TIM6 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
@ -633,7 +922,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM16) {
|
||||
if (htim->Instance == TIM6) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
@ -669,6 +958,7 @@ void assert_failed(uint8_t *file, uint32_t line)
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
printf("Wrong parameters value: file %s on line %d\r\n", file, line);
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -237,6 +237,61 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RTC MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hrtc: RTC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
|
||||
{
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(hrtc->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
/* USER CODE BEGIN RTC_MspInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RTC MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hrtc: RTC handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
|
||||
{
|
||||
if(hrtc->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RTC_DISABLE();
|
||||
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief PCD MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
|
@ -25,12 +25,12 @@
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim16;
|
||||
TIM_HandleTypeDef htim6;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM16 as a time base source.
|
||||
* @brief This function configures the TIM6 as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
@ -44,41 +44,41 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
uint32_t uwTimclock = 0;
|
||||
uint32_t uwPrescalerValue = 0;
|
||||
uint32_t pFLatency;
|
||||
/*Configure the TIM16 IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, TickPriority ,0);
|
||||
/*Configure the TIM6 IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0);
|
||||
|
||||
/* Enable the TIM16 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
|
||||
/* Enable the TIM6 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
|
||||
|
||||
/* Enable TIM16 clock */
|
||||
__HAL_RCC_TIM16_CLK_ENABLE();
|
||||
/* Enable TIM6 clock */
|
||||
__HAL_RCC_TIM6_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Compute TIM16 clock */
|
||||
uwTimclock = HAL_RCC_GetPCLK2Freq();
|
||||
/* Compute the prescaler value to have TIM16 counter clock equal to 1MHz */
|
||||
/* Compute TIM6 clock */
|
||||
uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
|
||||
/* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM16 */
|
||||
htim16.Instance = TIM16;
|
||||
/* Initialize TIM6 */
|
||||
htim6.Instance = TIM6;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
+ Period = [(TIM16CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
+ ClockDivision = 0
|
||||
+ Counter direction = Up
|
||||
*/
|
||||
htim16.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim16.Init.Prescaler = uwPrescalerValue;
|
||||
htim16.Init.ClockDivision = 0;
|
||||
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim6.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim6.Init.Prescaler = uwPrescalerValue;
|
||||
htim6.Init.ClockDivision = 0;
|
||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
|
||||
if(HAL_TIM_Base_Init(&htim16) == HAL_OK)
|
||||
if(HAL_TIM_Base_Init(&htim6) == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
return HAL_TIM_Base_Start_IT(&htim16);
|
||||
return HAL_TIM_Base_Start_IT(&htim6);
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
@ -87,25 +87,25 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM16 update interrupt.
|
||||
* @note Disable the tick increment by disabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM16 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim16, TIM_IT_UPDATE);
|
||||
/* Disable TIM6 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM16 update interrupt.
|
||||
* @note Enable the tick increment by Enabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM16 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim16, TIM_IT_UPDATE);
|
||||
/* Enable TIM6 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern UART_HandleTypeDef hlpuart1;
|
||||
extern TIM_HandleTypeDef htim16;
|
||||
extern TIM_HandleTypeDef htim6;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
@ -86,7 +86,8 @@ void NMI_Handler(void)
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
// printf("something went wrong -> HardFault_Handler called\n");
|
||||
return;
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
@ -161,17 +162,17 @@ void DebugMon_Handler(void)
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 update interrupt and TIM16 global interrupt.
|
||||
* @brief This function handles TIM6 global interrupt, DAC channel1 and channel2 underrun error interrupts.
|
||||
*/
|
||||
void TIM1_UP_TIM16_IRQHandler(void)
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_UP_TIM16_IRQn 0 */
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM1_UP_TIM16_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim16);
|
||||
/* USER CODE BEGIN TIM1_UP_TIM16_IRQn 1 */
|
||||
/* USER CODE END TIM6_DAC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim6);
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM1_UP_TIM16_IRQn 1 */
|
||||
/* USER CODE END TIM6_DAC_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user