This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1230 boot阶段初始化SPI



各位大神,我这里有个需求在boot阶段需要通过SPI访问外部Flash,结果发现回读的数总是0,因为例程自带的SPI初始化是初始化成Slave,不能使用,为了保证初始化的正确性,我直接移植App(调试好了访问外部Flash)中的代码,具体如下:

#ifdef SSI_ENABLE_UPDATE
	
    //
    // Enable the clocks to the SSI and GPIO modules.
    //
    //自带的时钟初始化,去掉后回读出问题
    HWREG(SYSCTL_RCGC2) |= SYSCTL_RCGC2_GPIOA;
    HWREG(SYSCTL_RCGC1) |= SYSCTL_RCGC1_SSI0;

    SysCtlPeripheralEnable(0xf0001c00);
    SysCtlPeripheralEnable(0xf0000800);

    GPIOPinConfigure(0x802);
    GPIOPinConfigure(0xc02);
    GPIOPinConfigure(0x1002);
    GPIOPinConfigure(0x1402);

    GPIOPinTypeSSI(GPIO_PORTA_BASE, SSI_PINS);

    SSIConfigSetExpClk(SSI0_BASE, CRYSTAL_FREQ, 0x0,						   0x0, CRYSTAL_FREQ/128, 8);
    //Enable SSI
    HWREG(SSI0_BASE + SSI_O_CR1) |= SSI_CR1_SSE;
#endif

boot阶段的SPI读写是验证过的,因为我在App中有个AC_JumpToBootLoader();,能够直接进入到boot的updater,这样自读写是成功,原因我觉得应该是没有下电,在App中初始化的SPI配置都没有变才没有问题,但是下电直接进入SPI初始化,再读写就不行,不知道我忘记写哪个寄存器了,请大神们帮忙看一下

  • 我已经比对了boot阶段初始化和正式阶段初始化SPI的寄存器了....一模一样的,还有什么要配置的吗....

    07 3F 00 00
    02 00 00 00
    00 00 00 00
    03 00 00 00
    02 00 00 00
    00 00 00 00
    08 00 00 00
    00 00 00 00
    00 00 00 00
    00 00 00 00

  • 1.SPI的时钟问题

    2.初始化的顺序问题。

    你不是第一还好好的么,第二次怎么不可以了,还是没看懂

  • 第一次好好的是因为从APP阶段直接跳入到boot的updater()函数,CPU的寄存器状态由于没下电都是正确的配置,第二次是上电后在boot阶段初始化SPI,所以怀疑初始化的方法漏了什么

  • 你好多都是操作的SPI的寄存器直接复制,没法看是否正确,给你看看SSI操作库函数的例程,这样对比的容易找错误

        //
        // The SSI0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    
        //
        // For this example SSI0 is used with PortA[5:2].  The actual port and
        // pins used may be different on your part, consult the data sheet for
        // more information.  GPIO port A needs to be enabled so these pins can
        // be used.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA2_SSI0CLK);
        GPIOPinConfigure(GPIO_PA3_SSI0FSS);
        GPIOPinConfigure(GPIO_PA4_SSI0RX);
        GPIOPinConfigure(GPIO_PA5_SSI0TX);
    
        //
        // Configure the GPIO settings for the SSI pins.  This function also gives
        // control of these pins to the SSI hardware.  Consult the data sheet to
        // see which functions are allocated per pin.
        // The pins are assigned as follows:
        //      PA5 - SSI0Tx
        //      PA4 - SSI0Rx
        //      PA3 - SSI0Fss
        //      PA2 - SSI0CLK
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
                       GPIO_PIN_2);
    
        //
        // Configure and enable the SSI port for TI master mode.  Use SSI0, system
        // clock supply, master mode, 1MHz SSI frequency, and 8-bit data.
        //
        SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_TI,
                           SSI_MODE_MASTER, 1000000, 8);
    
        //
        // Enable the SSI0 module.
        //
        SSIEnable(SSI0_BASE);