mirror of
https://github.com/armbian/mpads.git
synced 2026-01-06 10:32:31 -08:00
Add I2C functions to switch selected sd port
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
8DF89ED150041C4CBC7CB9A9CAA90856=6C266C1D6D9A4C85D433E945AEFC4708
|
||||
DC22A860405A8BF2F2C095E5B6529F12=6C266C1D6D9A4C85D433E945AEFC4708
|
||||
8DF89ED150041C4CBC7CB9A9CAA90856=3727D542A794DE1A9CDE772EF0B277F1
|
||||
DC22A860405A8BF2F2C095E5B6529F12=3727D542A794DE1A9CDE772EF0B277F1
|
||||
eclipse.preferences.version=1
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -46,7 +47,7 @@ I2C_HandleTypeDef hi2c1;
|
||||
SD_HandleTypeDef hsd;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
int selectedSDcard = 0x15;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -60,7 +61,6 @@ static void MX_I2C1_Init(void);
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -96,6 +96,9 @@ int main(void)
|
||||
MX_I2C1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
uint8_t buff[2];
|
||||
buff[0] = 255;
|
||||
buff[1] = 255;
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@@ -105,6 +108,69 @@ int main(void)
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
HAL_StatusTypeDef status = HAL_I2C_Slave_Receive(&hi2c1, buff, 2, 10);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
if (buff[0] == 0x01 && selectedSDcard != buff[1]) {
|
||||
// command to connect/disconnect host to sd
|
||||
if (selectedSDcard > 0 && selectedSDcard < 8) {
|
||||
HAL_SD_DeInit(&hsd);
|
||||
}
|
||||
|
||||
selectedSDcard = buff[1];
|
||||
|
||||
// disconnect all sd from master, connect to slaves
|
||||
HAL_GPIO_WritePin(GPIOB, PORT0_Pin|PORT1_Pin|PORT2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOC, PORT3_Pin|PORT4_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, PORT5_Pin|PORT6_Pin|PORT7_Pin, GPIO_PIN_RESET);
|
||||
|
||||
|
||||
// if valid sd number connect master to this sd
|
||||
switch (buff[1]) {
|
||||
case 0:
|
||||
HAL_GPIO_WritePin(PORT0_GPIO_Port, PORT0_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 1:
|
||||
HAL_GPIO_WritePin(PORT1_GPIO_Port, PORT1_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 2:
|
||||
HAL_GPIO_WritePin(PORT2_GPIO_Port, PORT2_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 3:
|
||||
HAL_GPIO_WritePin(PORT3_GPIO_Port, PORT3_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 4:
|
||||
HAL_GPIO_WritePin(PORT4_GPIO_Port, PORT4_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 5:
|
||||
HAL_GPIO_WritePin(PORT5_GPIO_Port, PORT5_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 6:
|
||||
HAL_GPIO_WritePin(PORT6_GPIO_Port, PORT6_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
case 7:
|
||||
HAL_GPIO_WritePin(PORT7_GPIO_Port, PORT7_Pin, GPIO_PIN_SET);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
MX_SDIO_SD_Init();
|
||||
|
||||
|
||||
}
|
||||
if (buff[0]==0x02) {
|
||||
//command to get currently selected sd card (if any)
|
||||
// buff[0] = selectedSDcard;
|
||||
// HAL_StatusTypeDef status = HAL_I2C_Slave_Transmit(&hi2c1, buff, 1, 20000);
|
||||
// if (status == HAL_OK)
|
||||
// {
|
||||
// int i = 2;
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
@@ -170,9 +236,9 @@ static void MX_I2C1_Init(void)
|
||||
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.ClockSpeed = 100000;
|
||||
hi2c1.Init.ClockSpeed = 400000;
|
||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
||||
hi2c1.Init.OwnAddress1 = 100;
|
||||
hi2c1.Init.OwnAddress1 = 74;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c1.Init.OwnAddress2 = 0;
|
||||
@@ -197,7 +263,7 @@ static void MX_SDIO_SD_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN SDIO_Init 0 */
|
||||
|
||||
if (selectedSDcard < 0 || selectedSDcard > 7) return;
|
||||
/* USER CODE END SDIO_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN SDIO_Init 1 */
|
||||
@@ -208,12 +274,16 @@ static void MX_SDIO_SD_Init(void)
|
||||
hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
|
||||
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||||
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
|
||||
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
|
||||
hsd.Init.ClockDiv = 3;
|
||||
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_ENABLE;
|
||||
hsd.Init.ClockDiv = 7;
|
||||
if (HAL_SD_Init(&hsd) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN SDIO_Init 2 */
|
||||
|
||||
/* USER CODE END SDIO_Init 2 */
|
||||
@@ -236,10 +306,7 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(PORT0_GPIO_Port, PORT0_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, PORT1_Pin|PORT2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, PORT0_Pin|PORT1_Pin|PORT2_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, PORT3_Pin|PORT4_Pin, GPIO_PIN_RESET);
|
||||
|
||||
@@ -167,10 +167,14 @@ void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
/**SDIO GPIO Configuration
|
||||
PC8 ------> SDIO_D0
|
||||
PC9 ------> SDIO_D1
|
||||
PC10 ------> SDIO_D2
|
||||
PC11 ------> SDIO_D3
|
||||
PC12 ------> SDIO_CK
|
||||
PD2 ------> SDIO_CMD
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_12;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
||||
|GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
@@ -205,10 +209,14 @@ void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd)
|
||||
|
||||
/**SDIO GPIO Configuration
|
||||
PC8 ------> SDIO_D0
|
||||
PC9 ------> SDIO_D1
|
||||
PC10 ------> SDIO_D2
|
||||
PC11 ------> SDIO_D3
|
||||
PC12 ------> SDIO_CK
|
||||
PD2 ------> SDIO_CMD
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_12);
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
||||
|GPIO_PIN_12);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
main.c:70:5:main 8 static
|
||||
main.c:116:6:SystemClock_Config 96 static
|
||||
main.c:162:13:MX_I2C1_Init 8 static
|
||||
main.c:196:13:MX_SDIO_SD_Init 8 static
|
||||
main.c:228:13:MX_GPIO_Init 40 static
|
||||
main.c:281:6:Error_Handler 4 static,ignoring_inline_asm
|
||||
main.c:70:5:main 16 static
|
||||
main.c:182:6:SystemClock_Config 96 static
|
||||
main.c:228:13:MX_I2C1_Init 8 static
|
||||
main.c:262:13:MX_SDIO_SD_Init 8 static
|
||||
main.c:298:13:MX_GPIO_Init 40 static
|
||||
main.c:348:6:Error_Handler 4 static,ignoring_inline_asm
|
||||
|
||||
Binary file not shown.
@@ -2,4 +2,4 @@ stm32f1xx_hal_msp.c:64:6:HAL_MspInit 24 static
|
||||
stm32f1xx_hal_msp.c:90:6:HAL_I2C_MspInit 40 static
|
||||
stm32f1xx_hal_msp.c:124:6:HAL_I2C_MspDeInit 16 static
|
||||
stm32f1xx_hal_msp.c:155:6:HAL_SD_MspInit 48 static
|
||||
stm32f1xx_hal_msp.c:196:6:HAL_SD_MspDeInit 16 static
|
||||
stm32f1xx_hal_msp.c:200:6:HAL_SD_MspDeInit 16 static
|
||||
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,9 @@
|
||||
#MicroXplorer Configuration settings - do not modify
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Group By Peripherals
|
||||
I2C1.IPParameters=OwnAddress
|
||||
I2C1.OwnAddress=50
|
||||
I2C1.I2C_Mode=I2C_Fast
|
||||
I2C1.IPParameters=OwnAddress,I2C_Mode
|
||||
I2C1.OwnAddress=0x25
|
||||
KeepUserPlacement=false
|
||||
Mcu.Family=STM32F1
|
||||
Mcu.IP0=I2C1
|
||||
@@ -17,26 +18,29 @@ Mcu.Name=STM32F103R(C-D-E)Tx
|
||||
Mcu.Package=LQFP64
|
||||
Mcu.Pin0=PD0-OSC_IN
|
||||
Mcu.Pin1=PD1-OSC_OUT
|
||||
Mcu.Pin10=PA10
|
||||
Mcu.Pin11=PA11
|
||||
Mcu.Pin12=PA12
|
||||
Mcu.Pin13=PA13
|
||||
Mcu.Pin14=PA14
|
||||
Mcu.Pin15=PC12
|
||||
Mcu.Pin16=PD2
|
||||
Mcu.Pin17=PB6
|
||||
Mcu.Pin18=PB7
|
||||
Mcu.Pin19=VP_SYS_VS_Systick
|
||||
Mcu.Pin10=PA9
|
||||
Mcu.Pin11=PA10
|
||||
Mcu.Pin12=PA11
|
||||
Mcu.Pin13=PA12
|
||||
Mcu.Pin14=PA13
|
||||
Mcu.Pin15=PA14
|
||||
Mcu.Pin16=PC10
|
||||
Mcu.Pin17=PC11
|
||||
Mcu.Pin18=PC12
|
||||
Mcu.Pin19=PD2
|
||||
Mcu.Pin2=PB13
|
||||
Mcu.Pin20=VP_USB_DEVICE_VS_USB_DEVICE_MSC_FS
|
||||
Mcu.Pin20=PB6
|
||||
Mcu.Pin21=PB7
|
||||
Mcu.Pin22=VP_SYS_VS_Systick
|
||||
Mcu.Pin23=VP_USB_DEVICE_VS_USB_DEVICE_MSC_FS
|
||||
Mcu.Pin3=PB14
|
||||
Mcu.Pin4=PB15
|
||||
Mcu.Pin5=PC6
|
||||
Mcu.Pin6=PC7
|
||||
Mcu.Pin7=PC8
|
||||
Mcu.Pin8=PA8
|
||||
Mcu.Pin9=PA9
|
||||
Mcu.PinsNb=21
|
||||
Mcu.Pin8=PC9
|
||||
Mcu.Pin9=PA8
|
||||
Mcu.PinsNb=24
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F103RCTx
|
||||
@@ -79,7 +83,7 @@ PA9.Signal=GPIO_Output
|
||||
PB13.GPIOParameters=PinState,GPIO_Label
|
||||
PB13.GPIO_Label=PORT0
|
||||
PB13.Locked=true
|
||||
PB13.PinState=GPIO_PIN_SET
|
||||
PB13.PinState=GPIO_PIN_RESET
|
||||
PB13.Signal=GPIO_Output
|
||||
PB14.GPIOParameters=GPIO_Label
|
||||
PB14.GPIO_Label=PORT1
|
||||
@@ -93,7 +97,11 @@ PB6.Mode=I2C
|
||||
PB6.Signal=I2C1_SCL
|
||||
PB7.Mode=I2C
|
||||
PB7.Signal=I2C1_SDA
|
||||
PC12.Mode=SD_1_bit
|
||||
PC10.Mode=SD_4_bits_Wide_bus
|
||||
PC10.Signal=SDIO_D2
|
||||
PC11.Mode=SD_4_bits_Wide_bus
|
||||
PC11.Signal=SDIO_D3
|
||||
PC12.Mode=SD_4_bits_Wide_bus
|
||||
PC12.Signal=SDIO_CK
|
||||
PC6.GPIOParameters=GPIO_Label
|
||||
PC6.GPIO_Label=PORT3
|
||||
@@ -103,13 +111,15 @@ PC7.GPIOParameters=GPIO_Label
|
||||
PC7.GPIO_Label=PORT4
|
||||
PC7.Locked=true
|
||||
PC7.Signal=GPIO_Output
|
||||
PC8.Mode=SD_1_bit
|
||||
PC8.Mode=SD_4_bits_Wide_bus
|
||||
PC8.Signal=SDIO_D0
|
||||
PC9.Mode=SD_4_bits_Wide_bus
|
||||
PC9.Signal=SDIO_D1
|
||||
PD0-OSC_IN.Mode=HSE-External-Oscillator
|
||||
PD0-OSC_IN.Signal=RCC_OSC_IN
|
||||
PD1-OSC_OUT.Mode=HSE-External-Oscillator
|
||||
PD1-OSC_OUT.Signal=RCC_OSC_OUT
|
||||
PD2.Mode=SD_1_bit
|
||||
PD2.Mode=SD_4_bits_Wide_bus
|
||||
PD2.Signal=SDIO_CMD
|
||||
PinOutPanel.RotationAngle=0
|
||||
ProjectManager.AskForMigrate=true
|
||||
@@ -144,7 +154,6 @@ RCC.ADCFreqValue=36000000
|
||||
RCC.AHBFreq_Value=72000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||
RCC.APB1Freq_Value=36000000
|
||||
RCC.APB1TimCLKDivider=2
|
||||
RCC.APB1TimFreq_Value=72000000
|
||||
RCC.APB2Freq_Value=72000000
|
||||
RCC.APB2TimFreq_Value=72000000
|
||||
@@ -155,7 +164,7 @@ RCC.HSEDivPLL=RCC_HSE_PREDIV_DIV2
|
||||
RCC.HSE_VALUE=16000000
|
||||
RCC.I2S2Freq_Value=72000000
|
||||
RCC.I2S3Freq_Value=72000000
|
||||
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimCLKDivider,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSEDivPLL,HSE_VALUE,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,USBPrescaler,VCOOutput2Freq_Value
|
||||
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSEDivPLL,HSE_VALUE,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,USBPrescaler,VCOOutput2Freq_Value
|
||||
RCC.MCOFreq_Value=72000000
|
||||
RCC.PLLCLKFreq_Value=72000000
|
||||
RCC.PLLMCOFreq_Value=36000000
|
||||
@@ -168,8 +177,10 @@ RCC.TimSysFreq_Value=72000000
|
||||
RCC.USBFreq_Value=48000000
|
||||
RCC.USBPrescaler=RCC_USBCLKSOURCE_PLL_DIV1_5
|
||||
RCC.VCOOutput2Freq_Value=8000000
|
||||
SDIO.ClockDiv=3
|
||||
SDIO.IPParameters=ClockDiv
|
||||
SDIO.ClockDiv=7
|
||||
SDIO.ClockEdge=SDIO_CLOCK_EDGE_RISING
|
||||
SDIO.HardwareFlowControl=SDIO_HARDWARE_FLOW_CONTROL_ENABLE
|
||||
SDIO.IPParameters=ClockDiv,HardwareFlowControl,ClockEdge
|
||||
USB_DEVICE.CLASS_NAME_FS=MSC
|
||||
USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS
|
||||
USB_DEVICE.VirtualMode=Msc
|
||||
|
||||
Reference in New Issue
Block a user