initialize ad9833 and mcp41

This commit is contained in:
2023-05-21 21:09:07 +02:00
parent 26f5cfe3ce
commit 40e0ca1d0c
15 changed files with 237 additions and 178 deletions

View File

@@ -23,8 +23,7 @@
#define __MAIN_H
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
@@ -34,25 +33,25 @@ extern "C"
/* USER CODE BEGIN Includes */
// #include "SEGGER_RTT.h"
#include "ulog.h"
/* USER CODE END Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
@@ -61,41 +60,47 @@ extern "C"
/* Private defines -----------------------------------------------------------*/
#define B1_Pin GPIO_PIN_13
#define B1_GPIO_Port GPIOC
#define BTN1_Pin GPIO_PIN_0
#define BTN1_GPIO_Port GPIOA
#define BTN2_Pin GPIO_PIN_1
#define BTN2_GPIO_Port GPIOA
#define USART_TX_Pin GPIO_PIN_2
#define USART_TX_GPIO_Port GPIOA
#define USART_RX_Pin GPIO_PIN_3
#define USART_RX_GPIO_Port GPIOA
#define LD2_Pin GPIO_PIN_5
#define LD2_GPIO_Port GPIOA
#define BTN1_Pin GPIO_PIN_1
#define BTN1_GPIO_Port GPIOB
#define BTN2_Pin GPIO_PIN_2
#define BTN2_GPIO_Port GPIOB
#define BTN3_Pin GPIO_PIN_11
#define BTN3_GPIO_Port GPIOB
#define BTN4_Pin GPIO_PIN_12
#define BTN4_GPIO_Port GPIOB
#define BTN5_Pin GPIO_PIN_11
#define BTN3_Pin GPIO_PIN_4
#define BTN3_GPIO_Port GPIOA
#define BTN4_Pin GPIO_PIN_5
#define BTN4_GPIO_Port GPIOA
#define AMP1_CS_Pin GPIO_PIN_11
#define AMP1_CS_GPIO_Port GPIOB
#define DDS1_CS_Pin GPIO_PIN_12
#define DDS1_CS_GPIO_Port GPIOB
#define ST7565_RST_Pin GPIO_PIN_8
#define ST7565_RST_GPIO_Port GPIOC
#define ST7565_A0_Pin GPIO_PIN_9
#define ST7565_A0_GPIO_Port GPIOC
#define BTN5_Pin GPIO_PIN_8
#define BTN5_GPIO_Port GPIOA
#define BTN_CH1_Pin GPIO_PIN_9
#define BTN_CH1_GPIO_Port GPIOA
#define LED_CH1_Pin GPIO_PIN_10
#define LED_CH1_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 ST7565_CS_Pin GPIO_PIN_15
#define ST7565_CS_GPIO_Port GPIOA
#define ST7565_SCK_Pin GPIO_PIN_10
#define ST7565_SCK_GPIO_Port GPIOC
#define ST7565_RST_Pin GPIO_PIN_11
#define ST7565_RST_GPIO_Port GPIOC
#define ST7565_CS_Pin GPIO_PIN_11
#define ST7565_CS_GPIO_Port GPIOC
#define ST7565_MOSI_Pin GPIO_PIN_12
#define ST7565_MOSI_GPIO_Port GPIOC
#define ST7565_A0_Pin GPIO_PIN_2
#define ST7565_A0_GPIO_Port GPIOD
#define SWO_Pin GPIO_PIN_3
#define SWO_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}

View File

