void GpioInit() { PEout(0) = 1; PEout(2) = 1; PEout(4) = 1; PEout(6) = 1; }
void LED_TASK(void *p_arg) { (void)p_arg; while(1) { PEout(0)=!PEout(0); OSTimeDlyHMSM(0,0,0,500); } }
int CMD_SPI(int argc, char *const argv[]) { uint8_t data[6]; uint32_t instance; printf("SPI TEST CMD\r\n"); GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); instance = SPI_QuickInit(SPI2_SCK_PD12_SOUT_PD13_SIN_PD14, kSPI_CPOL0_CPHA0, 20*1000*1000); PORT_PinMuxConfig(HW_GPIOD, 12, kPinAlt2); // PORT_PinMuxConfig(HW_GPIOD, 13, kPinAlt2); // PORT_PinMuxConfig(HW_GPIOD, 14, kPinAlt2); // PORT_PinMuxConfig(HW_GPIOD, 11, kPinAlt2); //SPI2_PCS0 PORT_PinMuxConfig(HW_GPIOD, 15, kPinAlt2); //SPI2_PCS1 SPI_EnableTxFIFO(HW_SPI2, true); SPI_EnableRxFIFO(HW_SPI2, true); // SPI_ReadWriteByte(instance, HW_CTAR0, 0x90, HW_SPI_CS1, kSPI_PCS_KeepAsserted); // DelayMs(20); if((argc == 2) && (!strcmp(argv[1], "FLASH"))) { return DO_SPI_FLASH(argc, argv); } if((argc == 2) && (!strcmp(argv[1], "DMA"))) { return DO_SPI_DMA(argc, argv); } printf("param error\r\n"); PEout(6) = !PEout(6); SPI_ReadWriteByte(instance, HW_CTAR0, 0x90, HW_SPI_CS1, kSPI_PCS_KeepAsserted); SPI_ReadWriteByte(instance, HW_CTAR0, 0x00, HW_SPI_CS1, kSPI_PCS_KeepAsserted); SPI_ReadWriteByte(instance, HW_CTAR0, 0x00, HW_SPI_CS1, kSPI_PCS_KeepAsserted); SPI_ReadWriteByte(instance, HW_CTAR0, 0x00, HW_SPI_CS1, kSPI_PCS_KeepAsserted); // SPI_WaitSync(instance); data[0] = SPI_ReadWriteByte(instance, HW_CTAR0, 0xFF, HW_SPI_CS1, kSPI_PCS_KeepAsserted); data[1] = SPI_ReadWriteByte(instance, HW_CTAR0, 0xFF, HW_SPI_CS1, kSPI_PCS_ReturnInactive); PEout(6) = !PEout(6); printf("data:0x%02X 0x%02X\r\n", data[0], data[1]); //初始化SPI // SPI_QuickInit(BOARD_SPI_MAP, kSPI_CPOL0_CPHA1, 1*1000); //安装回调函数 // SPI_CallbackInstall(BOARD_SPI_INSTANCE, SPI_ISR); //开启SPI中断 // SPI_ITDMAConfig(BOARD_SPI_INSTANCE, kSPI_IT_TCF); return CMD_RET_USAGE; }