moved to stm32l4a6zg-f0x.at1 folder
This commit is contained in:
174
stm32l4a6zg-f0x.at1/Core/Inc/FreeRTOSConfig.h
Normal file
174
stm32l4a6zg-f0x.at1/Core/Inc/FreeRTOSConfig.h
Normal file
@ -0,0 +1,174 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/*
|
||||
* FreeRTOS Kernel V10.3.1
|
||||
* Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Application specific definitions.
|
||||
*
|
||||
* These definitions should be adjusted for your particular hardware and
|
||||
* application requirements.
|
||||
*
|
||||
* These parameters and more are described within the 'configuration' section of the
|
||||
* FreeRTOS API documentation available on the FreeRTOS.org web site.
|
||||
*
|
||||
* See http://www.freertos.org/a00110.html
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* Section where include file can be added */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Ensure definitions are only used by the compiler, and not by the assembler. */
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
|
||||
#include <stdint.h>
|
||||
extern uint32_t SystemCoreClock;
|
||||
#endif
|
||||
#ifndef CMSIS_device_header
|
||||
#define CMSIS_device_header "stm32l4xx.h"
|
||||
#endif /* CMSIS_device_header */
|
||||
|
||||
#define configENABLE_FPU 0
|
||||
#define configENABLE_MPU 0
|
||||
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configSUPPORT_STATIC_ALLOCATION 1
|
||||
#define configSUPPORT_DYNAMIC_ALLOCATION 1
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configCPU_CLOCK_HZ ( SystemCoreClock )
|
||||
#define configTICK_RATE_HZ ((TickType_t)1000)
|
||||
#define configMAX_PRIORITIES ( 56 )
|
||||
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
|
||||
#define configTOTAL_HEAP_SIZE ((size_t)50000)
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 8
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
|
||||
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
|
||||
/* Defaults to size_t for backward compatibility, but can be changed
|
||||
if lengths will always be less than the number of bytes in a size_t. */
|
||||
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
|
||||
/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
||||
|
||||
/* Software timer definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( 2 )
|
||||
#define configTIMER_QUEUE_LENGTH 10
|
||||
#define configTIMER_TASK_STACK_DEPTH 256
|
||||
|
||||
/* The following flag must be enabled only when using newlib */
|
||||
#define configUSE_NEWLIB_REENTRANT 1
|
||||
|
||||
/* CMSIS-RTOS V2 flags */
|
||||
#define configUSE_OS2_THREAD_SUSPEND_RESUME 1
|
||||
#define configUSE_OS2_THREAD_ENUMERATE 1
|
||||
#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
|
||||
#define configUSE_OS2_THREAD_FLAGS 1
|
||||
#define configUSE_OS2_TIMER 1
|
||||
#define configUSE_OS2_MUTEX 1
|
||||
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
to exclude the API function. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 0
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
#define INCLUDE_xQueueGetMutexHolder 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||
#define INCLUDE_xTaskGetCurrentTaskHandle 1
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
|
||||
/*
|
||||
* The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used
|
||||
* by the application thus the correct define need to be enabled below
|
||||
*/
|
||||
#define USE_FreeRTOS_HEAP_4
|
||||
|
||||
/* Cortex-M specific definitions. */
|
||||
#ifdef __NVIC_PRIO_BITS
|
||||
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
|
||||
#define configPRIO_BITS __NVIC_PRIO_BITS
|
||||
#else
|
||||
#define configPRIO_BITS 4
|
||||
#endif
|
||||
|
||||
/* The lowest interrupt priority that can be used in a call to a "set priority"
|
||||
function. */
|
||||
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
|
||||
|
||||
/* The highest interrupt priority that can be used by any interrupt service
|
||||
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
|
||||
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
|
||||
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
|
||||
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
|
||||
|
||||
/* Interrupt priorities used by the kernel port layer itself. These are generic
|
||||
to all Cortex-M ports, and do not rely on any particular library functions. */
|
||||
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
|
||||
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
|
||||
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
|
||||
/* Normal assert() semantics without relying on the provision of an assert.h
|
||||
header file. */
|
||||
/* USER CODE BEGIN 1 */
|
||||
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
|
||||
standard names. */
|
||||
#define vPortSVCHandler SVC_Handler
|
||||
#define xPortPendSVHandler PendSV_Handler
|
||||
|
||||
/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */
|
||||
|
||||
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0
|
||||
|
||||
/* USER CODE BEGIN Defines */
|
||||
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
|
||||
/* USER CODE END Defines */
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
71
stm32l4a6zg-f0x.at1/Core/Inc/at1_defines.h
Normal file
71
stm32l4a6zg-f0x.at1/Core/Inc/at1_defines.h
Normal file
@ -0,0 +1,71 @@
|
||||
/******************************************************************************
|
||||
* File Name : at1_defines.h
|
||||
* Description : constants and defines for the project f0x.at1
|
||||
******************************************************************************
|
||||
* @author: Thomas Kuschel KW4NZ
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef _AT1_DEFINES_H_
|
||||
#define _AT1_DEFINES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#ifndef STR_HELPER
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#endif
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 4
|
||||
#ifdef DEBUG
|
||||
#define VERSION_DEBUG ".D"
|
||||
#else
|
||||
#define VERSION_DEBUG
|
||||
#endif
|
||||
#define PROGRAM_ID "f0x.at1 Version " STR(VERSION_MAJOR) "." STR(VERSION_MINOR) VERSION_DEBUG
|
||||
#define VERSION_STRING STR(VERSION_MAJOR) "." STR(VERION_MINOR)
|
||||
/*#define DATE __DATE__ */
|
||||
#define AUTHOR_STRING "Tom Kuschel KW4NZ"
|
||||
/* From SI5351 datasheet: */
|
||||
#define SI5351_I2C_ADDR (0x60 << 1)
|
||||
|
||||
/* #define COMPILE_YEAR (__DATE__ + 7) */
|
||||
#define DATE_COMPILE_CENTURY (20)
|
||||
#define DATE_COMPILE_YEAR (22)
|
||||
|
||||
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
|
||||
#define __AT1_ERROR_NUMBERS__
|
||||
typedef enum {
|
||||
EPERM = 1, /*!< Operation not permitted */
|
||||
EIO = 5, /*!< I/O error */
|
||||
ENOMEM = 12, /*!< Out of memory */
|
||||
EFAULT = 14, /*!< Bad address */
|
||||
EBUSY = 16, /*!< Device or resource busy */
|
||||
ENODEV = 19, /*!< No such device */
|
||||
EINVAL = 22, /*!< Invalid argument */
|
||||
EADDRINUSE = 98,/*!< Address already in use */
|
||||
ETIMEDOUT = 116,/*!< Connection timed out */
|
||||
} at1_errno_t;
|
||||
#endif
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _AT1_DEFINES_H_ */
|
37
stm32l4a6zg-f0x.at1/Core/Inc/commands.h
Normal file
37
stm32l4a6zg-f0x.at1/Core/Inc/commands.h
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file commands.h
|
||||
* @brief Header for command.c file, the command interpreter, a generic one
|
||||
******************************************************************************
|
||||
* @author: Thomas Kuschel KW4NZ
|
||||
* created 2022-06-04
|
||||
*
|
||||
******************************************************************************/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __COMMANDS_H_
|
||||
#define __COMMANDS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//struct command_ctx_s *command_inst;
|
||||
//typedef struct command_ctx_s *command_inst_t;
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
/* function prototypes */
|
||||
int do_help(char *args);
|
||||
int do_devid(char *args);
|
||||
int do_info(char *args);
|
||||
int do_sinfo(char *args);
|
||||
int do_test(/*command_inst_t inst,*/ char *args);
|
||||
int do_time(char *args);
|
||||
|
||||
int cmd_interpreter(char * cmdline);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __COMMANDS_H_ */
|
28
stm32l4a6zg-f0x.at1/Core/Inc/helper.h
Normal file
28
stm32l4a6zg-f0x.at1/Core/Inc/helper.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* helper.h
|
||||
*
|
||||
* Created on: Jul 14, 2022
|
||||
* Author: tom
|
||||
*/
|
||||
|
||||
#ifndef INC_HELPER_H_
|
||||
#define INC_HELPER_H_
|
||||
|
||||
struct _tm_ { /* compare to ctime(3) */
|
||||
uint16_t year;
|
||||
uint16_t mon;
|
||||
uint16_t day;
|
||||
uint16_t hour;
|
||||
uint16_t min;
|
||||
uint16_t sec;
|
||||
};
|
||||
|
||||
char *ltrim(char *s);
|
||||
char *rtrim(char *s);
|
||||
char *trim(char *s);
|
||||
|
||||
int strtotime (char *s, struct _tm_ *tp);
|
||||
// uint8_t dayofweek(uint8_t century, uint8_t y, uint8_t m, uint8_t d);
|
||||
|
||||
|
||||
#endif /* INC_HELPER_H_ */
|
99
stm32l4a6zg-f0x.at1/Core/Inc/main.h
Normal file
99
stm32l4a6zg-f0x.at1/Core/Inc/main.h
Normal file
@ -0,0 +1,99 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
void print_system_info(void);
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define B1_Pin GPIO_PIN_13
|
||||
#define B1_GPIO_Port GPIOC
|
||||
#define LD3_Pin GPIO_PIN_14
|
||||
#define LD3_GPIO_Port GPIOB
|
||||
#define USB_OverCurrent_Pin GPIO_PIN_5
|
||||
#define USB_OverCurrent_GPIO_Port GPIOG
|
||||
#define STLK_RX_Pin GPIO_PIN_7
|
||||
#define STLK_RX_GPIO_Port GPIOG
|
||||
#define STLK_TX_Pin GPIO_PIN_8
|
||||
#define STLK_TX_GPIO_Port GPIOG
|
||||
#define LD1_Pin GPIO_PIN_7
|
||||
#define LD1_GPIO_Port GPIOC
|
||||
#define USB_SOF_Pin GPIO_PIN_8
|
||||
#define USB_SOF_GPIO_Port GPIOA
|
||||
#define USB_VBUS_Pin GPIO_PIN_9
|
||||
#define USB_VBUS_GPIO_Port GPIOA
|
||||
#define USB_ID_Pin GPIO_PIN_10
|
||||
#define USB_ID_GPIO_Port GPIOA
|
||||
#define USB_DM_Pin GPIO_PIN_11
|
||||
#define USB_DM_GPIO_Port GPIOA
|
||||
#define USB_DP_Pin GPIO_PIN_12
|
||||
#define USB_DP_GPIO_Port GPIOA
|
||||
#define TMS_Pin GPIO_PIN_13
|
||||
#define TMS_GPIO_Port GPIOA
|
||||
#define TCK_Pin GPIO_PIN_14
|
||||
#define TCK_GPIO_Port GPIOA
|
||||
#define SWO_Pin GPIO_PIN_3
|
||||
#define SWO_GPIO_Port GPIOB
|
||||
#define LD2_Pin GPIO_PIN_7
|
||||
#define LD2_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
63
stm32l4a6zg-f0x.at1/Core/Inc/ringbuf.h
Normal file
63
stm32l4a6zg-f0x.at1/Core/Inc/ringbuf.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* ringbuf.h
|
||||
*
|
||||
* Created on: Jul 12, 2022
|
||||
* Author: tom
|
||||
*/
|
||||
|
||||
#ifndef _INC_RINGBUF_H_
|
||||
#define _INC_RINGBUF_H_
|
||||
|
||||
#define RING_STATISTICS_ENABLED 1
|
||||
|
||||
#define RINGBUF_MAX_READ_LEN 80
|
||||
|
||||
typedef enum {
|
||||
RINGBUF_PARAM_NONE = 0x00,
|
||||
RINGBUF_ALLOWOVERWRITE= 0x01,
|
||||
} ringbuf_param_t;
|
||||
|
||||
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
|
||||
typedef enum {
|
||||
EPERM = 1, /*!< Operation not permitted */
|
||||
EIO = 5, /*!< I/O error */
|
||||
ENOMEM = 12, /*!< Out of memory */
|
||||
EFAULT = 14, /*!< Bad address */
|
||||
EBUSY = 16, /*!< Device or resource busy */
|
||||
ENODEV = 19, /*!< No such device */
|
||||
EINVAL = 22, /*!< Invalid argument */
|
||||
EADDRINUSE = 98,/*!< Address already in use */
|
||||
ETIMEDOUT = 116,/*!< Connection timed out */
|
||||
} ringbuf_errno_t;
|
||||
#endif
|
||||
//extern ringbuf;
|
||||
#define hring struct ringbuf *
|
||||
//receive callback typedef definition
|
||||
typedef void (*ringbuf_rcv_cb_t)(uint16_t delimiterfound, void* cb_data);
|
||||
|
||||
#if !defined min
|
||||
#define min(a,b) ((a < b)? a : b)
|
||||
#endif
|
||||
|
||||
hring ringbuf_create(size_t size, ringbuf_param_t param);
|
||||
void ringbuf_destroy(hring);
|
||||
int ringbuf_push(hring, const uint8_t *data, size_t size);
|
||||
int ringbuf_pull(hring, uint8_t *data, size_t maxsize);
|
||||
int ringbuf_clear(hring);
|
||||
int ringbuf_free(hring);
|
||||
int ringbuf_read(hring, char *str);
|
||||
int ringbuf_write(hring, char *str);
|
||||
int ringbuf_callback_register(hring, ringbuf_rcv_cb_t cb_func, void *cb_data);
|
||||
int ringbuf_set_max_read_len(hring, int max_read_len);
|
||||
int ringbuf_get_max_read_len(hring);
|
||||
int ringbuf_is_empty(hring);
|
||||
int ringbuf_dump(hring);
|
||||
|
||||
#if RING_STATISTICS_ENABLED
|
||||
int ringbuf_statistics(hring);
|
||||
int ringbuf_stat_writes(hring);
|
||||
int ringbuf_stat_reads(hring);
|
||||
int ringbuf_stat_overflow(hring);
|
||||
#endif
|
||||
|
||||
#endif /* _INC_RINGBUF_H_ */
|
15
stm32l4a6zg-f0x.at1/Core/Inc/ringbuf_test.h
Normal file
15
stm32l4a6zg-f0x.at1/Core/Inc/ringbuf_test.h
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* ringbuf_test.h
|
||||
*
|
||||
* Created on: Jul 14, 2022
|
||||
* Author: tom
|
||||
*/
|
||||
|
||||
#ifndef INC_RINGBUF_TEST_H_
|
||||
#define INC_RINGBUF_TEST_H_
|
||||
|
||||
void ringbuf_test(void);
|
||||
|
||||
|
||||
|
||||
#endif /* INC_RINGBUF_TEST_H_ */
|
149
stm32l4a6zg-f0x.at1/Core/Inc/si5351.h
Normal file
149
stm32l4a6zg-f0x.at1/Core/Inc/si5351.h
Normal file
@ -0,0 +1,149 @@
|
||||
/******************************************************************************
|
||||
* File Name : si5351.h
|
||||
* Description : STM32 library/driver for the Si5351 clock chip
|
||||
* from Skyworks Solutions, Inc. (former SiLabs)
|
||||
******************************************************************************
|
||||
* @author: Thomas Kuschel KW4NZ, created 2022-05-11
|
||||
*
|
||||
* originally written by Petr Polasek, created Feb 16, 2018
|
||||
******************************************************************************
|
||||
* DO NOT EDIT THIS FILE FOR CONFIGURATION, USE THE FOLLOWING PROCEDURE:
|
||||
*
|
||||
* Inside your main.c program or within your STM32 code:
|
||||
* Include this header to the the main.c: #include "si5351.h"
|
||||
* You've to initialize the I2C functionality first (e.g. with STM32CubeIDE)
|
||||
* Afterwards, when there is a handle like "I2C_HandleTypeDef hi2c1;",
|
||||
* you simply initialize this si5351 library in your main.c ,
|
||||
* just after the MX_I2C1_Init();
|
||||
* so between the USER CODE like using the given i2c handle "hi2c1" with default values:
|
||||
*
|
||||
* /\* USER CODE BEGIN 2 *\/
|
||||
*
|
||||
* si5351_inst_t si5351_inst;
|
||||
* si5351_initialize(&hi2c1);
|
||||
*
|
||||
* /\* USER CODE END 2 *\/
|
||||
*
|
||||
* The 7-bit device (slave) address of the Si5351 consist of a 6-bit fixed
|
||||
* address plus a user selectable LSB bit as shown in Figure 6 of the datasheet.
|
||||
* The LSB bit is selectable as 0 or 1 using the optional A0 pin which is useful
|
||||
* for applications that require more than one Si5351 on a single I2C bus.
|
||||
* Only the Si5351A 20-QFN and Si5351A 16-QFN have the A0 LSB pin option.
|
||||
* If a part does not have the A0 pin, the default address is 0x60 with
|
||||
* the A0 bit set to 0.
|
||||
*
|
||||
* So additionally you may drive more then one Si5351 at the same or
|
||||
* another I2C bus when calling the init function with the given
|
||||
* I2C bus address (default: 0x60)
|
||||
* ( - internally this I2C address is shifted to the left
|
||||
* for the proper usage of the I2C HAL driver i.e. it becomes 0xC0 )
|
||||
*
|
||||
* Example:
|
||||
* /\* Define handlers for the sum of three SI5351 clock generators: *\/
|
||||
* si5351_HandleTypeDef hsi5351[3];
|
||||
*
|
||||
* /\* 1st SI5351 chip and with an A0 = 0: *\/
|
||||
* hsi5351[0] = si5351_init(&hi2c1, 0x60, 25000000);
|
||||
* /\* 2nd SI5351 chip on the same I2C bus "hi2c1" but address line A0 = 1 *\/
|
||||
* hsi5351[1] = si5351_init(&hi2c1, 0x61, 27000000);
|
||||
* /\* 3rd SI5351 chip on another IC2 bus with handle "hi2c2" *\/
|
||||
* hsi5351[2] = si5351_init(&hi2c2, 0x60, 25000000);
|
||||
*
|
||||
* PROs:
|
||||
* The library is preemptive and can be used within an operating system.
|
||||
* All structures and used variables are dynamically allocated.
|
||||
* CONs:
|
||||
* Not fully tested.
|
||||
* Tested with FreeRTOS and with 2 I2C bus systems.
|
||||
*
|
||||
* CHANGES:
|
||||
* - Removed several defines, enums, etc. from the header file, b/c we do not
|
||||
* want to export them to other programs
|
||||
******************************************************************************/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __SI5351_H__
|
||||
#define __SI5351_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* #include <errno.h> could also be included */
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/*!< Si5351 instance typedef -- handle as pointer */
|
||||
typedef struct __SI5351_HandleTypeDef *si5351_inst_t;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/** @enum errno_t Error Number Constants, @TODO you can also include <errno.h>
|
||||
*/
|
||||
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
|
||||
typedef enum {
|
||||
EPERM = 1, /*!< Operation not permitted */
|
||||
EIO = 5, /*!< I/O error */
|
||||
ENOMEM = 12, /*!< Out of memory */
|
||||
EFAULT = 14, /*!< Bad address */
|
||||
EBUSY = 16, /*!< Device or resource busy */
|
||||
ENODEV = 19, /*!< No such device */
|
||||
EINVAL = 22, /*!< Invalid argument */
|
||||
EADDRINUSE = 98,/*!< Address already in use */
|
||||
ETIMEDOUT = 116 /*!< Connection timed out */
|
||||
} si5351_errno_t;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SI5351_PLLA = 0,
|
||||
SI5351_PLLB
|
||||
}si5351_pll_t;
|
||||
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
#define __SI5351__ 1
|
||||
#define __SI5351_MINOR__ 2
|
||||
#define __SI5351_PATCHLEVEL__ 0
|
||||
|
||||
#define SI5351_VERSION (__SI5351__ * 10000 \
|
||||
+ __SI5351_MINOR__ * 100 \
|
||||
+ __SI5351_PATCHLEVEL__)
|
||||
|
||||
#ifndef SI5351_DEFAULTS
|
||||
#define SI5351_DEFAULTS 1
|
||||
#define SI5351_I2C_ADDR_DEFAULT 0x60
|
||||
#define SI5351_XTAL_DEFAULT 25000000u /* default xtal frequency in [Hz] */
|
||||
#define SI5351_NUMBER_OF_OUTPUTS 8
|
||||
#endif
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
#if SI5351_DEFAULTS
|
||||
si5351_inst_t si5351_initialize(void * i2c_handle);
|
||||
int si5351_deinitialize(void);
|
||||
#endif
|
||||
si5351_inst_t si5351_init(void * i2c_handle, uint8_t i2c_address, uint32_t xtal_frequency);
|
||||
int si5351_deinit(si5351_inst_t si5351_handle);
|
||||
int si5351_i2c_ready(si5351_inst_t inst);
|
||||
int si5351_enable_output(si5351_inst_t inst, uint8_t clk);
|
||||
int si5351_disable_output(si5351_inst_t inst, uint8_t clk);
|
||||
int si5351_set_clk0(si5351_inst_t inst, uint32_t frequency);
|
||||
int si5351_set_clk(si5351_inst_t inst, uint8_t clk, uint32_t frequency, si5351_pll_t pll);
|
||||
|
||||
char * si5351_read_debug_msg(si5351_inst_t inst);
|
||||
char * si5351_read_register_debug(si5351_inst_t inst, char *buf, size_t bufsize, uint8_t regaddr);
|
||||
|
||||
/* some functions for getting information */
|
||||
int si5351_get_instance(si5351_inst_t *inst);
|
||||
int si5351_get_i2c_address(si5351_inst_t inst);
|
||||
void* si5351_get_i2c_handle(si5351_inst_t inst);
|
||||
|
||||
/* under development */
|
||||
int si5351_set_clk_phase(si5351_inst_t inst, uint8_t clk, uint32_t frequency, double phase, si5351_pll_t pll);
|
||||
int si5351_set_phase(si5351_inst_t inst, uint8_t clk, uint8_t phase);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SI5351_H__ */
|
1174
stm32l4a6zg-f0x.at1/Core/Inc/si5351_reg.h
Normal file
1174
stm32l4a6zg-f0x.at1/Core/Inc/si5351_reg.h
Normal file
File diff suppressed because it is too large
Load Diff
482
stm32l4a6zg-f0x.at1/Core/Inc/stm32l4xx_hal_conf.h
Normal file
482
stm32l4a6zg-f0x.at1/Core/Inc/stm32l4xx_hal_conf.h
Normal file
@ -0,0 +1,482 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration template file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to stm32l4xx_hal_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef STM32L4xx_HAL_CONF_H
|
||||
#define STM32L4xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
/*#define HAL_ADC_MODULE_ENABLED */
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
/*#define HAL_CAN_MODULE_ENABLED */
|
||||
/*#define HAL_COMP_MODULE_ENABLED */
|
||||
/*#define HAL_CRC_MODULE_ENABLED */
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
/*#define HAL_DAC_MODULE_ENABLED */
|
||||
/*#define HAL_DCMI_MODULE_ENABLED */
|
||||
/*#define HAL_DMA2D_MODULE_ENABLED */
|
||||
/*#define HAL_DFSDM_MODULE_ENABLED */
|
||||
/*#define HAL_DSI_MODULE_ENABLED */
|
||||
/*#define HAL_FIREWALL_MODULE_ENABLED */
|
||||
/*#define HAL_GFXMMU_MODULE_ENABLED */
|
||||
/*#define HAL_HCD_MODULE_ENABLED */
|
||||
/*#define HAL_HASH_MODULE_ENABLED */
|
||||
/*#define HAL_I2S_MODULE_ENABLED */
|
||||
/*#define HAL_IRDA_MODULE_ENABLED */
|
||||
/*#define HAL_IWDG_MODULE_ENABLED */
|
||||
/*#define HAL_LTDC_MODULE_ENABLED */
|
||||
/*#define HAL_LCD_MODULE_ENABLED */
|
||||
/*#define HAL_LPTIM_MODULE_ENABLED */
|
||||
/*#define HAL_MMC_MODULE_ENABLED */
|
||||
/*#define HAL_NAND_MODULE_ENABLED */
|
||||
/*#define HAL_NOR_MODULE_ENABLED */
|
||||
/*#define HAL_OPAMP_MODULE_ENABLED */
|
||||
/*#define HAL_OSPI_MODULE_ENABLED */
|
||||
/*#define HAL_OSPI_MODULE_ENABLED */
|
||||
/*#define HAL_PCD_MODULE_ENABLED */
|
||||
/*#define HAL_PKA_MODULE_ENABLED */
|
||||
/*#define HAL_QSPI_MODULE_ENABLED */
|
||||
/*#define HAL_QSPI_MODULE_ENABLED */
|
||||
/*#define HAL_RNG_MODULE_ENABLED */
|
||||
#define HAL_RTC_MODULE_ENABLED
|
||||
/*#define HAL_SAI_MODULE_ENABLED */
|
||||
/*#define HAL_SD_MODULE_ENABLED */
|
||||
/*#define HAL_SMBUS_MODULE_ENABLED */
|
||||
/*#define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/*#define HAL_SPI_MODULE_ENABLED */
|
||||
/*#define HAL_SRAM_MODULE_ENABLED */
|
||||
/*#define HAL_SWPMI_MODULE_ENABLED */
|
||||
#define HAL_TIM_MODULE_ENABLED
|
||||
/*#define HAL_TSC_MODULE_ENABLED */
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
/*#define HAL_USART_MODULE_ENABLED */
|
||||
/*#define HAL_WWDG_MODULE_ENABLED */
|
||||
/*#define HAL_EXTI_MODULE_ENABLED */
|
||||
/*#define HAL_PSSI_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_I2C_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal Multiple Speed oscillator (MSI) default value.
|
||||
* This value is the default MSI range value after Reset.
|
||||
*/
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG.
|
||||
* This internal oscillator is mainly dedicated to provide a high precision clock to
|
||||
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
|
||||
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
|
||||
* which is subject to manufacturing process variations.
|
||||
*/
|
||||
#if !defined (HSI48_VALUE)
|
||||
#define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
|
||||
The real value my vary depending on manufacturing process variations.*/
|
||||
#endif /* HSI48_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI1 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI1_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI1_CLOCK_VALUE 2097000U /*!< Value of the SAI1 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI2 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI2_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI2_CLOCK_VALUE 2097000U /*!< Value of the SAI2 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 0U
|
||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||
#define DATA_CACHE_ENABLE 1U
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Register callback feature configuration ############### */
|
||||
/**
|
||||
* @brief Set below the peripheral configuration to "1U" to add the support
|
||||
* of HAL callback registration/deregistration feature for the HAL
|
||||
* driver(s). This allows user application to provide specific callback
|
||||
* functions thanks to HAL_PPP_RegisterCallback() rather than overwriting
|
||||
* the default weak callback functions (see each stm32l4xx_hal_ppp.h file
|
||||
* for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef
|
||||
* for each PPP peripheral).
|
||||
*/
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_OSPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_TSC_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 0U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DFSDM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dfsdm.h"
|
||||
#endif /* HAL_DFSDM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32l4xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_comp.h"
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dcmi.h"
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA2D_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dma2d.h"
|
||||
#endif /* HAL_DMA2D_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DSI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dsi.h"
|
||||
#endif /* HAL_DSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GFXMMU_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_gfxmmu.h"
|
||||
#endif /* HAL_GFXMMU_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FIREWALL_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_firewall.h"
|
||||
#endif /* HAL_FIREWALL_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lcd.h"
|
||||
#endif /* HAL_LCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LTDC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_ltdc.h"
|
||||
#endif /* HAL_LTDC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_opamp.h"
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_ospi.h"
|
||||
#endif /* HAL_OSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PKA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pka.h"
|
||||
#endif /* HAL_PKA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PSSI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pssi.h"
|
||||
#endif /* HAL_PSSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_QSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_qspi.h"
|
||||
#endif /* HAL_QSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sai.h"
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smbus.h"
|
||||
#endif /* HAL_SMBUS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SWPMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_swpmi.h"
|
||||
#endif /* HAL_SWPMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TSC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tsc.h"
|
||||
#endif /* HAL_TSC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* STM32L4xx_HAL_CONF_H */
|
66
stm32l4a6zg-f0x.at1/Core/Inc/stm32l4xx_it.h
Normal file
66
stm32l4a6zg-f0x.at1/Core/Inc/stm32l4xx_it.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_it.h
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L4xx_IT_H
|
||||
#define __STM32L4xx_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void TIM6_DAC_IRQHandler(void);
|
||||
void DMA2_Channel7_IRQHandler(void);
|
||||
void LPUART1_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32L4xx_IT_H */
|
242
stm32l4a6zg-f0x.at1/Core/Src/commands.c
Normal file
242
stm32l4a6zg-f0x.at1/Core/Src/commands.c
Normal file
@ -0,0 +1,242 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file commands.c
|
||||
* @brief command.c file, the command interpreter, a generic one
|
||||
******************************************************************************
|
||||
* @author: Thomas Kuschel KW4NZ
|
||||
* created 2022-06-04
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "main.h"
|
||||
#include "at1_defines.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <stdint.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h> //strchr
|
||||
#include <stdlib.h> //bsearch
|
||||
#include "helper.h" //ltrim
|
||||
#include "si5351.h"
|
||||
|
||||
#include "commands.h"
|
||||
|
||||
/*
|
||||
typedef struct command_ctx_s {
|
||||
osThreadId_t thread_id;
|
||||
osMutexId_t mutex;
|
||||
char *last_cmd;
|
||||
size_t last_cmd_size;
|
||||
} command_ctx_t;
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
CMD_NO_FLAG = 0x00,
|
||||
CMD_HIDDEN = 0x01, /*!< Not shown in help but listed with "help all" or with "?" */
|
||||
CMD_SECRET = 0x02, /*!< Not shown in help - hidden and secret commands */
|
||||
CMD_ADMIN = 0x04, /*!< Only an administrator or privileged person can use this command */
|
||||
CMD_NOT_IMPLEMENTED = 0x80 /*!< A command which is not implemented yet */
|
||||
} cmd_flags_t;
|
||||
|
||||
#define CMD_LENGTH 16
|
||||
#define MAXLINELENGTH 40
|
||||
|
||||
typedef struct {
|
||||
const char name[CMD_LENGTH]; /*!< command name */
|
||||
const uint8_t significantlength; /*!< length of command for the compare function */
|
||||
const uint8_t flag; /*!< command flags, i.e. CMD_HIDDEN, CMD_SECRET, CMD_ADMIN, etc. */
|
||||
int (*func)(/*command_ctx_t *ctx,*/ char *args);
|
||||
} cmd_table_t;
|
||||
|
||||
// the entries must be in alphabetical order due to the binary search
|
||||
static const cmd_table_t cmd_table[] = {
|
||||
{"admin", 2, CMD_ADMIN, do_test },
|
||||
{"altitude", 1, CMD_NO_FLAG, do_test },
|
||||
{"date", 1, CMD_NO_FLAG, do_time },
|
||||
{"devid", 3, CMD_HIDDEN, do_devid },
|
||||
{"help", 1, CMD_NO_FLAG, do_help },
|
||||
{"hidden", 2, CMD_HIDDEN, do_test },
|
||||
{"info", 1, CMD_NO_FLAG, do_info },
|
||||
{"sinfo", 1, CMD_SECRET, do_sinfo },
|
||||
|
||||
{"time", 1, CMD_NO_FLAG, do_time },
|
||||
};
|
||||
|
||||
int do_test(char *args) {
|
||||
(void) *args;
|
||||
printf("not implemented.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief compares two strings up to n characters, and next gets the pointer to the 2nd word in the string s1
|
||||
*
|
||||
* @pre s1, s2 and n not allowed to be 0
|
||||
*
|
||||
* @param s1
|
||||
* @param next
|
||||
* @param s2
|
||||
* @param n
|
||||
* @return int if the s1 and s2 are the same till n characters its 0, if s1 > s2 it becomes 1, else -1
|
||||
*/
|
||||
int cmdncasecmp(const char *s1, char **next, const char *s2, size_t n)
|
||||
{
|
||||
if (n == 0 || s1 == NULL || s2 == NULL) {
|
||||
if (next) *next = NULL;
|
||||
if (s2 == NULL && s1 != NULL) return 1;
|
||||
if (s1 == NULL && s2 != NULL) return -1;
|
||||
return 0;
|
||||
}
|
||||
int ret;
|
||||
while ((ret = ((unsigned char)tolower(*s1) - (unsigned char)tolower(*s2))) == 0
|
||||
&& *s1 != ' ' && *s1 && *s2) {
|
||||
if (n) n--;
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (next) *next = (char *) s1;
|
||||
if (n == 0 && (*s1 == ' ' || !*s1))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int compar(const void *a, const void *b)
|
||||
{
|
||||
cmd_table_t * cmd = (cmd_table_t *)b;
|
||||
return cmdncasecmp(a, NULL, cmd->name, cmd->significantlength);
|
||||
}
|
||||
|
||||
|
||||
int cmd_interpreter(char * cmdline) {
|
||||
char * ptr;
|
||||
const cmd_table_t *entry;
|
||||
int rv = 0;
|
||||
|
||||
ptr = strchr(cmdline, ' ');
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
ptr++;
|
||||
ptr = ltrim(ptr);
|
||||
}
|
||||
entry = bsearch(cmdline, cmd_table, sizeof(cmd_table)/sizeof(cmd_table[0]), sizeof(cmd_table[0]), compar);
|
||||
if (entry == NULL) {
|
||||
printf("Command \"%s\" not found.\n", cmdline);
|
||||
} else {
|
||||
printf("Command \"%s\":\n", entry->name);
|
||||
if (*ptr != '\0')
|
||||
printf("called with parameter: \"%s\"\n", ptr);
|
||||
rv = entry->func(ptr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int do_devid(char *args) {
|
||||
|
||||
(void)args;
|
||||
union myUnion {
|
||||
uint32_t myint[2];
|
||||
char mychar[8];
|
||||
} my;
|
||||
//char lot[sizeof(my) + 1];
|
||||
|
||||
printf("DEVID: 0x%08lx\n", HAL_GetDEVID());
|
||||
printf("REVID: 0x%08lx\n", HAL_GetREVID());
|
||||
printf("UID: 0x%08lx %08lx %08lx\n", HAL_GetUIDw2(), HAL_GetUIDw1(), HAL_GetUIDw0());
|
||||
|
||||
my.myint[1] = HAL_GetUIDw2();
|
||||
my.myint[0] = HAL_GetUIDw1();
|
||||
//memcpy(lot, my.mychar, sizeof(my.mychar));
|
||||
//lot[sizeof(my)] = '\0';
|
||||
|
||||
printf("=> Lot Number: %.8s\n", my.mychar);
|
||||
printf("=> Wafer Number: %u\n", (uint8_t)(HAL_GetUIDw1() & 0xff));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_info(char *args) {
|
||||
(void)args;
|
||||
print_system_info();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_sinfo(char *args) {
|
||||
int rv = 0;
|
||||
(void)args;
|
||||
si5351_inst_t inst = NULL;
|
||||
rv = si5351_get_instance(&inst);
|
||||
printf("%d Si5351 instance%s found.\n", rv, (rv==1)?"":"s");
|
||||
while (rv > 0) {
|
||||
printf("Si5351 Handle: 0x%08lx\n", (uint32_t)inst);
|
||||
|
||||
rv = si5351_get_instance(&inst);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int do_time(char *args) {
|
||||
|
||||
HAL_StatusTypeDef status;
|
||||
RTC_TimeTypeDef stime = {0};
|
||||
RTC_DateTypeDef sdate = {0};
|
||||
int rv = 0;
|
||||
|
||||
if (args) {
|
||||
|
||||
struct _tm_ tp;
|
||||
rv = strtotime (args, &tp);
|
||||
if (rv > 0) {
|
||||
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (tp.year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, \
|
||||
tp.year, tp.mon, tp.day, tp.hour, tp.min, tp.sec);
|
||||
/** Initialize RTC and set the Time and Date */
|
||||
stime.Hours = (uint8_t)tp.hour;
|
||||
stime.Minutes = (uint8_t)tp.min;
|
||||
stime.Seconds = (uint8_t)tp.sec;
|
||||
stime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
stime.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
if (HAL_RTC_SetTime(&hrtc, &stime, RTC_FORMAT_BIN) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sdate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
sdate.Month = (uint8_t)tp.mon;
|
||||
sdate.Date = (uint8_t)tp.day;
|
||||
sdate.Year = (uint8_t)tp.year;
|
||||
//uint8_t weekday;
|
||||
//weekday = dayofweek((tp.year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, sdate.Year, sdate.Month, sdate.Date);
|
||||
//printf("Wochentag: %d\n", weekday);
|
||||
if (HAL_RTC_SetDate(&hrtc, &sdate, RTC_FORMAT_BIN) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
status = HAL_RTC_GetTime(&hrtc, &stime, RTC_FORMAT_BIN);
|
||||
if (status != HAL_OK)
|
||||
puts("HAL_RTC_GetTime problem...");
|
||||
status = HAL_RTC_GetDate(&hrtc, &sdate, RTC_FORMAT_BIN);
|
||||
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (sdate.Year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, \
|
||||
sdate.Year, sdate.Month, sdate.Date, stime.Hours, stime.Minutes, stime.Seconds);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int do_help(char *args) {
|
||||
|
||||
int all = cmdncasecmp(args, NULL, "all", 1);
|
||||
const cmd_table_t *cmd = cmd_table;
|
||||
int j = 0;
|
||||
int n = 0;
|
||||
int rv = 0;
|
||||
|
||||
puts("Commands:");
|
||||
|
||||
for (size_t i = 0; i < (sizeof(cmd_table)/sizeof(cmd_table[0])); i++, cmd++) {
|
||||
if (cmd->flag != CMD_SECRET && (cmd->flag != CMD_HIDDEN || !all)) {
|
||||
if (n >= MAXLINELENGTH) {
|
||||
puts(",");
|
||||
n = 0;
|
||||
}
|
||||
// n += printf("%s%s (%.*s)", n?", ":"", cmd->name, cmd->significantlength, cmd->name);
|
||||
n += printf("%s(%.*s)%s", n?", ":"", cmd->significantlength, cmd->name, cmd->name + cmd->significantlength);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
printf("\n%d commands found.\n", j);
|
||||
return rv;
|
||||
}
|
59
stm32l4a6zg-f0x.at1/Core/Src/freertos.c
Normal file
59
stm32l4a6zg-f0x.at1/Core/Src/freertos.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* File Name : freertos.c
|
||||
* Description : Code for freertos applications
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Variables */
|
||||
|
||||
/* USER CODE END Variables */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
/* Private application code --------------------------------------------------*/
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
150
stm32l4a6zg-f0x.at1/Core/Src/helper.c
Normal file
150
stm32l4a6zg-f0x.at1/Core/Src/helper.c
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* helper.c
|
||||
*
|
||||
* Created on: Jul 14, 2022
|
||||
* Author: tom
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> /* sscanf */
|
||||
|
||||
#include <at1_defines.h> /* include my defines from a global view, else */
|
||||
#ifndef DATE_COMPILE_CENTURY
|
||||
#define DATE_COMPILE_CENTURY (20)
|
||||
#define DATE_COMPILE_YEAR (22)
|
||||
#endif
|
||||
|
||||
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
|
||||
#include <errno.h>
|
||||
#endif
|
||||
/* do not use the #include <time.h> library */
|
||||
#include "helper.h"
|
||||
|
||||
char *ltrim(char *s)
|
||||
{
|
||||
while(isspace((int)*s)) s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
char *rtrim(char *s)
|
||||
{
|
||||
char* back = s + strlen(s);
|
||||
while(isspace((int)*--back));
|
||||
*(back+1) = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
char *trim(char *s)
|
||||
{
|
||||
return rtrim(ltrim(s));
|
||||
}
|
||||
|
||||
/* this is ISO 8601 2018-12-31 with separator == '-' */
|
||||
int strtotime (char *s, struct _tm_ *tp) {
|
||||
|
||||
int rv = 0;
|
||||
uint32_t tmp;
|
||||
struct _tm_ tm = {0};
|
||||
do {
|
||||
/* Check for the day and/or year */
|
||||
tmp = strtoul(s, &s, 10); /* base 10 */
|
||||
/* Check of plausibility: Year must be within compilation year and max 10 centuries from now on, i.e. 3000 */
|
||||
if (tmp >= (DATE_COMPILE_CENTURY * 100 + DATE_COMPILE_YEAR) && tmp < ((DATE_COMPILE_CENTURY + 10) * 100)) {
|
||||
tm.year = (uint8_t)(tmp % 100UL);
|
||||
} else {
|
||||
rv = -EINVAL;
|
||||
break;
|
||||
}
|
||||
rv = sscanf(s, "-%hu-%hu %hu:%hu:%hu", &tm.mon, &tm.day, &tm.hour, &tm.min, &tm.sec);
|
||||
if (rv >= 3)
|
||||
*tp = tm;
|
||||
else
|
||||
rv = -EINVAL;
|
||||
|
||||
} while(0);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
while (*str == ' ') {
|
||||
str++;
|
||||
};
|
||||
*args = str;
|
||||
return CMD_OK;
|
||||
} else {
|
||||
separator = '/';
|
||||
if (tmp > 0 && tmp < 32)
|
||||
timeinfo.tm_mday = tmp;
|
||||
else
|
||||
goto error;
|
||||
}
|
||||
|
||||
str++;
|
||||
/* Read the month */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
if (*str != separator || tmp == 0 || tmp > 12)
|
||||
goto error;
|
||||
timeinfo.tm_mon = tmp - 1; /* the month is interpreted from 0..11 */
|
||||
str++;
|
||||
/* Check either the day or the four-digit year */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
/* there should either spaces or a T between date and time info */
|
||||
if ((toupper(*str) != 'T' && *str != ' ') || tmp == 0 || tmp >= 2106)
|
||||
goto error;
|
||||
if (separator == '-') {
|
||||
timeinfo.tm_mday = tmp;
|
||||
} else if (tmp >= FW_VERSION_YEAR) {
|
||||
timeinfo.tm_year = tmp - 1900;
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
do {
|
||||
str++;
|
||||
} while (*str == ' ');
|
||||
|
||||
/* the hour have to be 0..23 */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
if (*str != ':' || tmp > 23)
|
||||
goto error;
|
||||
timeinfo.tm_hour = tmp;
|
||||
str++;
|
||||
/* the minute have to be 0..59 */
|
||||
tmp = strtoul(str, &str, 10);
|
||||
if (tmp > 59)
|
||||
goto error;
|
||||
timeinfo.tm_min = tmp;
|
||||
|
||||
if (*str == ':') {
|
||||
str++;
|
||||
tmp = strtoul(str, &str, 10);
|
||||
} else {
|
||||
tmp = 0;
|
||||
}
|
||||
if (tmp > 59)
|
||||
goto error;
|
||||
timeinfo.tm_sec = tmp;
|
||||
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
if (*str != '\0' && (flags & ARG_LAST))
|
||||
goto error;
|
||||
/* Try to create the time stamp */
|
||||
{
|
||||
time_t tmp_unixtime = mktime(&timeinfo);
|
||||
if (tmp_unixtime == (unsigned)-1) {
|
||||
goto error;
|
||||
}
|
||||
*args = str;
|
||||
*unixtime = tmp_unixtime;
|
||||
}
|
||||
return CMD_OK;
|
||||
|
||||
error:
|
||||
*args = str;
|
||||
return CMD_ERROR_PARAMETERS;
|
||||
}
|
||||
#endif
|
1173
stm32l4a6zg-f0x.at1/Core/Src/main.c
Normal file
1173
stm32l4a6zg-f0x.at1/Core/Src/main.c
Normal file
File diff suppressed because it is too large
Load Diff
311
stm32l4a6zg-f0x.at1/Core/Src/ringbuf.c
Normal file
311
stm32l4a6zg-f0x.at1/Core/Src/ringbuf.c
Normal file
@ -0,0 +1,311 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ringbuf.c
|
||||
* @brief driver for a ring buffer used for UART RX
|
||||
******************************************************************************
|
||||
* @author: Thomas Kuschel KW4NZ
|
||||
* created 2022-07-12
|
||||
*
|
||||
* A description can be found in the header file ringbuf.h
|
||||
******************************************************************************/
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h> /* malloc */
|
||||
#include <stdio.h> /* printf */
|
||||
#include <string.h> /* memcpy */
|
||||
#include "ringbuf.h"
|
||||
|
||||
/* macros */
|
||||
#define MEM_USED(b) ((b->size + b->head - b->tail) % b->size)
|
||||
#define MEM_FREE(b) ((b->size + b->tail - b->head - 1) % b->size + 1)
|
||||
|
||||
#if RING_STATISTICS_ENABLED
|
||||
typedef struct stat {
|
||||
uint32_t overflows;
|
||||
uint32_t reads;
|
||||
uint32_t writes;
|
||||
} stat_t;
|
||||
#endif
|
||||
|
||||
typedef struct ringbuf {
|
||||
#if RING_STATISTICS_ENABLED
|
||||
stat_t statistics;
|
||||
#endif
|
||||
ringbuf_rcv_cb_t rcv_callback;
|
||||
void *rcv_cb_data;
|
||||
uint8_t *buf;
|
||||
uint16_t size;
|
||||
uint16_t head;
|
||||
uint16_t tail;
|
||||
uint16_t delimiterfound;
|
||||
uint16_t max_read_len;
|
||||
unsigned full :1; // not implemented yet
|
||||
unsigned halffull:1; // not implemented yet
|
||||
unsigned overflow:1;
|
||||
unsigned allowoverwrite:1;
|
||||
} ringbuf_t;
|
||||
|
||||
struct ringbuf * ringbuf_create(size_t size, ringbuf_param_t param) {
|
||||
|
||||
struct ringbuf * rb;
|
||||
if (size == 0 || size > USHRT_MAX)
|
||||
return NULL;
|
||||
|
||||
// rb = malloc(sizeof(ringbuf_t) + size * sizeof(uint8_t));
|
||||
rb = calloc(1, sizeof(ringbuf_t) + size * sizeof(uint8_t));
|
||||
if (rb == NULL) {
|
||||
puts("Memory not allocated.");
|
||||
exit(0);
|
||||
} else {
|
||||
//puts("Memory successfully allocated.");
|
||||
// the data area is connected to the structure
|
||||
rb->buf = (uint8_t *)rb + sizeof(ringbuf_t);
|
||||
rb->size = (uint16_t)size;
|
||||
// rb->head = rb->tail = rb->halffull = rb->overflow 0;
|
||||
if (param & RINGBUF_ALLOWOVERWRITE)
|
||||
rb->allowoverwrite = 1;
|
||||
rb->max_read_len = RINGBUF_MAX_READ_LEN;
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
|
||||
void ringbuf_destroy(struct ringbuf *ring) {
|
||||
if (ring != 0)
|
||||
free(ring);
|
||||
}
|
||||
|
||||
int ringbuf_dump(struct ringbuf *ring) {
|
||||
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
printf("Buffer: 0x%08x\n", (unsigned int) ring);
|
||||
printf("Start: 0x%08x\n", (unsigned int) ring->buf);
|
||||
printf("Size: total: %d used: %d free: %d\n", ring->size, MEM_USED(ring), MEM_FREE(ring));
|
||||
printf("Head: %d\n", ring->head);
|
||||
printf("Tail: %d\n", ring->tail);
|
||||
printf("Empty: %s\n", (ring->head == ring->tail) ? "yes" : "no");
|
||||
printf("Max read length: %d\n", ring->max_read_len);
|
||||
for (size_t i = 0; i < ring->size; i += 16 ) {
|
||||
for (size_t j = 0; j < 16 && (j + i) < ring->size; j++) {
|
||||
//printf("%02x%s", *(ring->buf +i), ((i%4)==3)?(((i%16)==15)?"\n":" "):"");
|
||||
printf("%02x%s", *(ring->buf + i + j), ((j%4)==3)?" ":"");
|
||||
}
|
||||
putchar(' ');
|
||||
for (size_t j = 0; j < 16 && (j + i) < ring->size; j++) {
|
||||
uint8_t b = *(ring->buf + i + j);
|
||||
printf("%c", ((b >= ' ') && (b < 127))? b: '.');
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ringbuf_push(struct ringbuf *ring, const uint8_t *data, size_t size) {
|
||||
|
||||
size_t delimiterpos;
|
||||
size_t delimiterfound = 0;
|
||||
uint16_t head;
|
||||
uint8_t *ptr;
|
||||
|
||||
if (ring == NULL || size == 0 || data == NULL || size > USHRT_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
if (size >= ring->size)
|
||||
return -ENOMEM;
|
||||
|
||||
if (size >= (size_t)MEM_FREE(ring)) { // no free space available, but overwrite ?
|
||||
#if RING_STATISTICS_ENABLED
|
||||
ring->statistics.overflows++;
|
||||
#endif
|
||||
if (ring->allowoverwrite)
|
||||
ring->overflow = 1;
|
||||
else
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
head = ring->head;
|
||||
if (head + size > ring->size) {
|
||||
uint16_t remaining = ring->size - head;
|
||||
memcpy(ring->buf + head, data, remaining);
|
||||
ring->head = (uint16_t)(size - remaining);
|
||||
memcpy(ring->buf, data + remaining, ring->head);
|
||||
} else {
|
||||
memcpy(ring->buf + head, data, size);
|
||||
ring->head += (uint16_t)size;
|
||||
}
|
||||
for (delimiterpos = 0; delimiterpos < size; delimiterpos++) {
|
||||
if (data[delimiterpos] == '\n' || data[delimiterpos] == 0 ) {
|
||||
delimiterfound++;
|
||||
ptr = ring->buf + ((head + delimiterpos) % ring->size);
|
||||
*ptr = 0;
|
||||
}
|
||||
}
|
||||
ring->head %= ring->size;
|
||||
|
||||
#if RING_STATISTICS_ENABLED
|
||||
ring->statistics.writes +=size;
|
||||
#endif
|
||||
ring->delimiterfound = (uint16_t)delimiterfound;
|
||||
//call registered callback function
|
||||
if (ring->delimiterfound && ring->rcv_callback != NULL)
|
||||
ring->rcv_callback(ring->delimiterfound, ring->rcv_cb_data);
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
int ringbuf_clear(struct ringbuf *ring) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
ring->tail = ring->head;
|
||||
ring->full = ring->halffull = ring->overflow = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ringbuf_is_empty(struct ringbuf *ring) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
return (ring->tail == ring->head);
|
||||
}
|
||||
|
||||
int ringbuf_pull(struct ringbuf *ring, uint8_t *data, size_t maxsize) {
|
||||
|
||||
size_t datasize;
|
||||
|
||||
if (ring == NULL || maxsize == 0 || data == NULL || maxsize > USHRT_MAX)
|
||||
return -EINVAL;
|
||||
datasize = min(maxsize, (size_t)MEM_USED(ring));
|
||||
if (datasize > ring->size)
|
||||
return -ENOMEM;
|
||||
|
||||
if ((ring->head > ring->tail) /*|| ring->full*/) {
|
||||
memcpy(data, ring->buf + ring->tail, datasize);
|
||||
ring->tail += (uint16_t)datasize;
|
||||
} else {
|
||||
if (ring->head < ring->tail) {
|
||||
size_t remaining = ring->size -ring->tail;
|
||||
if (datasize < remaining) {
|
||||
memcpy(data, ring->buf + ring->tail, datasize);
|
||||
ring->tail += (uint16_t)datasize;
|
||||
} else {
|
||||
memcpy(data, ring->buf + ring->tail, remaining);
|
||||
ring->tail = (uint16_t)(datasize - remaining);
|
||||
memcpy(data + remaining, ring->buf, ring->tail);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if RING_STATISTICS_ENABLED
|
||||
ring->statistics.reads += datasize;
|
||||
#endif
|
||||
ring->overflow = 0;
|
||||
return (int)datasize;
|
||||
}
|
||||
|
||||
int ringbuf_read(struct ringbuf *ring, char *str) {
|
||||
|
||||
int len = 0;
|
||||
uint16_t tail = 0;
|
||||
|
||||
if (ring == NULL || str == NULL)
|
||||
return -EINVAL;
|
||||
|
||||
*str = '\0';
|
||||
if (ring->head == ring->tail){
|
||||
return 0;
|
||||
}
|
||||
tail = ring->tail;
|
||||
if (ring->head > ring->tail) {
|
||||
if (ring->max_read_len < 2)
|
||||
return -ENOMEM;
|
||||
strncpy(str, (char *)(ring->buf + ring->tail), ring->max_read_len);
|
||||
str[ring->max_read_len] = '\0';
|
||||
for (int i = ring->tail; i < ring->head; i++) {
|
||||
if (*(ring->buf + i) == 0) {
|
||||
ring->tail = (uint16_t)i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ring->tail == tail) {
|
||||
// no \0 found
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
int continu = 1;
|
||||
int tail = 0;
|
||||
strncpy(str, (char *)(ring->buf + ring->tail),(size_t)min(ring->size - ring->tail, ring->max_read_len));
|
||||
str[ring->max_read_len] = '\0';
|
||||
len = (int)strlen(str);
|
||||
for (int i = ring->tail; i < ring->size; i++) {
|
||||
if (*(ring->buf + i) == 0) {
|
||||
tail = i + 1;
|
||||
continu = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (continu) {
|
||||
strncpy(str + ring->size - ring->tail, (char *)ring->buf, (size_t)(ring->max_read_len - ring->size + ring->tail));
|
||||
str[ring->max_read_len] = '\0';
|
||||
continu = 1;
|
||||
for (int i = 0; i < ring->head; i++) {
|
||||
if (*(ring->buf + i) == 0) {
|
||||
tail = i + 1;
|
||||
continu = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (continu)
|
||||
return -EINVAL;
|
||||
}
|
||||
ring->tail = (uint16_t)tail;
|
||||
}
|
||||
len = (int)strlen(str);
|
||||
ring->tail = ring->tail % ring->size;
|
||||
#if RING_STATISTICS_ENABLED
|
||||
ring->statistics.reads += (uint32_t)len + 1;
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
|
||||
int ringbuf_write(struct ringbuf *ring, char *str) {
|
||||
|
||||
size_t len = 0;
|
||||
len = (size_t)strlen(str);
|
||||
if (len > 0)
|
||||
return ringbuf_push(ring, (uint8_t *)str, len + 1);
|
||||
else
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if RING_STATISTICS_ENABLED
|
||||
int ringbuf_statistics(struct ringbuf *ring) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
puts("Ring Buffer Statistics:");
|
||||
printf(" Bytes written: %ld\n", ring->statistics.writes);
|
||||
printf(" Bytes read: %ld\n", ring->statistics.reads);
|
||||
printf("# of overflows: %ld\n", ring->statistics.overflows);
|
||||
return 0;
|
||||
}
|
||||
int ringbuf_stat_writes(struct ringbuf *ring) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
return (int)ring->statistics.writes;
|
||||
}
|
||||
int ringbuf_stat_reads(struct ringbuf *ring) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
return (int)ring->statistics.reads;
|
||||
}
|
||||
int ringbuf_stat_overflow(struct ringbuf *ring) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
return (int)ring->statistics.overflows;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ringbuf_callback_register(struct ringbuf *ring, ringbuf_rcv_cb_t cb_func, void *cb_data) {
|
||||
if (ring == NULL)
|
||||
return -EINVAL;
|
||||
ring->rcv_callback = cb_func;
|
||||
ring->rcv_cb_data = cb_data;
|
||||
return 0;
|
||||
}
|
144
stm32l4a6zg-f0x.at1/Core/Src/ringbuf_test.c
Normal file
144
stm32l4a6zg-f0x.at1/Core/Src/ringbuf_test.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* ringbuf_test.c
|
||||
*
|
||||
* Created on: Jul 14, 2022
|
||||
* Author: tom
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include "ringbuf.h"
|
||||
#include <malloc.h>
|
||||
|
||||
|
||||
void ringbuf_test(void) {
|
||||
size_t usable_size = 0;
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
malloc_stats();
|
||||
|
||||
|
||||
assert(1);
|
||||
// assert(0); // ... assertion "0" failed: ...blabla bla
|
||||
//1. Test Initialization
|
||||
hring rb1 = ringbuf_create(512, RINGBUF_PARAM_NONE);
|
||||
usable_size = malloc_usable_size(rb1);
|
||||
fprintf(stdout, "Malloc Usable Size: %d\n", usable_size);
|
||||
|
||||
hring rb2 = ringbuf_create(512, RINGBUF_ALLOWOVERWRITE);
|
||||
assert(rb1 != NULL);
|
||||
assert(rb2 != NULL);
|
||||
hring rb3 = ringbuf_create(512, RINGBUF_ALLOWOVERWRITE);
|
||||
hring rb4 = ringbuf_create(512, RINGBUF_ALLOWOVERWRITE);
|
||||
|
||||
|
||||
printf("Malloc Usable Size of rb1: %d\n", malloc_usable_size(rb1));
|
||||
printf("Malloc Usable Size of rb2: %d\n", malloc_usable_size(rb2));
|
||||
printf("Malloc Usable Size of rb3: %d\n", malloc_usable_size(rb3));
|
||||
printf("Malloc Usable Size of rb4: %d\n", malloc_usable_size(rb4));
|
||||
|
||||
ringbuf_destroy(rb4);
|
||||
malloc_stats();
|
||||
ringbuf_destroy(rb3);
|
||||
malloc_stats();
|
||||
|
||||
malloc_stats();
|
||||
ringbuf_destroy(rb2);
|
||||
malloc_stats();
|
||||
ringbuf_destroy(rb1);
|
||||
malloc_stats();
|
||||
|
||||
printf("rb1 after destroy is: 0x%08X\n", (unsigned int) rb1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
volatile int ret = 0;
|
||||
ring = ringbuf_create(64,RINGBUF_ALLOWOVERWRITE);
|
||||
if (ring == NULL)
|
||||
printf("we have some problems ...\n");
|
||||
|
||||
uint8_t data[1024];
|
||||
char str[1024]={0};
|
||||
|
||||
strcpy(str, "KW4NZ");
|
||||
|
||||
ret = ringbuf_dump(ring);
|
||||
ret = ringbuf_write(ring, str);
|
||||
printf("Writing string: %s\n", str);
|
||||
ret = ringbuf_dump(ring);
|
||||
ret = ringbuf_push(ring, (uint8_t *)"Ich gehe spazieren.", sizeof("Ich gehe spazieren."));
|
||||
ret = ringbuf_dump(ring);
|
||||
ret = ringbuf_push(ring, (uint8_t *)"NOCHMALS GEHE ICH RAUS.", sizeof("NOCHMALS GEHE ICH RAUS."));
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("STRING: %s\n", str);
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("STRING: %s\n", str);
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("STRING: %s\n", str);
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
strcpy(str, "OE3TKT,OE1TKT,OE7TKT");
|
||||
ret = ringbuf_write(ring, str);
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("STRING: %s\n", str);
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
strcpy(str, "OE1TKT,OE3TKT,OE7TKT");
|
||||
ret = ringbuf_write(ring, str);
|
||||
strcpy(str, "KW4NZ");
|
||||
ret = ringbuf_write(ring, str);
|
||||
ret = ringbuf_dump(ring);
|
||||
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("STRING: %s (OE1TKT,OE3TKT,OE7TKT)\n", str);
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("STRING: %s (KW4NZ)\n", str);
|
||||
|
||||
ret = ringbuf_pull(ring, data, 1024);
|
||||
printf("Read %d bytes...\n", ret);
|
||||
for (int i = 0; i < ret; i++)
|
||||
putchar(data[i]);
|
||||
puts("");
|
||||
|
||||
ringbuf_dump(ring);
|
||||
|
||||
ret = ringbuf_push(ring, (uint8_t *)"Eine 128-tägige Reise ist zu gewinnen!", sizeof("Eine 128-tägige Reise ist zu gewinnen!"));
|
||||
ringbuf_dump(ring);
|
||||
|
||||
// ret = ringbuf_push(ring, (uint8_t *)"Eine 100-tägige Reise ist zu gewinnen!", sizeof("Eine 128-tägige Reise ist zu gewinnen!"));
|
||||
// ret = ringbuf_push(ring, (uint8_t *)"Eine 90-tägige Reise ist zu gewinnen!", sizeof("Eine 90-tägige Reise ist zu gewinnen!"));
|
||||
ret = ringbuf_push(ring, (uint8_t *)"ENDENDENDENDEND", sizeof("ENDENDENDENDEND"));
|
||||
ringbuf_dump(ring);
|
||||
ret = ringbuf_push(ring, (uint8_t *)"Vereinbarungen treffen zu.", sizeof("Vereinbarungen treffen zu."));
|
||||
ringbuf_dump(ring);
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("String: %s (length: %d)\n", str, ret);
|
||||
ret = ringbuf_dump(ring);
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("String: %s (length: %d)\n", str, ret);
|
||||
ret = ringbuf_read(ring, str);
|
||||
printf("String: %s (length: %d)\n", str, ret);
|
||||
|
||||
ret = ringbuf_pull(ring, data, 1024);
|
||||
printf("Read %d bytes...\n", ret);
|
||||
for (int i = 0; i < ret; i++)
|
||||
putchar(data[i]);
|
||||
puts("");
|
||||
ringbuf_dump(ring);
|
||||
|
||||
ringbuf_clear(ring);
|
||||
ringbuf_dump(ring);
|
||||
#if RING_STATISTICS_ENABLED
|
||||
ringbuf_statistics(ring);
|
||||
#endif
|
||||
#endif
|
1002
stm32l4a6zg-f0x.at1/Core/Src/si5351.c
Normal file
1002
stm32l4a6zg-f0x.at1/Core/Src/si5351.c
Normal file
File diff suppressed because it is too large
Load Diff
319
stm32l4a6zg-f0x.at1/Core/Src/stm32l4xx_hal_msp.c
Normal file
319
stm32l4a6zg-f0x.at1/Core/Src/stm32l4xx_hal_msp.c
Normal file
@ -0,0 +1,319 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
extern DMA_HandleTypeDef hdma_lpuart_rx;
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
/* PendSV_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hi2c: I2C handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(hi2c->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
|
||||
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**I2C1 GPIO Configuration
|
||||
PB8 ------> I2C1_SCL
|
||||
PB9 ------> I2C1_SDA
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN I2C1_MspInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hi2c: I2C handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
|
||||
{
|
||||
if(hi2c->Instance==I2C1)
|
||||
{
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_I2C1_CLK_DISABLE();
|
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB8 ------> I2C1_SCL
|
||||
PB9 ------> I2C1_SDA
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
|
||||
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END I2C1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param huart: UART handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(huart->Instance==LPUART1)
|
||||
{
|
||||
/* USER CODE BEGIN LPUART1_MspInit 0 */
|
||||
|
||||
/* USER CODE END LPUART1_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
|
||||
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_LPUART1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
HAL_PWREx_EnableVddIO2();
|
||||
/**LPUART1 GPIO Configuration
|
||||
PG7 ------> LPUART1_TX
|
||||
PG8 ------> LPUART1_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
|
||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||
|
||||
/* LPUART1 DMA Init */
|
||||
/* LPUART_RX Init */
|
||||
hdma_lpuart_rx.Instance = DMA2_Channel7;
|
||||
hdma_lpuart_rx.Init.Request = DMA_REQUEST_4;
|
||||
hdma_lpuart_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_lpuart_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_lpuart_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_lpuart_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_lpuart_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_lpuart_rx.Init.Mode = DMA_NORMAL;
|
||||
hdma_lpuart_rx.Init.Priority = DMA_PRIORITY_LOW;
|
||||
if (HAL_DMA_Init(&hdma_lpuart_rx) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(huart,hdmarx,hdma_lpuart_rx);
|
||||
|
||||
/* LPUART1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(LPUART1_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(LPUART1_IRQn);
|
||||
/* USER CODE BEGIN LPUART1_MspInit 1 */
|
||||
|
||||
/* USER CODE END LPUART1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param huart: UART handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
||||
{
|
||||
if(huart->Instance==LPUART1)
|
||||
{
|
||||
/* USER CODE BEGIN LPUART1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END LPUART1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_LPUART1_CLK_DISABLE();
|
||||
|
||||
/**LPUART1 GPIO Configuration
|
||||
PG7 ------> LPUART1_TX
|
||||
PG8 ------> LPUART1_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOG, STLK_RX_Pin|STLK_TX_Pin);
|
||||
|
||||
/* LPUART1 DMA DeInit */
|
||||
HAL_DMA_DeInit(huart->hdmarx);
|
||||
|
||||
/* LPUART1 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(LPUART1_IRQn);
|
||||
/* USER CODE BEGIN LPUART1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END LPUART1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
136
stm32l4a6zg-f0x.at1/Core/Src/stm32l4xx_hal_timebase_tim.c
Normal file
136
stm32l4a6zg-f0x.at1/Core/Src/stm32l4xx_hal_timebase_tim.c
Normal file
@ -0,0 +1,136 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_timebase_TIM.c
|
||||
* @brief HAL time base based on the hardware TIM.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_hal.h"
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim6;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @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
|
||||
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority: Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock, uwAPB1Prescaler;
|
||||
|
||||
uint32_t uwPrescalerValue;
|
||||
uint32_t pFLatency;
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Enable TIM6 clock */
|
||||
__HAL_RCC_TIM6_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Get APB1 prescaler */
|
||||
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
|
||||
/* Compute TIM6 clock */
|
||||
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
|
||||
{
|
||||
uwTimclock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
else
|
||||
{
|
||||
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
/* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM6 */
|
||||
htim6.Instance = TIM6;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
+ 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
|
||||
*/
|
||||
htim6.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim6.Init.Prescaler = uwPrescalerValue;
|
||||
htim6.Init.ClockDivision = 0;
|
||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
|
||||
status = HAL_TIM_Base_Init(&htim6);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
status = HAL_TIM_Base_Start_IT(&htim6);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the TIM6 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
/* Configure the TIM IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM6 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM6 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);
|
||||
}
|
||||
|
208
stm32l4a6zg-f0x.at1/Core/Src/stm32l4xx_it.c
Normal file
208
stm32l4a6zg-f0x.at1/Core/Src/stm32l4xx_it.c
Normal file
@ -0,0 +1,208 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32l4xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern DMA_HandleTypeDef hdma_lpuart_rx;
|
||||
extern UART_HandleTypeDef hlpuart1;
|
||||
extern TIM_HandleTypeDef htim6;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M4 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
//printf("something went wrong -> HardFault_Handler called\n");
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32L4xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32l4xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM6 global interrupt, DAC channel1 and channel2 underrun error interrupts.
|
||||
*/
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM6_DAC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim6);
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM6_DAC_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA2 channel7 global interrupt.
|
||||
*/
|
||||
void DMA2_Channel7_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DMA2_Channel7_IRQn 0 */
|
||||
|
||||
/* USER CODE END DMA2_Channel7_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_lpuart_rx);
|
||||
/* USER CODE BEGIN DMA2_Channel7_IRQn 1 */
|
||||
|
||||
/* USER CODE END DMA2_Channel7_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles LPUART1 global interrupt.
|
||||
*/
|
||||
void LPUART1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN LPUART1_IRQn 0 */
|
||||
|
||||
/* USER CODE END LPUART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&hlpuart1);
|
||||
/* USER CODE BEGIN LPUART1_IRQn 1 */
|
||||
|
||||
/* USER CODE END LPUART1_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
176
stm32l4a6zg-f0x.at1/Core/Src/syscalls.c
Normal file
176
stm32l4a6zg-f0x.at1/Core/Src/syscalls.c
Normal file
@ -0,0 +1,176 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file syscalls.c
|
||||
* @author Auto-generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE Minimal System calls file
|
||||
*
|
||||
* For more information about which c-functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the Newlib libc-manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles()
|
||||
{
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int status)
|
||||
{
|
||||
_kill(status, -1);
|
||||
while (1) {} /* Make sure we hang here */
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
(void)file;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = (char)__io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
(void)file;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _close(int file)
|
||||
{
|
||||
(void)file;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
(void)file;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(char *path, int flags, ...)
|
||||
{
|
||||
(void)path;
|
||||
(void)flags;
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait(int *status)
|
||||
{
|
||||
(void)status;
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(char *name)
|
||||
{
|
||||
(void)name;
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _times(struct tms *buf)
|
||||
{
|
||||
(void)buf;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(char *file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _link(char *old, char *new)
|
||||
{
|
||||
(void)old;
|
||||
(void)new;
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork(void)
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _execve(char *name, char **argv, char **env)
|
||||
{
|
||||
(void)name;
|
||||
(void)argv;
|
||||
(void)env;
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
79
stm32l4a6zg-f0x.at1/Core/Src/sysmem.c
Normal file
79
stm32l4a6zg-f0x.at1/Core/Src/sysmem.c
Normal file
@ -0,0 +1,79 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sysmem.c
|
||||
* @author Generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE System Memory calls file
|
||||
*
|
||||
* For more information about which C functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the newlib libc manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Pointer to the current high watermark of the heap usage
|
||||
*/
|
||||
static uint8_t *__sbrk_heap_end = NULL;
|
||||
|
||||
/**
|
||||
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
|
||||
* and others from the C library
|
||||
*
|
||||
* @verbatim
|
||||
* ############################################################################
|
||||
* # .data # .bss # newlib heap # MSP stack #
|
||||
* # # # # Reserved by _Min_Stack_Size #
|
||||
* ############################################################################
|
||||
* ^-- RAM start ^-- _end _estack, RAM end --^
|
||||
* @endverbatim
|
||||
*
|
||||
* This implementation starts allocating at the '_end' linker symbol
|
||||
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
|
||||
* The implementation considers '_estack' linker symbol to be RAM end
|
||||
* NOTE: If the MSP stack, at any point during execution, grows larger than the
|
||||
* reserved size, please increase the '_Min_Stack_Size'.
|
||||
*
|
||||
* @param incr Memory size
|
||||
* @return Pointer to allocated memory
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern uint8_t _end; /* Symbol defined in the linker script */
|
||||
extern uint8_t _estack; /* Symbol defined in the linker script */
|
||||
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
|
||||
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
|
||||
const uint8_t *max_heap = (uint8_t *)stack_limit;
|
||||
uint8_t *prev_heap_end;
|
||||
|
||||
/* Initialize heap end at first call */
|
||||
if (NULL == __sbrk_heap_end)
|
||||
{
|
||||
__sbrk_heap_end = &_end;
|
||||
}
|
||||
|
||||
/* Protect heap from growing into the reserved MSP stack */
|
||||
if (__sbrk_heap_end + incr > max_heap)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
prev_heap_end = __sbrk_heap_end;
|
||||
__sbrk_heap_end += incr;
|
||||
|
||||
return (void *)prev_heap_end;
|
||||
}
|
332
stm32l4a6zg-f0x.at1/Core/Src/system_stm32l4xx.c
Normal file
332
stm32l4a6zg-f0x.at1/Core/Src/system_stm32l4xx.c
Normal file
@ -0,0 +1,332 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32l4xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
|
||||
*
|
||||
* This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32l4xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* After each device reset the MSI (4 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* This file configures the system clock as follows:
|
||||
*=============================================================================
|
||||
*-----------------------------------------------------------------------------
|
||||
* System Clock source | MSI
|
||||
*-----------------------------------------------------------------------------
|
||||
* SYSCLK(Hz) | 4000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* HCLK(Hz) | 4000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* AHB Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB1 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB2 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_M | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_N | 8
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_P | 7
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_Q | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_R | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI1_P | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI1_Q | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI1_R | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI2_P | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI2_Q | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLSAI2_R | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* Require 48MHz for USB OTG FS, | Disabled
|
||||
* SDIO and RNG clock |
|
||||
*-----------------------------------------------------------------------------
|
||||
*=============================================================================
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32l4xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32l4xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
/* #define USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in Sram else user remap will be done in Flash. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/* The SystemCoreClock variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 4000000U;
|
||||
|
||||
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
|
||||
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
|
||||
const uint32_t MSIRangeTable[12] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
|
||||
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32L4xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void SystemInit(void)
|
||||
{
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
|
||||
#endif
|
||||
|
||||
/* FPU settings ------------------------------------------------------------*/
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
|
||||
* or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* (*) MSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
|
||||
* 4 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
|
||||
* 16 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (***) HSE_VALUE is a constant defined in stm32l4xx_hal.h file (default value
|
||||
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
|
||||
* frequency of the crystal used. Otherwise, this function may
|
||||
* have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
uint32_t tmp, msirange, pllvco, pllsource, pllm, pllr;
|
||||
|
||||
/* Get MSI Range frequency--------------------------------------------------*/
|
||||
if ((RCC->CR & RCC_CR_MSIRGSEL) == 0U)
|
||||
{ /* MSISRANGE from RCC_CSR applies */
|
||||
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
|
||||
}
|
||||
else
|
||||
{ /* MSIRANGE from RCC_CR applies */
|
||||
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
|
||||
}
|
||||
/*MSI frequency range in HZ*/
|
||||
msirange = MSIRangeTable[msirange];
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
switch (RCC->CFGR & RCC_CFGR_SWS)
|
||||
{
|
||||
case 0x00: /* MSI used as system clock source */
|
||||
SystemCoreClock = msirange;
|
||||
break;
|
||||
|
||||
case 0x04: /* HSI used as system clock source */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
|
||||
case 0x08: /* HSE used as system clock source */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
|
||||
case 0x0C: /* PLL used as system clock source */
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
|
||||
SYSCLK = PLL_VCO / PLLR
|
||||
*/
|
||||
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
|
||||
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ;
|
||||
|
||||
switch (pllsource)
|
||||
{
|
||||
case 0x02: /* HSI used as PLL clock source */
|
||||
pllvco = (HSI_VALUE / pllm);
|
||||
break;
|
||||
|
||||
case 0x03: /* HSE used as PLL clock source */
|
||||
pllvco = (HSE_VALUE / pllm);
|
||||
break;
|
||||
|
||||
default: /* MSI used as PLL clock source */
|
||||
pllvco = (msirange / pllm);
|
||||
break;
|
||||
}
|
||||
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U);
|
||||
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U;
|
||||
SystemCoreClock = pllvco/pllr;
|
||||
break;
|
||||
|
||||
default:
|
||||
SystemCoreClock = msirange;
|
||||
break;
|
||||
}
|
||||
/* Compute HCLK clock frequency --------------------------------------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
550
stm32l4a6zg-f0x.at1/Core/Startup/startup_stm32l4a6zgtx.s
Normal file
550
stm32l4a6zg-f0x.at1/Core/Startup/startup_stm32l4a6zgtx.s
Normal file
@ -0,0 +1,550 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file startup_stm32l4a6xx.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32L4A6xx devices vector table GCC toolchain.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address,
|
||||
* - Configure the clock system
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M4 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.fpu softvfp
|
||||
.thumb
|
||||
|
||||
.global g_pfnVectors
|
||||
.global Default_Handler
|
||||
|
||||
/* start address for the initialization values of the .data section.
|
||||
defined in linker script */
|
||||
.word _sidata
|
||||
/* start address for the .data section. defined in linker script */
|
||||
.word _sdata
|
||||
/* end address for the .data section. defined in linker script */
|
||||
.word _edata
|
||||
/* start address for the .bss section. defined in linker script */
|
||||
.word _sbss
|
||||
/* end address for the .bss section. defined in linker script */
|
||||
.word _ebss
|
||||
|
||||
.equ BootRAM, 0xF1E0F85F
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor first
|
||||
* starts execution following a reset event. Only the absolutely
|
||||
* necessary set is performed, after which the application
|
||||
* supplied main() routine is called.
|
||||
* @param None
|
||||
* @retval : None
|
||||
*/
|
||||
|
||||
.section .text.Reset_Handler
|
||||
.weak Reset_Handler
|
||||
.type Reset_Handler, %function
|
||||
Reset_Handler:
|
||||
ldr sp, =_estack /* Set stack pointer */
|
||||
|
||||
/* Call the clock system initialization function.*/
|
||||
bl SystemInit
|
||||
|
||||
/* Copy the data segment initializers from flash to SRAM */
|
||||
ldr r0, =_sdata
|
||||
ldr r1, =_edata
|
||||
ldr r2, =_sidata
|
||||
movs r3, #0
|
||||
b LoopCopyDataInit
|
||||
|
||||
CopyDataInit:
|
||||
ldr r4, [r2, r3]
|
||||
str r4, [r0, r3]
|
||||
adds r3, r3, #4
|
||||
|
||||
LoopCopyDataInit:
|
||||
adds r4, r0, r3
|
||||
cmp r4, r1
|
||||
bcc CopyDataInit
|
||||
|
||||
/* Zero fill the bss segment. */
|
||||
ldr r2, =_sbss
|
||||
ldr r4, =_ebss
|
||||
movs r3, #0
|
||||
b LoopFillZerobss
|
||||
|
||||
FillZerobss:
|
||||
str r3, [r2]
|
||||
adds r2, r2, #4
|
||||
|
||||
LoopFillZerobss:
|
||||
cmp r2, r4
|
||||
bcc FillZerobss
|
||||
|
||||
/* Call static constructors */
|
||||
bl __libc_init_array
|
||||
/* Call the application's entry point.*/
|
||||
bl main
|
||||
|
||||
LoopForever:
|
||||
b LoopForever
|
||||
|
||||
.size Reset_Handler, .-Reset_Handler
|
||||
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor receives an
|
||||
* unexpected interrupt. This simply enters an infinite loop, preserving
|
||||
* the system state for examination by a debugger.
|
||||
*
|
||||
* @param None
|
||||
* @retval : None
|
||||
*/
|
||||
.section .text.Default_Handler,"ax",%progbits
|
||||
Default_Handler:
|
||||
Infinite_Loop:
|
||||
b Infinite_Loop
|
||||
.size Default_Handler, .-Default_Handler
|
||||
/******************************************************************************
|
||||
*
|
||||
* The minimal vector table for a Cortex-M4. Note that the proper constructs
|
||||
* must be placed on this to ensure that it ends up at physical address
|
||||
* 0x0000.0000.
|
||||
*
|
||||
******************************************************************************/
|
||||
.section .isr_vector,"a",%progbits
|
||||
.type g_pfnVectors, %object
|
||||
.size g_pfnVectors, .-g_pfnVectors
|
||||
|
||||
|
||||
g_pfnVectors:
|
||||
.word _estack
|
||||
.word Reset_Handler
|
||||
.word NMI_Handler
|
||||
.word HardFault_Handler
|
||||
.word MemManage_Handler
|
||||
.word BusFault_Handler
|
||||
.word UsageFault_Handler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word SVC_Handler
|
||||
.word DebugMon_Handler
|
||||
.word 0
|
||||
.word PendSV_Handler
|
||||
.word SysTick_Handler
|
||||
.word WWDG_IRQHandler
|
||||
.word PVD_PVM_IRQHandler
|
||||
.word TAMP_STAMP_IRQHandler
|
||||
.word RTC_WKUP_IRQHandler
|
||||
.word FLASH_IRQHandler
|
||||
.word RCC_IRQHandler
|
||||
.word EXTI0_IRQHandler
|
||||
.word EXTI1_IRQHandler
|
||||
.word EXTI2_IRQHandler
|
||||
.word EXTI3_IRQHandler
|
||||
.word EXTI4_IRQHandler
|
||||
.word DMA1_Channel1_IRQHandler
|
||||
.word DMA1_Channel2_IRQHandler
|
||||
.word DMA1_Channel3_IRQHandler
|
||||
.word DMA1_Channel4_IRQHandler
|
||||
.word DMA1_Channel5_IRQHandler
|
||||
.word DMA1_Channel6_IRQHandler
|
||||
.word DMA1_Channel7_IRQHandler
|
||||
.word ADC1_2_IRQHandler
|
||||
.word CAN1_TX_IRQHandler
|
||||
.word CAN1_RX0_IRQHandler
|
||||
.word CAN1_RX1_IRQHandler
|
||||
.word CAN1_SCE_IRQHandler
|
||||
.word EXTI9_5_IRQHandler
|
||||
.word TIM1_BRK_TIM15_IRQHandler
|
||||
.word TIM1_UP_TIM16_IRQHandler
|
||||
.word TIM1_TRG_COM_TIM17_IRQHandler
|
||||
.word TIM1_CC_IRQHandler
|
||||
.word TIM2_IRQHandler
|
||||
.word TIM3_IRQHandler
|
||||
.word TIM4_IRQHandler
|
||||
.word I2C1_EV_IRQHandler
|
||||
.word I2C1_ER_IRQHandler
|
||||
.word I2C2_EV_IRQHandler
|
||||
.word I2C2_ER_IRQHandler
|
||||
.word SPI1_IRQHandler
|
||||
.word SPI2_IRQHandler
|
||||
.word USART1_IRQHandler
|
||||
.word USART2_IRQHandler
|
||||
.word USART3_IRQHandler
|
||||
.word EXTI15_10_IRQHandler
|
||||
.word RTC_Alarm_IRQHandler
|
||||
.word DFSDM1_FLT3_IRQHandler
|
||||
.word TIM8_BRK_IRQHandler
|
||||
.word TIM8_UP_IRQHandler
|
||||
.word TIM8_TRG_COM_IRQHandler
|
||||
.word TIM8_CC_IRQHandler
|
||||
.word ADC3_IRQHandler
|
||||
.word FMC_IRQHandler
|
||||
.word SDMMC1_IRQHandler
|
||||
.word TIM5_IRQHandler
|
||||
.word SPI3_IRQHandler
|
||||
.word UART4_IRQHandler
|
||||
.word UART5_IRQHandler
|
||||
.word TIM6_DAC_IRQHandler
|
||||
.word TIM7_IRQHandler
|
||||
.word DMA2_Channel1_IRQHandler
|
||||
.word DMA2_Channel2_IRQHandler
|
||||
.word DMA2_Channel3_IRQHandler
|
||||
.word DMA2_Channel4_IRQHandler
|
||||
.word DMA2_Channel5_IRQHandler
|
||||
.word DFSDM1_FLT0_IRQHandler
|
||||
.word DFSDM1_FLT1_IRQHandler
|
||||
.word DFSDM1_FLT2_IRQHandler
|
||||
.word COMP_IRQHandler
|
||||
.word LPTIM1_IRQHandler
|
||||
.word LPTIM2_IRQHandler
|
||||
.word OTG_FS_IRQHandler
|
||||
.word DMA2_Channel6_IRQHandler
|
||||
.word DMA2_Channel7_IRQHandler
|
||||
.word LPUART1_IRQHandler
|
||||
.word QUADSPI_IRQHandler
|
||||
.word I2C3_EV_IRQHandler
|
||||
.word I2C3_ER_IRQHandler
|
||||
.word SAI1_IRQHandler
|
||||
.word SAI2_IRQHandler
|
||||
.word SWPMI1_IRQHandler
|
||||
.word TSC_IRQHandler
|
||||
.word LCD_IRQHandler
|
||||
.word AES_IRQHandler
|
||||
.word HASH_RNG_IRQHandler
|
||||
.word FPU_IRQHandler
|
||||
.word CRS_IRQHandler
|
||||
.word I2C4_EV_IRQHandler
|
||||
.word I2C4_ER_IRQHandler
|
||||
.word DCMI_IRQHandler
|
||||
.word CAN2_TX_IRQHandler
|
||||
.word CAN2_RX0_IRQHandler
|
||||
.word CAN2_RX1_IRQHandler
|
||||
.word CAN2_SCE_IRQHandler
|
||||
.word DMA2D_IRQHandler
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Provide weak aliases for each Exception handler to the Default_Handler.
|
||||
* As they are weak aliases, any function with the same name will override
|
||||
* this definition.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
.weak NMI_Handler
|
||||
.thumb_set NMI_Handler,Default_Handler
|
||||
|
||||
.weak HardFault_Handler
|
||||
.thumb_set HardFault_Handler,Default_Handler
|
||||
|
||||
.weak MemManage_Handler
|
||||
.thumb_set MemManage_Handler,Default_Handler
|
||||
|
||||
.weak BusFault_Handler
|
||||
.thumb_set BusFault_Handler,Default_Handler
|
||||
|
||||
.weak UsageFault_Handler
|
||||
.thumb_set UsageFault_Handler,Default_Handler
|
||||
|
||||
.weak SVC_Handler
|
||||
.thumb_set SVC_Handler,Default_Handler
|
||||
|
||||
.weak DebugMon_Handler
|
||||
.thumb_set DebugMon_Handler,Default_Handler
|
||||
|
||||
.weak PendSV_Handler
|
||||
.thumb_set PendSV_Handler,Default_Handler
|
||||
|
||||
.weak SysTick_Handler
|
||||
.thumb_set SysTick_Handler,Default_Handler
|
||||
|
||||
.weak WWDG_IRQHandler
|
||||
.thumb_set WWDG_IRQHandler,Default_Handler
|
||||
|
||||
.weak PVD_PVM_IRQHandler
|
||||
.thumb_set PVD_PVM_IRQHandler,Default_Handler
|
||||
|
||||
.weak TAMP_STAMP_IRQHandler
|
||||
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_WKUP_IRQHandler
|
||||
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak FLASH_IRQHandler
|
||||
.thumb_set FLASH_IRQHandler,Default_Handler
|
||||
|
||||
.weak RCC_IRQHandler
|
||||
.thumb_set RCC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI0_IRQHandler
|
||||
.thumb_set EXTI0_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI1_IRQHandler
|
||||
.thumb_set EXTI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI2_IRQHandler
|
||||
.thumb_set EXTI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI3_IRQHandler
|
||||
.thumb_set EXTI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI4_IRQHandler
|
||||
.thumb_set EXTI4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel1_IRQHandler
|
||||
.thumb_set DMA1_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel2_IRQHandler
|
||||
.thumb_set DMA1_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel3_IRQHandler
|
||||
.thumb_set DMA1_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel4_IRQHandler
|
||||
.thumb_set DMA1_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel5_IRQHandler
|
||||
.thumb_set DMA1_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel6_IRQHandler
|
||||
.thumb_set DMA1_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel7_IRQHandler
|
||||
.thumb_set DMA1_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak ADC1_2_IRQHandler
|
||||
.thumb_set ADC1_2_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_TX_IRQHandler
|
||||
.thumb_set CAN1_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_RX0_IRQHandler
|
||||
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_RX1_IRQHandler
|
||||
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_SCE_IRQHandler
|
||||
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI9_5_IRQHandler
|
||||
.thumb_set EXTI9_5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_BRK_TIM15_IRQHandler
|
||||
.thumb_set TIM1_BRK_TIM15_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_UP_TIM16_IRQHandler
|
||||
.thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_TRG_COM_TIM17_IRQHandler
|
||||
.thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_CC_IRQHandler
|
||||
.thumb_set TIM1_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM2_IRQHandler
|
||||
.thumb_set TIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM3_IRQHandler
|
||||
.thumb_set TIM3_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM4_IRQHandler
|
||||
.thumb_set TIM4_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_EV_IRQHandler
|
||||
.thumb_set I2C1_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_ER_IRQHandler
|
||||
.thumb_set I2C1_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C2_EV_IRQHandler
|
||||
.thumb_set I2C2_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C2_ER_IRQHandler
|
||||
.thumb_set I2C2_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI1_IRQHandler
|
||||
.thumb_set SPI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI2_IRQHandler
|
||||
.thumb_set SPI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART1_IRQHandler
|
||||
.thumb_set USART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART2_IRQHandler
|
||||
.thumb_set USART2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART3_IRQHandler
|
||||
.thumb_set USART3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI15_10_IRQHandler
|
||||
.thumb_set EXTI15_10_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_Alarm_IRQHandler
|
||||
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM1_FLT3_IRQHandler
|
||||
.thumb_set DFSDM1_FLT3_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_BRK_IRQHandler
|
||||
.thumb_set TIM8_BRK_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_UP_IRQHandler
|
||||
.thumb_set TIM8_UP_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_TRG_COM_IRQHandler
|
||||
.thumb_set TIM8_TRG_COM_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM8_CC_IRQHandler
|
||||
.thumb_set TIM8_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak ADC3_IRQHandler
|
||||
.thumb_set ADC3_IRQHandler,Default_Handler
|
||||
|
||||
.weak FMC_IRQHandler
|
||||
.thumb_set FMC_IRQHandler,Default_Handler
|
||||
|
||||
.weak SDMMC1_IRQHandler
|
||||
.thumb_set SDMMC1_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM5_IRQHandler
|
||||
.thumb_set TIM5_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI3_IRQHandler
|
||||
.thumb_set SPI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART4_IRQHandler
|
||||
.thumb_set UART4_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART5_IRQHandler
|
||||
.thumb_set UART5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM6_DAC_IRQHandler
|
||||
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM7_IRQHandler
|
||||
.thumb_set TIM7_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel1_IRQHandler
|
||||
.thumb_set DMA2_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel2_IRQHandler
|
||||
.thumb_set DMA2_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel3_IRQHandler
|
||||
.thumb_set DMA2_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel4_IRQHandler
|
||||
.thumb_set DMA2_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel5_IRQHandler
|
||||
.thumb_set DMA2_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM1_FLT0_IRQHandler
|
||||
.thumb_set DFSDM1_FLT0_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM1_FLT1_IRQHandler
|
||||
.thumb_set DFSDM1_FLT1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DFSDM1_FLT2_IRQHandler
|
||||
.thumb_set DFSDM1_FLT2_IRQHandler,Default_Handler
|
||||
|
||||
.weak COMP_IRQHandler
|
||||
.thumb_set COMP_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM1_IRQHandler
|
||||
.thumb_set LPTIM1_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPTIM2_IRQHandler
|
||||
.thumb_set LPTIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak OTG_FS_IRQHandler
|
||||
.thumb_set OTG_FS_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel6_IRQHandler
|
||||
.thumb_set DMA2_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel7_IRQHandler
|
||||
.thumb_set DMA2_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak LPUART1_IRQHandler
|
||||
.thumb_set LPUART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak QUADSPI_IRQHandler
|
||||
.thumb_set QUADSPI_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_EV_IRQHandler
|
||||
.thumb_set I2C3_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C3_ER_IRQHandler
|
||||
.thumb_set I2C3_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak SAI1_IRQHandler
|
||||
.thumb_set SAI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SAI2_IRQHandler
|
||||
.thumb_set SAI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak SWPMI1_IRQHandler
|
||||
.thumb_set SWPMI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak TSC_IRQHandler
|
||||
.thumb_set TSC_IRQHandler,Default_Handler
|
||||
|
||||
.weak LCD_IRQHandler
|
||||
.thumb_set LCD_IRQHandler,Default_Handler
|
||||
|
||||
.weak AES_IRQHandler
|
||||
.thumb_set AES_IRQHandler,Default_Handler
|
||||
|
||||
.weak HASH_RNG_IRQHandler
|
||||
.thumb_set HASH_RNG_IRQHandler,Default_Handler
|
||||
|
||||
.weak FPU_IRQHandler
|
||||
.thumb_set FPU_IRQHandler,Default_Handler
|
||||
|
||||
.weak CRS_IRQHandler
|
||||
.thumb_set CRS_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C4_EV_IRQHandler
|
||||
.thumb_set I2C4_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C4_ER_IRQHandler
|
||||
.thumb_set I2C4_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak DCMI_IRQHandler
|
||||
.thumb_set DCMI_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_TX_IRQHandler
|
||||
.thumb_set CAN2_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_RX0_IRQHandler
|
||||
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_RX1_IRQHandler
|
||||
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_SCE_IRQHandler
|
||||
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2D_IRQHandler
|
||||
.thumb_set DMA2D_IRQHandler,Default_Handler
|
||||
|
889
stm32l4a6zg-f0x.at1/Core/external_sources/polasek/si5351.c
Normal file
889
stm32l4a6zg-f0x.at1/Core/external_sources/polasek/si5351.c
Normal file
@ -0,0 +1,889 @@
|
||||
/*
|
||||
* si5351.c
|
||||
*
|
||||
* Created on: Jan 14, 2019
|
||||
* Author: Petr Polasek
|
||||
*
|
||||
* To make this library useable on any other device than
|
||||
* STM32Fxxx Cortex Mx, please edit these parts of the library:
|
||||
*
|
||||
* DEFINES:
|
||||
* SI5351_I2C_PERIPHERAL - the I2C peripheral name according
|
||||
* to your devices HAL library
|
||||
* I2C_TIMEOUT - time for the communication to time out
|
||||
*
|
||||
* TYPEDEFS:
|
||||
* Si5351_ConfigTypeDef - the I2Cx parameter should be changed
|
||||
* so that its type corresponds to your HAL library
|
||||
*
|
||||
* FUNCTIONS:
|
||||
* Si5351_WriteRegister
|
||||
* Si5351_ReadRegister
|
||||
* You need to write your own I2C handlers here
|
||||
*
|
||||
*/
|
||||
|
||||
//put your I2C HAL library name here
|
||||
//#include "stm32f10x_i2c.h"
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include "si5351.h"
|
||||
|
||||
int Si5351_WriteRegister(Si5351_ConfigTypeDef *Si5351_ConfigStruct, uint8_t reg_address, uint8_t reg_data)
|
||||
{
|
||||
uint32_t error_wait;
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(Si5351_ConfigStruct->I2Cx, I2C_FLAG_BUSY) == SET)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0)
|
||||
{
|
||||
I2C_SoftwareResetCmd(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
I2C_SoftwareResetCmd(Si5351_ConfigStruct->I2Cx, DISABLE);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
//wait for I2C to get ready, if not ready in time, reset I2C and return
|
||||
|
||||
I2C_GenerateSTART(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
//send START condition
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_MODE_SELECT) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for START to be sent, if not sent in time, return
|
||||
|
||||
I2C_Send7bitAddress(Si5351_ConfigStruct->I2Cx, Si5351_ConfigStruct->HW_I2C_Address, I2C_Direction_Transmitter);
|
||||
//send address+RW bit
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for address to be sent, if not sent in time, return
|
||||
|
||||
I2C_SendData(Si5351_ConfigStruct->I2Cx, reg_address);
|
||||
//send reg address
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for reg address to be sent
|
||||
|
||||
I2C_SendData(Si5351_ConfigStruct->I2Cx, reg_data);
|
||||
//send reg data
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for data to be sent, if not sent in time, return
|
||||
|
||||
I2C_GenerateSTOP(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
//generate STOP condition
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(Si5351_ConfigStruct->I2Cx, I2C_FLAG_STOPF))
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait until STOP is cleared
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t Si5351_ReadRegister(Si5351_ConfigTypeDef *Si5351_ConfigStruct, uint8_t reg_address)
|
||||
{
|
||||
uint32_t error_wait;
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(Si5351_ConfigStruct->I2Cx, I2C_FLAG_BUSY) == SET)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0)
|
||||
{
|
||||
I2C_SoftwareResetCmd(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
I2C_SoftwareResetCmd(Si5351_ConfigStruct->I2Cx, DISABLE);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
//wait for I2C to get ready, if not ready in time, reset I2C and return
|
||||
|
||||
I2C_GenerateSTART(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
//send START condition
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_MODE_SELECT) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for START to be sent, if not sent in time, return
|
||||
|
||||
I2C_Send7bitAddress(Si5351_ConfigStruct->I2Cx, Si5351_ConfigStruct->HW_I2C_Address, I2C_Direction_Transmitter);
|
||||
//send address+RW bit
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for address to be sent, if not sent in time, return
|
||||
|
||||
I2C_SendData(Si5351_ConfigStruct->I2Cx, reg_address);
|
||||
//send reg address
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for reg address to be sent
|
||||
|
||||
I2C_GenerateSTOP(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
//generate STOP condition
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(Si5351_ConfigStruct->I2Cx, I2C_FLAG_STOPF))
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait until STOP is cleared
|
||||
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(Si5351_ConfigStruct->I2Cx, I2C_FLAG_BUSY) == SET)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0)
|
||||
{
|
||||
I2C_SoftwareResetCmd(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
I2C_SoftwareResetCmd(Si5351_ConfigStruct->I2Cx, DISABLE);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
//wait for I2C to get ready, if not ready in time, reset I2C and return
|
||||
|
||||
I2C_GenerateSTART(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
//send START condition
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_MODE_SELECT) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for START to be sent, if not sent in time, return
|
||||
|
||||
I2C_Send7bitAddress(Si5351_ConfigStruct->I2Cx, Si5351_ConfigStruct->HW_I2C_Address, I2C_Direction_Receiver);
|
||||
//send address+RW bit
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for address to be sent, if not sent in time, return
|
||||
|
||||
while (I2C_CheckEvent(Si5351_ConfigStruct->I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) == ERROR)
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait for data
|
||||
|
||||
uint8_t reg_data;
|
||||
reg_data = I2C_ReceiveData(Si5351_ConfigStruct->I2Cx);
|
||||
//receive reg data
|
||||
|
||||
I2C_GenerateSTOP(Si5351_ConfigStruct->I2Cx, ENABLE);
|
||||
//generate STOP condition
|
||||
|
||||
error_wait = I2C_TIMEOUT;
|
||||
while (I2C_GetFlagStatus(Si5351_ConfigStruct->I2Cx, I2C_FLAG_STOPF))
|
||||
{
|
||||
error_wait--;
|
||||
if (error_wait==0) return 1;
|
||||
}
|
||||
//wait until STOP is cleared
|
||||
|
||||
return reg_data;
|
||||
}
|
||||
|
||||
//set safe values in the config structure
|
||||
void Si5351_StructInit(Si5351_ConfigTypeDef *Si5351_ConfigStruct)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
Si5351_ConfigStruct->HW_I2C_Address = SI5351_I2C_ADDRESS;
|
||||
Si5351_ConfigStruct->I2Cx = SI5351_I2C_PERIPHERAL;
|
||||
|
||||
Si5351_ConfigStruct->f_CLKIN = SI5351_CLKIN_FREQ;
|
||||
Si5351_ConfigStruct->f_XTAL = SI5351_XTAL_FREQ;
|
||||
|
||||
Si5351_ConfigStruct->Interrupt_Mask_CLKIN = ON;
|
||||
Si5351_ConfigStruct->Interrupt_Mask_PLLA = ON;
|
||||
Si5351_ConfigStruct->Interrupt_Mask_PLLB = ON;
|
||||
Si5351_ConfigStruct->Interrupt_Mask_SysInit = ON;
|
||||
Si5351_ConfigStruct->Interrupt_Mask_XTAL = ON;
|
||||
|
||||
Si5351_ConfigStruct->Fanout_CLKIN_EN = ON;
|
||||
Si5351_ConfigStruct->Fanout_MS_EN = ON;
|
||||
Si5351_ConfigStruct->Fanout_XO_EN = ON;
|
||||
|
||||
Si5351_ConfigStruct->OSC.CLKIN_Div = CLKINDiv_Div1;
|
||||
Si5351_ConfigStruct->OSC.OSC_XTAL_Load = XTAL_Load_10_pF;
|
||||
Si5351_ConfigStruct->OSC.VCXO_Pull_Range_ppm = 0; //maybe should be set to 30 ppm, not clear from the AN-619
|
||||
|
||||
for (i=0; i<=1; i++)
|
||||
{
|
||||
Si5351_ConfigStruct->PLL[i].PLL_Clock_Source = PLL_Clock_Source_XTAL;
|
||||
Si5351_ConfigStruct->PLL[i].PLL_Multiplier_Integer = 32; //range 24..36 for 25 MHz clock
|
||||
Si5351_ConfigStruct->PLL[i].PLL_Multiplier_Numerator = 0; //range 0..1048575
|
||||
Si5351_ConfigStruct->PLL[i].PLL_Multiplier_Denominator = 1; //range 1..1048575
|
||||
Si5351_ConfigStruct->PLL[i].PLL_Capacitive_Load = PLL_Capacitive_Load_0; //select 0, unless you want to tune the PLL to <200 MHZ
|
||||
}
|
||||
|
||||
Si5351_ConfigStruct->SS.SS_Amplitude_ppm = 0; //1.5% modulation = 15000
|
||||
Si5351_ConfigStruct->SS.SS_Enable = OFF;
|
||||
Si5351_ConfigStruct->SS.SS_Mode = SS_Mode_CenterSpread;
|
||||
Si5351_ConfigStruct->SS.SS_NCLK = SS_NCLK_0; //default value, this parameter is unexplained in documentation
|
||||
|
||||
for (i=0; i<=7; i++)
|
||||
{
|
||||
Si5351_ConfigStruct->MS[i].MS_Clock_Source = MS_Clock_Source_PLLA;
|
||||
Si5351_ConfigStruct->MS[i].MS_Divider_Integer = 4;
|
||||
Si5351_ConfigStruct->MS[i].MS_Divider_Numerator = 0;
|
||||
Si5351_ConfigStruct->MS[i].MS_Divider_Denominator = 1;
|
||||
|
||||
Si5351_ConfigStruct->CLK[i].CLK_Clock_Source = CLK_Clock_Source_MS_Own;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_Disable_State = CLK_Disable_State_HIGH_Z;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_Enable = OFF;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_I_Drv = CLK_I_Drv_8mA;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_Invert = OFF;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_PowerDown = OFF;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_QuarterPeriod_Offset = 0;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_R_Div = CLK_R_Div1;
|
||||
Si5351_ConfigStruct->CLK[i].CLK_Use_OEB_Pin = OFF;
|
||||
}
|
||||
}
|
||||
|
||||
void Si5351_OSCConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct)
|
||||
{
|
||||
uint8_t tmp;
|
||||
uint32_t VCXO_Param;
|
||||
|
||||
//set XTAL capacitive load and PLL VCO load capacitance
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_XTAL_CL);
|
||||
tmp &= ~(XTAL_CL_MASK | PLL_CL_MASK);
|
||||
tmp |= (XTAL_CL_MASK & (Si5351_ConfigStruct->OSC.OSC_XTAL_Load)) | (PLL_CL_MASK & ((Si5351_ConfigStruct->PLL[0].PLL_Capacitive_Load) << 1)) | (PLL_CL_MASK & ((Si5351_ConfigStruct->PLL[1].PLL_Capacitive_Load) << 4));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_XTAL_CL, tmp);
|
||||
|
||||
//set CLKIN pre-divider
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLKIN_DIV);
|
||||
tmp &= ~CLKIN_MASK;
|
||||
tmp |= CLKIN_MASK & Si5351_ConfigStruct->OSC.CLKIN_Div;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLKIN_DIV, tmp);
|
||||
|
||||
//set fanout of XO, MS0, MS4 and CLKIN - should be always on unless you
|
||||
//need to reduce power consumption
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_FANOUT_EN);
|
||||
tmp &= ~(FANOUT_CLKIN_EN_MASK | FANOUT_MS_EN_MASK | FANOUT_XO_EN_MASK);
|
||||
if (Si5351_ConfigStruct->Fanout_CLKIN_EN == ON) tmp |= FANOUT_CLKIN_EN_MASK;
|
||||
if (Si5351_ConfigStruct->Fanout_MS_EN == ON) tmp |= FANOUT_MS_EN_MASK;
|
||||
if (Si5351_ConfigStruct->Fanout_XO_EN == ON) tmp |= FANOUT_XO_EN_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_FANOUT_EN, tmp);
|
||||
|
||||
//if "b" in PLLB set to 10^6, set VCXO parameter
|
||||
if (Si5351_ConfigStruct->PLL[1].PLL_Multiplier_Denominator == 1000000)
|
||||
{
|
||||
VCXO_Param = VCXO_PARAM_MASK & (uint32_t)
|
||||
((103 * Si5351_ConfigStruct->OSC.VCXO_Pull_Range_ppm
|
||||
* ((uint64_t)128000000 * Si5351_ConfigStruct->PLL[1].PLL_Multiplier_Integer +
|
||||
Si5351_ConfigStruct->PLL[1].PLL_Multiplier_Numerator))/100000000);
|
||||
} else {
|
||||
VCXO_Param = 0;
|
||||
}
|
||||
|
||||
tmp = (uint8_t) VCXO_Param;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_VCXO_PARAM_0_7, tmp);
|
||||
tmp = (uint8_t)(VCXO_Param>>8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_VCXO_PARAM_8_15, tmp);
|
||||
tmp = (uint8_t)((VCXO_Param>>16) & VCXO_PARAM_16_21_MASK);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_VCXO_PARAM_16_21, tmp);
|
||||
}
|
||||
|
||||
EnableState Si5351_CheckStatusBit(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_StatusBitTypeDef StatusBit)
|
||||
{
|
||||
uint8_t tmp;
|
||||
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_DEV_STATUS);
|
||||
tmp &= StatusBit;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
EnableState Si5351_CheckStickyBit(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_StatusBitTypeDef StatusBit)
|
||||
{
|
||||
uint8_t tmp;
|
||||
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_DEV_STICKY);
|
||||
tmp &= StatusBit;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void Si5351_InterruptConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct)
|
||||
{
|
||||
uint8_t tmp;
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_INT_MASK);
|
||||
|
||||
tmp &= ~INT_MASK_LOS_XTAL_MASK;
|
||||
if (Si5351_ConfigStruct->Interrupt_Mask_XTAL == ON)
|
||||
{
|
||||
tmp |= INT_MASK_LOS_XTAL_MASK;
|
||||
}
|
||||
|
||||
tmp &= ~INT_MASK_LOS_CLKIN_MASK;
|
||||
if (Si5351_ConfigStruct->Interrupt_Mask_CLKIN == ON)
|
||||
{
|
||||
tmp |= INT_MASK_LOS_CLKIN_MASK;
|
||||
}
|
||||
|
||||
tmp &= ~INT_MASK_LOL_A_MASK;
|
||||
if (Si5351_ConfigStruct->Interrupt_Mask_PLLA == ON)
|
||||
{
|
||||
tmp |= INT_MASK_LOL_A_MASK;
|
||||
}
|
||||
|
||||
tmp &= ~INT_MASK_LOL_B_MASK;
|
||||
if (Si5351_ConfigStruct->Interrupt_Mask_PLLB == ON)
|
||||
{
|
||||
tmp |= INT_MASK_LOL_B_MASK;
|
||||
}
|
||||
|
||||
tmp &= ~INT_MASK_SYS_INIT_MASK;
|
||||
if (Si5351_ConfigStruct->Interrupt_Mask_SysInit == ON)
|
||||
{
|
||||
tmp |= INT_MASK_SYS_INIT_MASK;
|
||||
}
|
||||
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_INT_MASK, tmp);
|
||||
}
|
||||
|
||||
void Si5351_ClearStickyBit(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_StatusBitTypeDef StatusBit)
|
||||
{
|
||||
uint8_t tmp;
|
||||
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_DEV_STICKY);
|
||||
tmp &= ~StatusBit;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_DEV_STICKY, tmp);
|
||||
}
|
||||
|
||||
void Si5351_PLLConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_PLLChannelTypeDef PLL_Channel)
|
||||
{
|
||||
uint8_t tmp, tmp_mask;
|
||||
uint32_t MSN_P1, MSN_P2, MSN_P3;
|
||||
|
||||
//set PLL clock source
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_PLL_CLOCK_SOURCE);
|
||||
tmp_mask = PLLA_CLOCK_SOURCE_MASK << PLL_Channel;
|
||||
tmp &= ~tmp_mask;
|
||||
tmp |= tmp_mask & Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Clock_Source;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_PLL_CLOCK_SOURCE, tmp);
|
||||
|
||||
//if new multiplier not even integer, disable the integer mode
|
||||
if ((Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Numerator != 0) | ((Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Integer & 0x01) != 0 ))
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_FB_INT + PLL_Channel);
|
||||
tmp &= ~FB_INT_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_FB_INT + PLL_Channel, tmp);
|
||||
}
|
||||
|
||||
//configure the PLL multiplier
|
||||
MSN_P1 = 128 * Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Integer + ((128 * Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Numerator) / Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Denominator) - 512;
|
||||
MSN_P2 = 128 * Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Numerator - Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Denominator * ((128 * Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Numerator) / Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Denominator);
|
||||
MSN_P3 = Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Denominator;
|
||||
|
||||
tmp = (uint8_t) MSN_P1;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P1_0_7 + 8 * PLL_Channel, tmp);
|
||||
tmp = (uint8_t) (MSN_P1 >> 8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P1_8_15 + 8 * PLL_Channel, tmp);
|
||||
tmp = (uint8_t) (MSN_P1_16_17_MASK & (MSN_P1 >> 16));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P1_16_17 + 8 * PLL_Channel, tmp);
|
||||
|
||||
tmp = (uint8_t) MSN_P2;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P2_0_7 + 8 * PLL_Channel, tmp);
|
||||
tmp = (uint8_t) (MSN_P2 >> 8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P2_8_15 + 8 * PLL_Channel, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MSN_P2_16_19);
|
||||
tmp &= ~MSN_P2_16_19_MASK;
|
||||
tmp |= (uint8_t) (MSN_P2_16_19_MASK & (MSN_P2 >> 16));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P2_16_19 + 8 * PLL_Channel, tmp);
|
||||
|
||||
tmp = (uint8_t) MSN_P3;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P3_0_7 + 8 * PLL_Channel, tmp);
|
||||
tmp = (uint8_t) (MSN_P3 >> 8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P3_8_15 + 8 * PLL_Channel, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MSN_P3_16_19);
|
||||
tmp &= ~MSN_P3_16_19_MASK;
|
||||
tmp |= (uint8_t) (MSN_P3_16_19_MASK & ((MSN_P3 >> 16) << 4));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MSN_P3_16_19 + 8 * PLL_Channel, tmp);
|
||||
|
||||
//if new multiplier is an even integer, enable integer mode
|
||||
if ((Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Numerator == 0) & ((Si5351_ConfigStruct->PLL[PLL_Channel].PLL_Multiplier_Integer & 0x01) == 0 ))
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_FB_INT + PLL_Channel);
|
||||
tmp |= FB_INT_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_FB_INT + PLL_Channel, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void Si5351_PLLReset(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_PLLChannelTypeDef PLL_Channel)
|
||||
{
|
||||
uint8_t tmp;
|
||||
|
||||
//reset PLL
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_PLL_RESET);
|
||||
if (PLL_Channel == PLL_A)
|
||||
{
|
||||
tmp |= PLLA_RESET_MASK;
|
||||
} else {
|
||||
tmp |= PLLB_RESET_MASK;
|
||||
}
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_PLL_RESET, tmp);
|
||||
}
|
||||
|
||||
void Si5351_PLLSimultaneousReset(Si5351_ConfigTypeDef *Si5351_ConfigStruct)
|
||||
{
|
||||
uint8_t tmp;
|
||||
|
||||
//reset PLL
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_PLL_RESET);
|
||||
tmp |= PLLA_RESET_MASK | PLLB_RESET_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_PLL_RESET, tmp);
|
||||
}
|
||||
|
||||
void Si5351_SSConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct)
|
||||
{
|
||||
uint8_t tmp;
|
||||
uint32_t SSUDP, SSUP_P1, SSUP_P2, SSUP_P3, SSDN_P1, SSDN_P2, SSDN_P3;
|
||||
uint64_t SSDN, SSUP;
|
||||
|
||||
//turn off SS if it should be disabled
|
||||
if ((Si5351_ConfigStruct->SS.SS_Enable == OFF)|
|
||||
(((Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Integer & 0x01) == 0)
|
||||
& (Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Numerator == 0)) )
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSC_EN);
|
||||
tmp &= ~SSC_EN_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSC_EN, tmp);
|
||||
}
|
||||
|
||||
//set default value of SS_NCLK - spread spectrum reserved register
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SS_NCLK);
|
||||
tmp &= ~SS_NCLK_MASK;
|
||||
tmp |= SS_NCLK_MASK & (Si5351_ConfigStruct->SS.SS_NCLK);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SS_NCLK, tmp);
|
||||
|
||||
//set SS mode
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSC_MODE);
|
||||
tmp &= ~SSC_MODE_MASK;
|
||||
tmp |= SSC_MODE_MASK & Si5351_ConfigStruct->SS.SS_Mode;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSC_MODE, tmp);
|
||||
|
||||
//set SSUDP parameter
|
||||
if (Si5351_ConfigStruct->PLL[0].PLL_Clock_Source == PLL_Clock_Source_CLKIN)
|
||||
{
|
||||
SSUDP = (Si5351_ConfigStruct->f_CLKIN)/(4*31500);
|
||||
} else {
|
||||
SSUDP = (Si5351_ConfigStruct->f_XTAL)/(4*31500);
|
||||
}
|
||||
|
||||
//set SSUDP parameter
|
||||
tmp = (uint8_t) SSUDP;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUDP_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSUDP_8_11);
|
||||
tmp &= ~SSUDP_8_11_MASK;
|
||||
tmp |= (uint8_t) (SSUDP_8_11_MASK & ((SSUDP >> 8) << 4));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUDP_8_11, tmp);
|
||||
|
||||
//calculate SSUP and SSDN parameters
|
||||
if (Si5351_ConfigStruct->SS.SS_Mode == SS_Mode_CenterSpread)
|
||||
{
|
||||
SSUP = ((uint64_t)(64000000*Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Integer
|
||||
+ (64000000*Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Numerator)/(Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Denominator)
|
||||
) * Si5351_ConfigStruct->SS.SS_Amplitude_ppm
|
||||
) / ((1000000 - Si5351_ConfigStruct->SS.SS_Amplitude_ppm) * SSUDP);
|
||||
|
||||
SSDN = ((uint64_t)(64000000*Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Integer
|
||||
+ (64000000*Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Numerator)/(Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Denominator)
|
||||
) * Si5351_ConfigStruct->SS.SS_Amplitude_ppm
|
||||
) / ((1000000 + Si5351_ConfigStruct->SS.SS_Amplitude_ppm) * SSUDP);
|
||||
|
||||
SSUP_P1 = (uint32_t) (SSUP/1000000);
|
||||
SSUP_P2 = (uint32_t)(32767*(SSUP/1000000-SSUP_P1));
|
||||
SSUP_P3 = 0x7FFF;
|
||||
|
||||
} else {
|
||||
|
||||
SSDN = ((uint64_t)(64000000*Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Integer
|
||||
+ (64000000*Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Numerator)/(Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Denominator)
|
||||
) * Si5351_ConfigStruct->SS.SS_Amplitude_ppm
|
||||
) / ((1000000 + Si5351_ConfigStruct->SS.SS_Amplitude_ppm) * SSUDP);
|
||||
|
||||
SSUP_P1 = 0;
|
||||
SSUP_P2 = 0;
|
||||
SSUP_P3 = 1;
|
||||
|
||||
}
|
||||
|
||||
//set SSDN parameter
|
||||
SSDN_P1 = (uint32_t) (SSDN/1000000);
|
||||
SSDN_P2 = (uint32_t)(32767*(SSDN/1000000-SSDN_P1));
|
||||
SSDN_P3 = 0x7FFF;
|
||||
|
||||
//write SSUP parameter P1
|
||||
tmp = (uint8_t) SSUP_P1;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUP_P1_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSUP_P1_8_11);
|
||||
tmp &= ~SSUP_P1_8_11_MASK;
|
||||
tmp |= (uint8_t)(SSUP_P1_8_11_MASK & (SSUP_P1 >> 8));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUP_P1_8_11, tmp);
|
||||
|
||||
//write SSUP parameter P2
|
||||
tmp = (uint8_t) SSUP_P2;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUP_P2_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSUP_P2_8_14);
|
||||
tmp &= ~SSUP_P2_8_14_MASK;
|
||||
tmp |= (uint8_t)(SSUP_P2_8_14_MASK & (SSUP_P2 >> 8));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUP_P2_8_14, tmp);
|
||||
|
||||
//write SSUP parameter P3
|
||||
tmp = (uint8_t) SSUP_P3;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUP_P3_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSUP_P3_8_14);
|
||||
tmp &= ~SSUP_P3_8_14_MASK;
|
||||
tmp |= (uint8_t)(SSUP_P3_8_14_MASK & (SSUP_P3 >> 8));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSUP_P3_8_14, tmp);
|
||||
|
||||
//write SSDN parameter P1
|
||||
tmp = (uint8_t) SSDN_P1;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSDN_P1_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSDN_P1_8_11);
|
||||
tmp &= ~SSDN_P1_8_11_MASK;
|
||||
tmp |= (uint8_t)(SSDN_P1_8_11_MASK & (SSDN_P1 >> 8));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSDN_P1_8_11, tmp);
|
||||
|
||||
//write SSDN parameter P2
|
||||
tmp = (uint8_t) SSDN_P2;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSDN_P2_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSDN_P2_8_14);
|
||||
tmp &= ~SSDN_P2_8_14_MASK;
|
||||
tmp |= (uint8_t)(SSDN_P2_8_14_MASK & (SSDN_P2 >> 8));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSDN_P2_8_14, tmp);
|
||||
|
||||
//write SSDN parameter P3
|
||||
tmp = (uint8_t) SSDN_P3;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSDN_P3_0_7, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSDN_P3_8_14);
|
||||
tmp &= ~SSDN_P3_8_14_MASK;
|
||||
tmp |= (uint8_t)(SSDN_P3_8_14_MASK & (SSDN_P3 >> 8));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSDN_P3_8_14, tmp);
|
||||
|
||||
//turn on SS if it should be enabled
|
||||
if ((Si5351_ConfigStruct->SS.SS_Enable == ON)
|
||||
& (((Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Integer & 0x01) != 0)
|
||||
| (Si5351_ConfigStruct->PLL[0].PLL_Multiplier_Numerator != 0)))
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_SSC_EN);
|
||||
tmp |= SSC_EN_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_SSC_EN, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void Si5351_MSConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_MSChannelTypeDef MS_Channel)
|
||||
{
|
||||
uint8_t tmp;
|
||||
uint32_t MS_P1, MS_P2, MS_P3;
|
||||
|
||||
//configure MultiSynth clock source
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_SRC + MS_Channel);
|
||||
tmp &= ~MS_SRC_MASK;
|
||||
if (Si5351_ConfigStruct->MS[MS_Channel].MS_Clock_Source == MS_Clock_Source_PLLB)
|
||||
{
|
||||
tmp |= MS_SRC_MASK;
|
||||
}
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_SRC + MS_Channel, tmp);
|
||||
|
||||
if (MS_Channel <= MS5) //configuration is simpler for MS6 and 7 since they are integer-only
|
||||
{
|
||||
//if next value not in even integer mode or if divider is not equal to 4, disable DIVBY4
|
||||
if ((Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Integer != 4)|(Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Numerator != 0))
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_DIVBY4 + 8 * MS_Channel);
|
||||
tmp &= ~MS_DIVBY4_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_DIVBY4 + 8 * MS_Channel, tmp);
|
||||
}
|
||||
|
||||
//if next value not in even integer mode or SS enabled, disable integer mode
|
||||
if ((Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Numerator != 0)|((Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Integer & 0x01) != 0)|(Si5351_ConfigStruct->SS.SS_Enable == ON))
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_INT + MS_Channel);
|
||||
tmp &= ~MS_INT_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_INT + MS_Channel, tmp);
|
||||
}
|
||||
|
||||
//set new divider value
|
||||
MS_P1 = 128 * Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Integer
|
||||
+ ((128 * Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Numerator) / Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Denominator)
|
||||
- 512;
|
||||
MS_P2 = 128 * Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Numerator
|
||||
- Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Denominator
|
||||
* ((128 * Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Numerator) / Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Denominator);
|
||||
MS_P3 = Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Denominator;
|
||||
|
||||
tmp = (uint8_t) MS_P1;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P1_0_7 + 8 * MS_Channel, tmp);
|
||||
tmp = (uint8_t) (MS_P1 >> 8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P1_8_15 + 8 * MS_Channel, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_P1_16_17);
|
||||
tmp &= ~MS_P1_16_17_MASK;
|
||||
tmp |= (uint8_t) (MS_P1_16_17_MASK & (MS_P1 >> 16));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P1_16_17 + 8 * MS_Channel, tmp);
|
||||
|
||||
tmp = (uint8_t) MS_P2;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P2_0_7 + 8 * MS_Channel, tmp);
|
||||
tmp = (uint8_t) (MS_P2 >> 8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P2_8_15 + 8 * MS_Channel, tmp);
|
||||
Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_P2_16_19 + 8 * MS_Channel);
|
||||
tmp &= ~MS_P2_16_19_MASK;
|
||||
tmp |= (uint8_t) (MS_P2_16_19_MASK & (MS_P2 >> 16));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P2_16_19 + 8 * MS_Channel, tmp);
|
||||
|
||||
tmp = (uint8_t) MS_P3;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P3_0_7 + 8 * MS_Channel, tmp);
|
||||
tmp = (uint8_t) (MS_P3 >> 8);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P3_8_15 + 8 * MS_Channel, tmp);
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_P3_16_19 + 8 * MS_Channel);
|
||||
tmp &= ~MS_P3_16_19_MASK;
|
||||
tmp |= (uint8_t) (MS_P3_16_19_MASK & ((MS_P3 >> 16) << 4));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_P3_16_19 + 8 * MS_Channel, tmp);
|
||||
|
||||
//if next value is even integer and SS not enabled, enable integer mode
|
||||
if ((Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Numerator == 0) & ((Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Integer & 0x01) == 0) & (Si5351_ConfigStruct->SS.SS_Enable == OFF))
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_INT + MS_Channel);
|
||||
tmp |= MS_INT_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_INT + MS_Channel, tmp);
|
||||
|
||||
//if next value in integer mode and if divider is equal to 4, enable DIVBY4
|
||||
if (Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Integer == 4)
|
||||
{
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_MS_DIVBY4 + 8 * MS_Channel);
|
||||
tmp |= MS_DIVBY4_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS_DIVBY4 + 8 * MS_Channel, tmp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//configure divider of Multisynth 6 and 7
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_MS67_P1 + (MS_Channel - MS6), (uint8_t)(Si5351_ConfigStruct->MS[MS_Channel].MS_Divider_Integer));
|
||||
//can be only even integers between 6 and 254, inclusive
|
||||
}
|
||||
}
|
||||
|
||||
void Si5351_CLKPowerCmd(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_CLKChannelTypeDef CLK_Channel)
|
||||
{
|
||||
uint8_t tmp, tmp_mask;
|
||||
|
||||
//set CLK disable state
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_DIS_STATE + (CLK_Channel >> 2)); //increment the address by 1 if CLKx>=CLK4
|
||||
tmp_mask = CLK_DIS_STATE_MASK << ((CLK_Channel & 0x03)<<1); //shift the mask according to the selected channel
|
||||
tmp &= ~tmp_mask;
|
||||
tmp |= tmp_mask & ((Si5351_ConfigStruct->CLK[CLK_Channel].CLK_Disable_State) << ((CLK_Channel & 0x03)<<1));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_DIS_STATE + (CLK_Channel >> 2), tmp);
|
||||
|
||||
//set OEB pin
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_OEB);
|
||||
tmp_mask = 1 << CLK_Channel;
|
||||
tmp &= ~tmp_mask;
|
||||
if (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_Use_OEB_Pin == OFF)
|
||||
{
|
||||
tmp |= tmp_mask;
|
||||
}
|
||||
|
||||
if (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_Enable == OFF) //disable clock
|
||||
{
|
||||
//power down the clock
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_EN);
|
||||
tmp |= 1 << CLK_Channel;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_EN, tmp);
|
||||
}
|
||||
|
||||
if (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_PowerDown == ON) //power down clock
|
||||
{
|
||||
//power down output driver
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_PDN + CLK_Channel);
|
||||
tmp |= CLK_PDN_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_PDN + CLK_Channel, tmp);
|
||||
}
|
||||
|
||||
if (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_PowerDown == OFF) //power up clock
|
||||
{
|
||||
//power up output driver
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_PDN + CLK_Channel);
|
||||
tmp &= ~CLK_PDN_MASK;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_PDN + CLK_Channel, tmp);
|
||||
}
|
||||
|
||||
if (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_Enable == ON) //enable clock
|
||||
{
|
||||
//power up the clock
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_EN);
|
||||
tmp &= ~(1 << CLK_Channel);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_EN, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void Si5351_CLKConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_CLKChannelTypeDef CLK_Channel)
|
||||
{
|
||||
uint8_t tmp, tmp_mask;
|
||||
|
||||
//set CLK source clock
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_SRC + CLK_Channel);
|
||||
tmp &= ~CLK_SRC_MASK;
|
||||
tmp |= CLK_SRC_MASK & Si5351_ConfigStruct->CLK[CLK_Channel].CLK_Clock_Source;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_SRC + CLK_Channel, tmp);
|
||||
|
||||
//set CLK inversion
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_INV + CLK_Channel);
|
||||
tmp &= ~CLK_INV_MASK;
|
||||
if (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_Invert == ON)
|
||||
{
|
||||
tmp |= CLK_INV_MASK;
|
||||
}
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_INV + CLK_Channel, tmp);
|
||||
|
||||
//set CLK current drive
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_IDRV + CLK_Channel);
|
||||
tmp &= ~CLK_IDRV_MASK;
|
||||
tmp |= CLK_IDRV_MASK & Si5351_ConfigStruct->CLK[CLK_Channel].CLK_I_Drv;
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_IDRV + CLK_Channel, tmp);
|
||||
|
||||
if (CLK_Channel <= CLK5) //CLK6 and 7 are integer only, which causes several limitations
|
||||
{
|
||||
//set CLK phase offset
|
||||
tmp = CLK_PHOFF_MASK & (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_QuarterPeriod_Offset);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_PHOFF + CLK_Channel, tmp);
|
||||
//set Rx divider
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_R_DIV + CLK_Channel * CLK_R_DIV_STEP);
|
||||
tmp &= ~CLK_R_DIV_MASK;
|
||||
tmp |= CLK_R_DIV_MASK & (Si5351_ConfigStruct->CLK[CLK_Channel].CLK_R_Div);
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_R_DIV + CLK_Channel * CLK_R_DIV_STEP, tmp);
|
||||
} else {
|
||||
//CLK6 and CLK7 have no fractional mode, so they lack the phase offset function
|
||||
|
||||
//set Rx divider
|
||||
tmp_mask = CLK_R67_DIV_MASK << ((CLK_Channel-CLK6) << 2); //shift mask left by 4 if CLK7
|
||||
tmp = Si5351_ReadRegister(Si5351_ConfigStruct, REG_CLK_R67_DIV);
|
||||
tmp &= ~tmp_mask;
|
||||
tmp |= tmp_mask & ((Si5351_ConfigStruct->CLK[CLK_Channel].CLK_R_Div >> 4) << ((CLK_Channel-CLK6) << 2));
|
||||
Si5351_WriteRegister(Si5351_ConfigStruct, REG_CLK_R67_DIV, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
int Si5351_Init(Si5351_ConfigTypeDef *Si5351_ConfigStruct)
|
||||
{
|
||||
uint32_t timeout = SI5351_TIMEOUT;
|
||||
uint8_t i;
|
||||
|
||||
//wait for the 5351 to initialize
|
||||
while (Si5351_CheckStatusBit(Si5351_ConfigStruct, StatusBit_SysInit))
|
||||
{
|
||||
timeout--;
|
||||
if (timeout==0) return 1; //return 1 if initialization timed out
|
||||
}
|
||||
|
||||
//configure oscillator, fanout, interrupts, VCXO
|
||||
Si5351_OSCConfig(Si5351_ConfigStruct);
|
||||
Si5351_InterruptConfig(Si5351_ConfigStruct);
|
||||
|
||||
//configure PLLs
|
||||
for (i=PLL_A; i<=PLL_B; i++)
|
||||
{
|
||||
Si5351_PLLConfig(Si5351_ConfigStruct, i);
|
||||
Si5351_PLLReset(Si5351_ConfigStruct, i);
|
||||
}
|
||||
|
||||
//configure Spread Spectrum
|
||||
Si5351_SSConfig(Si5351_ConfigStruct);
|
||||
|
||||
//Configure Multisynths
|
||||
for (i=MS0; i<=MS7; i++)
|
||||
{
|
||||
Si5351_MSConfig(Si5351_ConfigStruct, i);
|
||||
}
|
||||
|
||||
//configure outputs
|
||||
for (i=CLK0; i<=CLK7; i++)
|
||||
{
|
||||
Si5351_CLKConfig(Si5351_ConfigStruct, i);
|
||||
}
|
||||
|
||||
//wait for PLLs to lock
|
||||
while (Si5351_CheckStatusBit(Si5351_ConfigStruct, StatusBit_SysInit | StatusBit_PLLA | StatusBit_PLLB))
|
||||
{
|
||||
timeout--;
|
||||
if (timeout==0) return 1; //return 1 if problem with any PLL
|
||||
}
|
||||
|
||||
//clear sticky bits
|
||||
Si5351_ClearStickyBit(Si5351_ConfigStruct, StatusBit_SysInit | StatusBit_PLLA | StatusBit_PLLB);
|
||||
|
||||
if (Si5351_ConfigStruct->f_CLKIN != 0) //if CLKIN used, check it as well
|
||||
{
|
||||
while (Si5351_CheckStatusBit(Si5351_ConfigStruct, StatusBit_CLKIN))
|
||||
{
|
||||
timeout--;
|
||||
if (timeout==0) return 1; //return 1 if initialization timed out
|
||||
}
|
||||
//clear CLKIN sticky bit
|
||||
Si5351_ClearStickyBit(Si5351_ConfigStruct, StatusBit_CLKIN);
|
||||
}
|
||||
|
||||
if (Si5351_ConfigStruct->f_XTAL != 0) //if XTAL used, check it as well
|
||||
{
|
||||
while (Si5351_CheckStatusBit(Si5351_ConfigStruct, StatusBit_XTAL))
|
||||
{
|
||||
timeout--;
|
||||
if (timeout==0) return 1; //return 1 if initialization timed out
|
||||
}
|
||||
//clear XTAL sticky bit
|
||||
Si5351_ClearStickyBit(Si5351_ConfigStruct, StatusBit_XTAL);
|
||||
}
|
||||
|
||||
//power on or off the outputs
|
||||
for (i=CLK0; i<=CLK7; i++)
|
||||
{
|
||||
Si5351_CLKPowerCmd(Si5351_ConfigStruct, i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
525
stm32l4a6zg-f0x.at1/Core/external_sources/polasek/si5351.h
Normal file
525
stm32l4a6zg-f0x.at1/Core/external_sources/polasek/si5351.h
Normal file
@ -0,0 +1,525 @@
|
||||
/*
|
||||
* si5351.h
|
||||
*
|
||||
* Created on: Feb 16, 2018
|
||||
* Author: Petr Polasek
|
||||
*
|
||||
* To make this library useable on any other device than
|
||||
* STM32Fxxx Cortex Mx, please edit these parts of the library:
|
||||
*
|
||||
* DEFINES:
|
||||
* SI5351_I2C_PERIPHERAL - the I2C peripheral name according
|
||||
* to your devices HAL library
|
||||
* I2C_TIMEOUT - time for the communication to time out
|
||||
*
|
||||
* TYPEDEFS:
|
||||
* Si5351_ConfigTypeDef - the I2Cx parameter should be changed
|
||||
* so that its type corresponds to your HAL library
|
||||
*
|
||||
* FUNCTIONS:
|
||||
* Si5351_WriteRegister
|
||||
* Si5351_ReadRegister
|
||||
* You need to write your own I2C handlers here
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SI5351_H_
|
||||
#define SI5351_H_
|
||||
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#define SI5351_I2C_ADDRESS 0xC0 //default I2C address of Si5351
|
||||
#define SI5351_I2C_PERIPHERAL I2C1 //default I2C interface
|
||||
|
||||
#define SI5351_XTAL_FREQ 25000000 // sets default value, 25000000 for 25 MHz, 27000000 for 27 MHz
|
||||
#define SI5351_CLKIN_FREQ 0 // set in Hz
|
||||
|
||||
#ifdef I2C_TIMEOUT
|
||||
#undef I2C_TIMEOUT
|
||||
#endif
|
||||
#define I2C_TIMEOUT 100000 //I2C timeout for wait loops
|
||||
|
||||
#define SI5351_TIMEOUT (I2C_TIMEOUT * 10)
|
||||
|
||||
#ifndef ENABLESTATE
|
||||
#define ENABLESTATE
|
||||
typedef enum
|
||||
{
|
||||
OFF = 0,
|
||||
ON = 1
|
||||
} EnableState;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This section contains register addresses and bit masks for
|
||||
* the device status registers.
|
||||
*/
|
||||
|
||||
#define REG_DEV_STATUS 0
|
||||
#define DEV_SYS_INIT_MASK 0x80
|
||||
#define DEV_LOL_B_MASK 0x40
|
||||
#define DEV_LOL_A_MASK 0x20
|
||||
#define DEV_LOS_CLKIN_MASK 0x10
|
||||
#define DEV_LOS_XTAL_MASK 0x08
|
||||
#define DEV_REVID_MASK 0x03
|
||||
|
||||
#define REG_DEV_STICKY 1
|
||||
#define DEV_STKY_SYS_INIT_MASK 0x80
|
||||
#define DEV_STKY_LOL_B_MASK 0x40
|
||||
#define DEV_STKY_LOL_A_MASK 0x20
|
||||
#define DEV_STKY_LOS_CLKIN_MASK 0x10
|
||||
#define DEV_STKY_LOS_XTAL_MASK 0x08
|
||||
|
||||
#define REG_INT_MASK 2
|
||||
#define INT_MASK_SYS_INIT_MASK 0x80
|
||||
#define INT_MASK_LOL_B_MASK 0x40
|
||||
#define INT_MASK_LOL_A_MASK 0x20
|
||||
#define INT_MASK_LOS_CLKIN_MASK 0x10
|
||||
#define INT_MASK_LOS_XTAL_MASK 0x08
|
||||
|
||||
/*
|
||||
* This section contains data structures for configuring the
|
||||
* oscillator, VCXO and CLKIN section.
|
||||
*/
|
||||
|
||||
#define REG_XTAL_CL 183
|
||||
#define XTAL_CL_MASK 0xC0
|
||||
#define PLL_CL_MASK 0x36
|
||||
|
||||
//this sets the crystal load capacitance
|
||||
typedef enum
|
||||
{
|
||||
XTAL_Load_4_pF = 0x00,
|
||||
XTAL_Load_6_pF = 0x40,
|
||||
XTAL_Load_8_pF = 0x80,
|
||||
XTAL_Load_10_pF = 0xC0
|
||||
} Si5351_XTALLoadTypeDef;
|
||||
|
||||
//The following is an unexplained parameter. However someone from SiLabs called it "VCO load cap".
|
||||
//Lower settings seem to be more stable on higher frequencies, higher settings are more stable on lower frequencies allowing to tune the PLL to <200 MHz.
|
||||
typedef enum
|
||||
{
|
||||
PLL_Capacitive_Load_0 = 0,
|
||||
PLL_Capacitive_Load_1 = 1,
|
||||
PLL_Capacitive_Load_2 = 2
|
||||
} Si5351_PLLCapacitiveLoadTypeDef;
|
||||
|
||||
#define REG_CLKIN_DIV 15
|
||||
#define CLKIN_MASK 0xC0
|
||||
|
||||
//this sets the CLKIN pre-divider, after division, CLKIN should
|
||||
//fall between 10-40 MHz
|
||||
typedef enum
|
||||
{
|
||||
CLKINDiv_Div1 = 0x00,
|
||||
CLKINDiv_Div2 = 0x40,
|
||||
CLKINDiv_Div4 = 0x80,
|
||||
CLKINDiv_Div8 = 0xC0
|
||||
} Si5351_CLKINDivTypeDef;
|
||||
|
||||
#define REG_FANOUT_EN 187
|
||||
#define FANOUT_CLKIN_EN_MASK 0x80
|
||||
#define FANOUT_XO_EN_MASK 0x40
|
||||
#define FANOUT_MS_EN_MASK 0x10
|
||||
|
||||
#define REG_VCXO_PARAM_0_7 162
|
||||
#define REG_VCXO_PARAM_8_15 163
|
||||
#define REG_VCXO_PARAM_16_21 164
|
||||
#define VCXO_PARAM_16_21_MASK 0x3F
|
||||
#define VCXO_PARAM_MASK 0x003FFFFF
|
||||
|
||||
#define APR_MINIMUM 30 //minimum pull range
|
||||
#define APR_MAXIMUM 240 //maximum pull range
|
||||
|
||||
#define CLKIN_MINIMUM 10000 //minimum CLKIN frequency after division in kHz
|
||||
#define CLKIN_MAXIMUM 40000 //maximum CLKIN frequency after division in kHz
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Si5351_XTALLoadTypeDef OSC_XTAL_Load; //capacitive load of XTAL, 10pF by default
|
||||
Si5351_CLKINDivTypeDef CLKIN_Div; //CLKIN predivision, input f to PLL must be 10-40 MHz
|
||||
uint8_t VCXO_Pull_Range_ppm; //can range from +-30 ppm to 240ppm
|
||||
} Si5351_OSCConfigTypeDef;
|
||||
|
||||
/*
|
||||
* This section contains data structures for configuring the
|
||||
* PLL (PLLA and PLLB)
|
||||
*/
|
||||
|
||||
#define REG_PLL_CLOCK_SOURCE 15
|
||||
#define PLLA_CLOCK_SOURCE_MASK 0x04
|
||||
#define PLLB_CLOCK_SOURCE_MASK 0x08
|
||||
|
||||
//this selects the clock source for the PLL
|
||||
typedef enum
|
||||
{
|
||||
PLL_Clock_Source_XTAL = 0x00,
|
||||
PLL_Clock_Source_CLKIN = 0x0C //0x04 for PLLA, 0x08 for PLLB, use mask!
|
||||
} Si5351_PLLClockSourceTypeDef;
|
||||
|
||||
#define REG_FB_INT 22
|
||||
#define FB_INT_MASK 0x40
|
||||
|
||||
#define REG_PLL_RESET 177
|
||||
#define PLLA_RESET_MASK 0x20
|
||||
#define PLLB_RESET_MASK 0x80
|
||||
|
||||
#define REG_MSN_P1_0_7 30
|
||||
#define REG_MSN_P1_8_15 29
|
||||
#define REG_MSN_P1_16_17 28
|
||||
#define MSN_P1_16_17_MASK 0x03
|
||||
|
||||
#define REG_MSN_P2_0_7 33
|
||||
#define REG_MSN_P2_8_15 32
|
||||
#define REG_MSN_P2_16_19 31
|
||||
#define MSN_P2_16_19_MASK 0x0F
|
||||
|
||||
#define REG_MSN_P3_0_7 27
|
||||
#define REG_MSN_P3_8_15 26
|
||||
#define REG_MSN_P3_16_19 31
|
||||
#define MSN_P3_16_19_MASK 0xF0
|
||||
|
||||
#define MSNA_MSNB_OFFSET 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t PLL_Multiplier_Integer;
|
||||
uint32_t PLL_Multiplier_Numerator;
|
||||
uint32_t PLL_Multiplier_Denominator;
|
||||
Si5351_PLLClockSourceTypeDef PLL_Clock_Source;
|
||||
Si5351_PLLCapacitiveLoadTypeDef PLL_Capacitive_Load;
|
||||
} Si5351_PLLConfigTypeDef;
|
||||
|
||||
/*
|
||||
* This section contains data structures for configuring the
|
||||
* Spread Spectrum feature.
|
||||
*/
|
||||
|
||||
#define REG_SSC_MODE 151
|
||||
#define SSC_MODE_MASK 0x80
|
||||
|
||||
//this selects the Spread Spectrum mode
|
||||
typedef enum
|
||||
{
|
||||
SS_Mode_DownSpread = 0x00,
|
||||
SS_Mode_CenterSpread = 0x80
|
||||
} Si5351_SSModeTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SS_NCLK_0 = 0x00,
|
||||
SS_NCLK_1 = 0x10,
|
||||
SS_NCLK_2 = 0x20,
|
||||
SS_NCLK_3 = 0x30,
|
||||
SS_NCLK_4 = 0x40,
|
||||
SS_NCLK_5 = 0x50,
|
||||
SS_NCLK_6 = 0x60,
|
||||
SS_NCLK_7 = 0x70,
|
||||
SS_NCLK_8 = 0x80,
|
||||
SS_NCLK_9 = 0x90,
|
||||
SS_NCLK_10 = 0xA0,
|
||||
SS_NCLK_11 = 0xB0,
|
||||
SS_NCLK_12 = 0xC0,
|
||||
SS_NCLK_13 = 0xD0,
|
||||
SS_NCLK_14 = 0xE0,
|
||||
SS_NCLK_15 = 0xF0
|
||||
} Si5351_SSNCLKTypeDef;
|
||||
|
||||
#define REG_SSDN_P1_0_7 153
|
||||
#define REG_SSDN_P1_8_11 154
|
||||
#define SSDN_P1_8_11_MASK 0x0F
|
||||
|
||||
#define REG_SSDN_P2_0_7 150
|
||||
#define REG_SSDN_P2_8_14 149
|
||||
#define SSDN_P2_8_14_MASK 0x7F
|
||||
|
||||
#define REG_SSDN_P3_0_7 152
|
||||
#define REG_SSDN_P3_8_14 151
|
||||
#define SSDN_P3_8_14_MASK 0x7F
|
||||
|
||||
#define REG_SSUDP_0_7 155
|
||||
#define REG_SSUDP_8_11 154
|
||||
#define SSUDP_8_11_MASK 0xF0
|
||||
|
||||
#define REG_SSUP_P1_0_7 160
|
||||
#define REG_SSUP_P1_8_11 161
|
||||
#define SSUP_P1_8_11_MASK 0x0F
|
||||
|
||||
#define REG_SSUP_P2_0_7 157
|
||||
#define REG_SSUP_P2_8_14 156
|
||||
#define SSUP_P2_8_14_MASK 0x7F
|
||||
|
||||
#define REG_SSUP_P3_0_7 159
|
||||
#define REG_SSUP_P3_8_14 158
|
||||
#define SSUP_P3_8_14_MASK 0x7F
|
||||
|
||||
#define REG_SSC_EN 149
|
||||
#define SSC_EN_MASK 0x80
|
||||
|
||||
#define REG_SS_NCLK 161
|
||||
#define SS_NCLK_MASK 0xF0
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t SS_Amplitude_ppm; //amplitude of the SS feature in ppm of center frequency
|
||||
EnableState SS_Enable;
|
||||
Si5351_SSModeTypeDef SS_Mode;
|
||||
Si5351_SSNCLKTypeDef SS_NCLK;
|
||||
} Si5351_SSConfigTypeDef;
|
||||
|
||||
/*
|
||||
* This section contains data structures for configuring the
|
||||
* Output Multisynth.
|
||||
*/
|
||||
|
||||
//this selects the Multisynth clock source
|
||||
typedef enum
|
||||
{
|
||||
MS_Clock_Source_PLLA = 0x00,
|
||||
MS_Clock_Source_PLLB = 0x20
|
||||
} Si5351_MSClockSourceTypeDef;
|
||||
|
||||
#define REG_MS_P1_0_7 46
|
||||
#define REG_MS_P1_8_15 45
|
||||
#define REG_MS_P1_16_17 44
|
||||
#define MS_P1_16_17_MASK 0x03
|
||||
|
||||
#define REG_MS_P2_0_7 49
|
||||
#define REG_MS_P2_8_15 48
|
||||
#define REG_MS_P2_16_19 47
|
||||
#define MS_P2_16_19_MASK 0x0F
|
||||
|
||||
#define REG_MS_P3_0_7 43
|
||||
#define REG_MS_P3_8_15 42
|
||||
#define REG_MS_P3_16_19 47
|
||||
#define MS_P3_16_19_MASK 0xF0
|
||||
|
||||
#define REG_MS67_P1 90
|
||||
|
||||
#define REG_MS_INT 16
|
||||
#define MS_INT_MASK 0x40
|
||||
|
||||
#define REG_MS_DIVBY4 44
|
||||
#define MS_DIVBY4_MASK 0x0C
|
||||
|
||||
#define REG_MS_SRC 16
|
||||
#define MS_SRC_MASK 0x20
|
||||
|
||||
#define MS_SETUP_STEP 1
|
||||
#define MS_DIVIDER_STEP 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Si5351_MSClockSourceTypeDef MS_Clock_Source; //select source on MS input
|
||||
uint32_t MS_Divider_Integer; //the integer part of divider, called "a"
|
||||
uint32_t MS_Divider_Numerator; //the numerator, called "b"
|
||||
uint32_t MS_Divider_Denominator; //the denominator, called "c"
|
||||
} Si5351_MSConfigTypeDef; //sets MS divider ( a+(b/c) ) and clock (PLLA/PLLB)
|
||||
|
||||
/*
|
||||
* This section contains data structures for configuring the
|
||||
* CLK, R divider and output stage (joined together because they make
|
||||
* a tight block without any multiplexer).
|
||||
*/
|
||||
|
||||
#define REG_CLK_SRC 16
|
||||
#define CLK_SRC_MASK 0x0C
|
||||
|
||||
//this sets the CLK source clock
|
||||
typedef enum
|
||||
{
|
||||
CLK_Clock_Source_XTAL = 0x00,
|
||||
CLK_Clock_Source_CLKIN = 0x04,
|
||||
CLK_Clock_Source_MS0_MS4 = 0x08, //this uses MS0 for CLK0..3 and MS4 for CLK4..7
|
||||
CLK_Clock_Source_MS_Own = 0x0C //this uses MSx for CLKx
|
||||
} Si5351_CLKClockSourceTypeDef; //configures multiplexer on CLK input
|
||||
|
||||
#define REG_CLK_R_DIV 44
|
||||
#define CLK_R_DIV_MASK 0x70
|
||||
|
||||
#define REG_CLK_R67_DIV 92
|
||||
#define CLK_R67_DIV_MASK 0x07
|
||||
|
||||
//this sets the R divider ratio
|
||||
typedef enum
|
||||
{
|
||||
CLK_R_Div1 = 0x00,
|
||||
CLK_R_Div2 = 0x10,
|
||||
CLK_R_Div4 = 0x20,
|
||||
CLK_R_Div8 = 0x30,
|
||||
CLK_R_Div16 = 0x40,
|
||||
CLK_R_Div32 = 0x50,
|
||||
CLK_R_Div64 = 0x60,
|
||||
CLK_R_Div128 = 0x70
|
||||
} Si5351_CLKRDivTypeDef;
|
||||
|
||||
#define REG_CLK_DIS_STATE 24
|
||||
#define CLK_DIS_STATE_MASK 0x03
|
||||
|
||||
//this sets output buffer behaviour when disabled
|
||||
typedef enum
|
||||
{
|
||||
CLK_Disable_State_LOW = 0x00,
|
||||
CLK_Disable_State_HIGH = 0x01,
|
||||
CLK_Disable_State_HIGH_Z = 0x02, //three-stated when off
|
||||
CLK_Disable_State_ALWAYS_ON = 0x03 //cannot be disabled
|
||||
} Si5351_CLKDisableStateTypeDef;
|
||||
|
||||
#define REG_CLK_IDRV 16
|
||||
#define CLK_IDRV_MASK 0x03
|
||||
|
||||
//this sets current drive of the output buffer
|
||||
typedef enum
|
||||
{
|
||||
CLK_I_Drv_2mA = 0x00,
|
||||
CLK_I_Drv_4mA = 0x01,
|
||||
CLK_I_Drv_6mA = 0x02,
|
||||
CLK_I_Drv_8mA = 0x03
|
||||
} Si5351_CLKIDrvTypeDef;
|
||||
|
||||
#define REG_CLK_PHOFF 165
|
||||
#define CLK_PHOFF_MASK 0x7F
|
||||
|
||||
#define REG_CLK_EN 3
|
||||
|
||||
#define REG_CLK_INV 16
|
||||
#define CLK_INV_MASK 0x10
|
||||
|
||||
#define REG_CLK_PDN 16
|
||||
#define CLK_PDN_MASK 0x80
|
||||
|
||||
#define REG_CLK_OEB 9
|
||||
|
||||
#define CLK_PHOFF_STEP 1
|
||||
#define CLK_SETUP_STEP 1
|
||||
#define CLK_R_DIV_STEP 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Si5351_CLKClockSourceTypeDef CLK_Clock_Source; //clock source
|
||||
|
||||
/* this sets the time offset of the CLK channel, basic unit
|
||||
* is one quarter of the VCO period (90deg offset),
|
||||
* set it to 4*fVCO*toffset, the value is 7-bit, the max time offset
|
||||
* varies between 35 and 53 ns (1 cycle for 28 and 19 MHz, respectively)
|
||||
* according to the current frequency of the VCO
|
||||
*/
|
||||
uint8_t CLK_QuarterPeriod_Offset;
|
||||
|
||||
Si5351_CLKRDivTypeDef CLK_R_Div; //R divider value (only powers of 2)
|
||||
EnableState CLK_Invert; //invert output clock
|
||||
EnableState CLK_Enable; //enable flag
|
||||
EnableState CLK_PowerDown; //powerdown flag
|
||||
Si5351_CLKDisableStateTypeDef CLK_Disable_State; //sets output behaviour when disabled
|
||||
Si5351_CLKIDrvTypeDef CLK_I_Drv; //output driver current drive strength
|
||||
EnableState CLK_Use_OEB_Pin; //allows using OEB pin to enable clock
|
||||
} Si5351_CLKConfigTypeDef;
|
||||
|
||||
/*
|
||||
* This section contains main data structure for Si5351 configuration
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*
|
||||
* These are frequencies of the input clocks, set it in Hz.
|
||||
*/
|
||||
uint32_t f_XTAL;
|
||||
uint32_t f_CLKIN;
|
||||
|
||||
//Interrupt masking - enabling it disables the int source from pulling INTR low
|
||||
EnableState Interrupt_Mask_SysInit;
|
||||
EnableState Interrupt_Mask_PLLB;
|
||||
EnableState Interrupt_Mask_PLLA;
|
||||
EnableState Interrupt_Mask_CLKIN;
|
||||
EnableState Interrupt_Mask_XTAL;
|
||||
|
||||
//Fanout enable - enables internal clock routing
|
||||
EnableState Fanout_MS_EN;
|
||||
EnableState Fanout_XO_EN;
|
||||
EnableState Fanout_CLKIN_EN;
|
||||
|
||||
I2C_TypeDef *I2Cx; //the I2C interface that will be used
|
||||
uint8_t HW_I2C_Address; //I2C address of the Si5351 for the packages with A0 pin
|
||||
//(also, some duds with strange address reported)
|
||||
Si5351_OSCConfigTypeDef OSC; //Oscillator, CLKIN and VCXO settings
|
||||
Si5351_PLLConfigTypeDef PLL[2]; //PLL settings for PLLA and PLLB
|
||||
Si5351_MSConfigTypeDef MS[8]; //MultiSynth[0..7] settings
|
||||
Si5351_CLKConfigTypeDef CLK[8]; //CLK[0..7], R divider and output stage settings
|
||||
Si5351_SSConfigTypeDef SS; //spread spectrum settings
|
||||
} Si5351_ConfigTypeDef;
|
||||
|
||||
/*
|
||||
* Typedefs for selecting PLL, MS and CLK to be used
|
||||
*/
|
||||
|
||||
//this selects PLL channel
|
||||
typedef enum
|
||||
{
|
||||
PLL_A = 0,
|
||||
PLL_B = 1
|
||||
} Si5351_PLLChannelTypeDef;
|
||||
|
||||
//this selects Multisynth channel
|
||||
typedef enum
|
||||
{
|
||||
MS0 = 0,
|
||||
MS1 = 1,
|
||||
MS2 = 2,
|
||||
MS3 = 3,
|
||||
MS4 = 4,
|
||||
MS5 = 5,
|
||||
MS6 = 6,
|
||||
MS7 = 7
|
||||
} Si5351_MSChannelTypeDef;
|
||||
|
||||
//this selects CLK channel
|
||||
typedef enum
|
||||
{
|
||||
CLK0 = 0,
|
||||
CLK1 = 1,
|
||||
CLK2 = 2,
|
||||
CLK3 = 3,
|
||||
CLK4 = 4,
|
||||
CLK5 = 5,
|
||||
CLK6 = 6,
|
||||
CLK7 = 7
|
||||
} Si5351_CLKChannelTypeDef;
|
||||
|
||||
//this selects device status flag
|
||||
typedef enum
|
||||
{
|
||||
StatusBit_SysInit = DEV_SYS_INIT_MASK,
|
||||
StatusBit_PLLA = DEV_STKY_LOL_A_MASK,
|
||||
StatusBit_PLLB = DEV_LOL_B_MASK,
|
||||
StatusBit_CLKIN = DEV_LOS_CLKIN_MASK,
|
||||
StatusBit_XTAL = DEV_LOS_XTAL_MASK,
|
||||
} Si5351_StatusBitTypeDef;
|
||||
|
||||
//these write to and read from a Si5351 register, for porting
|
||||
//purposes, these functions should be the only ones which should need edits
|
||||
int Si5351_WriteRegister(Si5351_ConfigTypeDef *Si5351_ConfigStruct, uint8_t reg_address, uint8_t reg_data);
|
||||
uint8_t Si5351_ReadRegister(Si5351_ConfigTypeDef *Si5351_ConfigStruct, uint8_t reg_address);
|
||||
|
||||
void Si5351_StructInit(Si5351_ConfigTypeDef *Si5351_ConfigStruct);
|
||||
|
||||
void Si5351_OSCConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct);
|
||||
|
||||
EnableState Si5351_CheckStatusBit(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_StatusBitTypeDef StatusBit);
|
||||
EnableState Si5351_CheckStickyBit(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_StatusBitTypeDef StatusBit);
|
||||
void Si5351_InterruptConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct);
|
||||
void Si5351_ClearStickyBit(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_StatusBitTypeDef StatusBit);
|
||||
|
||||
void Si5351_PLLConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_PLLChannelTypeDef PLL_Channel);
|
||||
void Si5351_PLLReset(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_PLLChannelTypeDef PLL_Channel);
|
||||
void Si5351_PLLSimultaneousReset(Si5351_ConfigTypeDef *Si5351_ConfigStruct);
|
||||
|
||||
void Si5351_SSConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct);
|
||||
|
||||
void Si5351_MSConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_MSChannelTypeDef MS_Channel);
|
||||
|
||||
void Si5351_CLKPowerCmd(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_CLKChannelTypeDef CLK_Channel);
|
||||
void Si5351_CLKConfig(Si5351_ConfigTypeDef *Si5351_ConfigStruct, Si5351_CLKChannelTypeDef CLK_Channel);
|
||||
|
||||
int Si5351_Init(Si5351_ConfigTypeDef *Si5351_ConfigStruct);
|
||||
#endif /* SI5351_H_ */
|
Reference in New Issue
Block a user