@@ -1,21 +1,21 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.c
* @brief This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* Copyright (c) 2023 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.
*
******************************************************************************
*/
******************************************************************************
* @file gpio.c
* @brief This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* Copyright (c) 2023 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 ------------------------------------------------------------------*/
@@ -49,16 +49,15 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, LD2_Pin|ST7565_CS_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, AMP1_CS_Pin|DDS1_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, ST7565_RST_Pin|ST7565_A0_Pin|ST7565_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_CH1_GPIO_Port, LED_CH1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = B1_Pin;
@@ -66,38 +65,34 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PAPin PAPin */
GPIO_InitStruct.Pin = LD2_Pin|ST7565_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
/*Configure GPIO pins : PAPin PAPin PAPin PAPin
PAPin PAPin */
GPIO_InitStruct.Pin = BTN1_Pin|BTN2_Pin|BTN3_Pin|BTN4_Pin
|BTN5_Pin|BTN_CH1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
GPIO_InitStruct.Pin = BTN1_Pin|BTN2_Pin|BTN3_Pin|BTN4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
/*Configure GPIO pins : PBPin PBPin */
GPIO_InitStruct.Pin = AMP1_CS_Pin|DDS1_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = BTN5_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(BTN5_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = ST7565_RST_Pin;
/*Configure GPIO pins : PCPin PCPin PCPin */
GPIO_InitStruct.Pin = ST7565_RST_Pin|ST7565_A0_Pin|ST7565_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(ST7565_RST_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = ST7565_A0_Pin;
GPIO_InitStruct.Pin = LED_CH1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(ST7565_A0_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(LED_CH1_GPIO_Port, &GPIO_InitStruct);
}

View File

@@ -102,9 +102,8 @@ int main(void)
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
ulog_init();
ulog_subscribe(RTT_console_logger, ULOG_DEBUG_LEVEL);
ulog_subscribe(RTT_console_logger, ULOG_TRACE_LEVEL);
APP_init(&app_data);
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
// SEGGER_RTT_WriteString(0, "App start...\n");
ULOG_INFO("start app...");
@@ -124,8 +123,9 @@ int main(void)
/* USER CODE BEGIN WHILE */
DISP_clearScreen(&disp);
ST7565_DisplayAll(&hst7565);
HAL_Delay(1000);
uint32_t last_tick = HAL_GetTick();
APP_init(&app_data);
while (1)
{
CTRL_buttonsHandler();

View File

@@ -42,7 +42,7 @@ void MX_SPI2_Init(void)
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;

View File

@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Fri Apr 21 19:03:25 CEST 2023]
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Sun May 21 21:04:44 CEST 2023]
##########################################################################################################################
# ------------------------------------------------

View File

@@ -21,35 +21,38 @@ Mcu.Name=STM32F303R(D-E)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PC13
Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PB1
Mcu.Pin11=PB2
Mcu.Pin12=PB11
Mcu.Pin13=PB12
Mcu.Pin14=PB13
Mcu.Pin15=PB14
Mcu.Pin16=PB15
Mcu.Pin17=PA11
Mcu.Pin18=PA13
Mcu.Pin19=PA14
Mcu.Pin10=PA5
Mcu.Pin11=PA6
Mcu.Pin12=PA7
Mcu.Pin13=PB11
Mcu.Pin14=PB12
Mcu.Pin15=PB13
Mcu.Pin16=PB14
Mcu.Pin17=PB15
Mcu.Pin18=PC8
Mcu.Pin19=PC9
Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin20=PA15
Mcu.Pin21=PC10
Mcu.Pin22=PC11
Mcu.Pin23=PC12
Mcu.Pin24=PD2
Mcu.Pin25=PB3
Mcu.Pin26=PB6
Mcu.Pin27=PB7
Mcu.Pin28=VP_SYS_VS_Systick
Mcu.Pin29=VP_TIM2_VS_ClockSourceINT
Mcu.Pin20=PA8
Mcu.Pin21=PA9
Mcu.Pin22=PA10
Mcu.Pin23=PA13
Mcu.Pin24=PA14
Mcu.Pin25=PC10
Mcu.Pin26=PC11
Mcu.Pin27=PC12
Mcu.Pin28=PB3
Mcu.Pin29=PB6
Mcu.Pin3=PF0-OSC_IN
Mcu.Pin30=PB7
Mcu.Pin31=VP_SYS_VS_Systick
Mcu.Pin32=VP_TIM2_VS_ClockSourceINT
Mcu.Pin4=PF1-OSC_OUT
Mcu.Pin5=PA2
Mcu.Pin6=PA3
Mcu.Pin7=PA5
Mcu.Pin8=PA6
Mcu.Pin9=PA7
Mcu.PinsNb=30
Mcu.Pin5=PA0
Mcu.Pin6=PA1
Mcu.Pin7=PA2
Mcu.Pin8=PA3
Mcu.Pin9=PA4
Mcu.PinsNb=33
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F303RETx
@@ -66,10 +69,18 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SysTick_IRQn=true\:0\:0\:true\:false\:true\:true\:true\:false
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
PA11.GPIOParameters=GPIO_Label
PA11.GPIO_Label=BTN5
PA11.Locked=true
PA11.Signal=GPIO_Input
PA0.GPIOParameters=GPIO_Label
PA0.GPIO_Label=BTN1
PA0.Locked=true
PA0.Signal=GPIO_Input
PA1.GPIOParameters=GPIO_Label
PA1.GPIO_Label=BTN2
PA1.Locked=true
PA1.Signal=GPIO_Input
PA10.GPIOParameters=GPIO_Label
PA10.GPIO_Label=LED_CH1
PA10.Locked=true
PA10.Signal=GPIO_Output
PA13.GPIOParameters=GPIO_Label
PA13.GPIO_Label=TMS
PA13.Locked=true
@@ -80,10 +91,6 @@ PA14.GPIO_Label=TCK
PA14.Locked=true
PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK
PA15.GPIOParameters=GPIO_Label
PA15.GPIO_Label=ST7565_CS
PA15.Locked=true
PA15.Signal=GPIO_Output
PA2.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode
PA2.GPIO_Label=USART_TX
PA2.GPIO_Mode=GPIO_MODE_AF_PP
@@ -100,38 +107,39 @@ PA3.GPIO_Speed=GPIO_SPEED_FREQ_LOW
PA3.Locked=true
PA3.Mode=Asynchronous
PA3.Signal=USART2_RX
PA5.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode
PA5.GPIO_Label=LD2 [Green Led]
PA5.GPIO_Mode=GPIO_MODE_OUTPUT_PP
PA5.GPIO_PuPd=GPIO_NOPULL
PA5.GPIO_Speed=GPIO_SPEED_FREQ_LOW
PA4.GPIOParameters=GPIO_Label
PA4.GPIO_Label=BTN3
PA4.Locked=true
PA4.Signal=GPIO_Input
PA5.GPIOParameters=GPIO_Label
PA5.GPIO_Label=BTN4
PA5.Locked=true
PA5.Signal=GPIO_Output
PA5.Signal=GPIO_Input
PA6.Signal=S_TIM3_CH1
PA7.Locked=true
PA7.Signal=S_TIM3_CH2
PB1.GPIOParameters=GPIO_Label
PB1.GPIO_Label=BTN1
PB1.Locked=true
PB1.Signal=GPIO_Input
PA8.GPIOParameters=GPIO_Label
PA8.GPIO_Label=BTN5
PA8.Locked=true
PA8.Signal=GPIO_Input
PA9.GPIOParameters=GPIO_Label
PA9.GPIO_Label=BTN_CH1
PA9.Locked=true
PA9.Signal=GPIO_Input
PB11.GPIOParameters=GPIO_Label
PB11.GPIO_Label=BTN3
PB11.GPIO_Label=AMP1_CS
PB11.Locked=true
PB11.Signal=GPIO_Input
PB11.Signal=GPIO_Output
PB12.GPIOParameters=GPIO_Label
PB12.GPIO_Label=BTN4
PB12.GPIO_Label=DDS1_CS
PB12.Locked=true
PB12.Signal=GPIO_Input
PB12.Signal=GPIO_Output
PB13.Mode=Full_Duplex_Master
PB13.Signal=SPI2_SCK
PB14.Mode=Full_Duplex_Master
PB14.Signal=SPI2_MISO
PB15.Mode=Full_Duplex_Master
PB15.Signal=SPI2_MOSI
PB2.GPIOParameters=GPIO_Label
PB2.GPIO_Label=BTN2
PB2.Locked=true
PB2.Signal=GPIO_Input
PB3.GPIOParameters=GPIO_Label
PB3.GPIO_Label=SWO
PB3.Locked=true
@@ -147,7 +155,7 @@ PC10.Locked=true
PC10.Mode=Simplex_Bidirectional_Master
PC10.Signal=SPI3_SCK
PC11.GPIOParameters=GPIO_Label
PC11.GPIO_Label=ST7565_RST
PC11.GPIO_Label=ST7565_CS
PC11.Locked=true
PC11.Signal=GPIO_Output
PC12.GPIOParameters=GPIO_Label
@@ -165,10 +173,14 @@ PC14-OSC32_IN.Signal=RCC_OSC32_IN
PC15-OSC32_OUT.Locked=true
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
PD2.GPIOParameters=GPIO_Label
PD2.GPIO_Label=ST7565_A0
PD2.Locked=true
PD2.Signal=GPIO_Output
PC8.GPIOParameters=GPIO_Label
PC8.GPIO_Label=ST7565_RST
PC8.Locked=true
PC8.Signal=GPIO_Output
PC9.GPIOParameters=GPIO_Label
PC9.GPIO_Label=ST7565_A0
PC9.Locked=true
PC9.Signal=GPIO_Output
PF0-OSC_IN.Locked=true
PF0-OSC_IN.Mode=HSE-External-Clock-Source
PF0-OSC_IN.Signal=RCC_OSC_IN
@@ -202,7 +214,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_SPI3_Init-SPI3-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_SPI3_Init-SPI3-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true,8-MX_TIM3_Init-TIM3-false-HAL-true,9-MX_ADC1_Init-ADC1-false-HAL-true
RCC.ADC12outputFreq_Value=72000000
RCC.ADC34outputFreq_Value=72000000
RCC.AHBFreq_Value=72000000
@@ -258,10 +270,11 @@ SH.S_TIM3_CH1.ConfNb=1
SH.S_TIM3_CH2.0=TIM3_CH2,Encoder_Interface
SH.S_TIM3_CH2.ConfNb=1
SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32
SPI2.CLKPolarity=SPI_POLARITY_HIGH
SPI2.CalculateBaudRate=1.125 MBits/s
SPI2.DataSize=SPI_DATASIZE_8BIT
SPI2.Direction=SPI_DIRECTION_2LINES
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode,BaudRatePrescaler
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode,BaudRatePrescaler,CLKPolarity
SPI2.Mode=SPI_MODE_MASTER
SPI2.NSSPMode=SPI_NSS_PULSE_ENABLE
SPI2.VirtualType=VM_MASTER