Browse Source

更换SPI引脚为新板引脚

simulating_SPI_by_software
tianjialong 2 years ago
parent
commit
a4cfea2850
  1. 6
      app/Core/Inc/main.h
  2. 32
      app/Core/Src/gpio.c
  3. 24
      app/MDK-ARM/app.uvguix.29643
  4. 2
      app/MDK-ARM/app.uvprojx
  5. 39
      app/app.ioc
  6. 4
      usersrc/usermain.c

6
app/Core/Inc/main.h

@ -57,14 +57,14 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define CLK_Pin GPIO_PIN_1
#define SEL_Pin GPIO_PIN_4
#define SEL_GPIO_Port GPIOA
#define CLK_Pin GPIO_PIN_5
#define CLK_GPIO_Port GPIOA
#define MISO_Pin GPIO_PIN_6
#define MISO_GPIO_Port GPIOA
#define MOSI_Pin GPIO_PIN_7
#define MOSI_GPIO_Port GPIOA
#define SPI_SEL_Pin GPIO_PIN_4
#define SPI_SEL_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */

32
app/Core/Src/gpio.c

@ -53,10 +53,7 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOH_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, CLK_Pin|MOSI_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, SEL_Pin|CLK_Pin|MOSI_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : PC14 PC15 */
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
@ -64,16 +61,16 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pins : PA0 PA4 PA5 PA8
PA11 PA12 PA15 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_8
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_15;
/*Configure GPIO pins : PA0 PA1 PA8 PA11
PA12 PA15 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11
|GPIO_PIN_12|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PAPin PAPin */
GPIO_InitStruct.Pin = CLK_Pin|MOSI_Pin;
/*Configure GPIO pins : PAPin PAPin PAPin */
GPIO_InitStruct.Pin = SEL_Pin|CLK_Pin|MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
@ -85,21 +82,14 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(MISO_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PB0 PB1 PB3 PB5
PB6 PB7 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_5
|GPIO_PIN_6|GPIO_PIN_7;
/*Configure GPIO pins : PB0 PB1 PB3 PB4
PB5 PB6 PB7 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = SPI_SEL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SPI_SEL_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PH3 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

24
app/MDK-ARM/app.uvguix.29643
File diff suppressed because it is too large
View File

2
app/MDK-ARM/app.uvprojx

@ -54,7 +54,7 @@
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
<DebugInformation>1</DebugInformation>
<BrowseInformation>1</BrowseInformation>
<BrowseInformation>0</BrowseInformation>
<ListingPath></ListingPath>
<HexFormatSelection>1</HexFormatSelection>
<Merge32K>0</Merge32K>

39
app/app.ioc

@ -16,18 +16,18 @@ Mcu.IP5=USART2
Mcu.IPNb=6
Mcu.Name=STM32L432K(B-C)Ux
Mcu.Package=UFQFPN32
Mcu.Pin0=PA1
Mcu.Pin1=PA2
Mcu.Pin0=PA2
Mcu.Pin1=PA3
Mcu.Pin10=VP_SYS_VS_Systick
Mcu.Pin11=VP_TIM7_VS_ClockSourceINT
Mcu.Pin2=PA3
Mcu.Pin3=PA6
Mcu.Pin4=PA7
Mcu.Pin5=PA9
Mcu.Pin6=PA10
Mcu.Pin7=PA13 (JTMS-SWDIO)
Mcu.Pin8=PA14 (JTCK-SWCLK)
Mcu.Pin9=PB4 (NJTRST)
Mcu.Pin2=PA4
Mcu.Pin3=PA5
Mcu.Pin4=PA6
Mcu.Pin5=PA7
Mcu.Pin6=PA9
Mcu.Pin7=PA10
Mcu.Pin8=PA13 (JTMS-SWDIO)
Mcu.Pin9=PA14 (JTCK-SWCLK)
Mcu.PinsNb=12
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
@ -47,10 +47,6 @@ NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.USART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA1.GPIOParameters=GPIO_Label
PA1.GPIO_Label=CLK
PA1.Locked=true
PA1.Signal=GPIO_Output
PA10.Mode=Asynchronous
PA10.Signal=USART1_RX
PA13\ (JTMS-SWDIO).Mode=Serial_Wire
@ -62,6 +58,14 @@ PA2.Mode=Asynchronous
PA2.Signal=USART2_TX
PA3.Mode=Asynchronous
PA3.Signal=USART2_RX
PA4.GPIOParameters=GPIO_Label
PA4.GPIO_Label=SEL
PA4.Locked=true
PA4.Signal=GPIO_Output
PA5.GPIOParameters=GPIO_Label
PA5.GPIO_Label=CLK
PA5.Locked=true
PA5.Signal=GPIO_Output
PA6.GPIOParameters=GPIO_Label
PA6.GPIO_Label=MISO
PA6.Locked=true
@ -72,11 +76,6 @@ PA7.Locked=true
PA7.Signal=GPIO_Output
PA9.Mode=Asynchronous
PA9.Signal=USART1_TX
PB4\ (NJTRST).GPIOParameters=GPIO_PuPd,GPIO_Label
PB4\ (NJTRST).GPIO_Label=SPI_SEL
PB4\ (NJTRST).GPIO_PuPd=GPIO_NOPULL
PB4\ (NJTRST).Locked=true
PB4\ (NJTRST).Signal=GPIO_Output
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
@ -105,7 +104,7 @@ ProjectManager.StackSize=0x800
ProjectManager.TargetToolchain=MDK-ARM V5.32
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART1_UART_Init-USART1-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_TIM7_Init-TIM7-false-HAL-true
RCC.ADCFreq_Value=64000000
RCC.AHBFreq_Value=64000000
RCC.APB1Freq_Value=64000000

4
usersrc/usermain.c

@ -8,8 +8,8 @@
#define READ_CMD 0x80
#define SPI_TIMEOUT_VALUE 1000
#define SPI_CS_1() HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_SET) /* */
#define SPI_CS_0() HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_RESET) /* */
#define SPI_CS_1() HAL_GPIO_WritePin(SEL_GPIO_Port, SEL_Pin, GPIO_PIN_SET) /* */
#define SPI_CS_0() HAL_GPIO_WritePin(SEL_GPIO_Port, SEL_Pin, GPIO_PIN_RESET) /* */
#define SPI_SCK_1() HAL_GPIO_WritePin(CLK_GPIO_Port, CLK_Pin, GPIO_PIN_SET) /* SCK = 1 */
#define SPI_SCK_0() HAL_GPIO_WritePin(CLK_GPIO_Port, CLK_Pin, GPIO_PIN_RESET) /* SCK = 0 */
#define SPI_MOSI_1() HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_SET) /* MOSI = 1 */

Loading…
Cancel
Save