有没有大佬给我分析一下一个简单的问题,感谢感谢!!!
测试主板单片机为GD32F103C8,
相关引脚定义:SPI1_MOSI:PB15,SPI1_MISO:PB14,SPI1_SCK:PB13,SPI1_CS:PB12,
测试程序来源:官网GD32F103VC的SPI0-FLASH程序,
测试步骤:
1)关闭外部时钟,开启内部时钟48M(设计主板无外部时钟提供);
2)GPIO初始化改为GPIOB及引脚修改,SPI0初始化修改为SPI1,片选信号的拉高拉低宏定义函数修改;
3)打印串口usart0改为usart1(代码注释及参考打印信息都没做修改)
后两点都是VC和C8差异而做的初始化修改,板卡设计用的SPI1读外部FLASH
测试现象:读到的FLASH ID为0xFFFFFF
程序如下:
//#define SPI_FLASH_CS_LOW() gpio_bit_reset(GPIOE, GPIO_PIN_3)
//#define SPI_FLASH_CS_HIGH() gpio_bit_set(GPIOE, GPIO_PIN_3)
#define SPI_FLASH_CS_LOW() gpio_bit_reset(GPIOB, GPIO_PIN_12)
#define SPI_FLASH_CS_HIGH() gpio_bit_set(GPIOB, GPIO_PIN_12)
int main(void)
{
/* systick configuration*/
// systick_config();
/* configure the led GPIO */
// test_status_led_init();
/* USART parameter configuration */
gd_eval_com_init(EVAL_COM1);
/* configure SPI0 GPIO and parameter */
spi_flash_init();
/* GD32103C-EVAL-V1.2 Start up */
printf("\n\r###############################################################################\n\r");
printf("\n\rSystem is Starting up...\n\r");
printf("\n\rFlash:%dK\n\r", *(__IO uint16_t*)(0x1FFFF7E0));
/* get chip serial number */
get_chip_serial_num();
/* printf CPU unique device id */
printf("\n\rThe CPU Unique Device ID:[%X-%X-%X]\n\r", int_device_serial[2], int_device_serial[1], int_device_serial[0]);
printf("\n\rSPI Flash:GD25Q16 configured...\n\r");
/* get flash id */
flash_id = spi_flash_read_id();
printf("\n\rThe Flash_ID:0x%X\n\r", flash_id);
}
void spi_flash_init(void)
{
spi_parameter_struct spi_init_struct;
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOE);
rcu_periph_clock_enable(RCU_SPI0);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_SPI1);
/* SPI0_SCK(PA5), SPI0_MISO(PA6) and SPI0_MOSI(PA7) GPIO pin configuration */
// gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5 | GPIO_PIN_7);
// gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
// /* SPI0_CS(PE3) GPIO pin configuration */
// gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
/* SPI0_SCK(PA5), SPI0_MISO(PA6) and SPI0_MOSI(PA7) GPIO pin configuration */
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13 | GPIO_PIN_15);//SPI1_SCK:PB13 SPI1_MOSI:PB15
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_14);//SPI1_MISO:PB14
/* SPI0_CS(PE3) GPIO pin configuration */
gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12);//SPI1_CS:PB12
/* chip select invalid*/
SPI_FLASH_CS_HIGH();
/* SPI0 parameter config */
spi_init_struct.trans_mode = SPI_TRANSMODE_FULLDUPLEX;
spi_init_struct.device_mode = SPI_MASTER;
spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT;
spi_init_struct.clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE;
spi_init_struct.nss = SPI_NSS_SOFT;
spi_init_struct.prescale = SPI_PSC_8;
spi_init_struct.endian = SPI_ENDIAN_MSB;
spi_init(SPI1, &spi_init_struct);
/* enable SPI0 */
spi_enable(SPI1);
}
uint32_t spi_flash_read_id(void)
{
uint32_t temp = 0, temp0 = 0, temp1 = 0, temp2 = 0;
/* select the flash: chip select low */
SPI_FLASH_CS_LOW();
/* send "RDID " instruction */
spi_flash_send_byte(0x9F);
/* read a byte from the flash */
temp0 = spi_flash_send_byte(DUMMY_BYTE);
/* read a byte from the flash */
temp1 = spi_flash_send_byte(DUMMY_BYTE);
/* read a byte from the flash */
temp2 = spi_flash_send_byte(DUMMY_BYTE);
/* deselect the flash: chip select high */
SPI_FLASH_CS_HIGH();
temp = (temp0 << 16) | (temp1 << 8) | temp2;
return temp;
}
个人分析:
1)外部时钟切换为内部时钟,会不会影响FLASH的操作,内部时钟不同频率都试过,现象一样;
2)返回0xFFFFFF能不能怀疑硬件的焊接问题,能有什么方法排除硬件问题;
3)GD32F103VC FLASH和 GD32F103C8 FLASH厂商是一样的,读取ID时发送的指令应该是一样吧
4)跳过读FLASH失败,在擦除FLASH时,发送指令之后,一直卡在等待擦除完成的循环里边 |