X4 x4sip02 + custom control board

Discussion in 'X2 & X4 SoC' started by Jaeho, Jun 21, 2018.

  1. Jaeho

    Jaeho New Member

    Hi Novelda.

    sorry, I'm not good at English.

    I am working on a setup consisting of the X4SIP02 and costom control board (main cpu : stm32f429 series).
    I succeeded in read/write the SPI debug register(0x04) over SPI.
    SPI_debug_register.JPG

    And next step, I try to setting PIF register. I referenced x4driver_raspbian code and x4driver.c.
    I'm not used RTOS.

    MY code and spi_mb_fifo_status register read result.
    ---------------------------------------------------------------------------------------------------
    uint16_t dac_min = 900;
    uint8_t dac_min_lsb = (uint8_t)(dac_min & 0x0007);
    uint8_t dac_min_msb = (uint8_t)((dac_min >> 3) & 0x00ff);

    uint16_t dac_max = 1150;
    uint8_t dac_max_lsb = (uint8_t)(dac_max & 0x0007);
    uint8_t dac_max_msb = (uint8_t)((dac_max >> 3) & 0x00ff);

    uint8_t iterations = 16;

    uint8_t pps = 26;
    uint8_t pps_lsb = pps & 0x00FF;
    uint8_t pps_msb = (pps & 0xFF00) >> 8;

    /* Set dac_min_lsb _ begin */
    SPI_wr(0x10,0x00); // read SPI register : spi_mb_fifo_status <- read result : 0x04
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,ADDR_PIF_TRX_DAC_MIN_L_RW+0x80);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,0);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,dac_min_lsb);
    SPI_wr(0x10,0x00); <- read result : 0x00
    HAL_Delay(10);
    /* Set dac_min_lsb _ end */

    /* Set dac_min_msb _ begin */
    SPI_wr(0x10,0x00); <- read result : 0x00
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,ADDR_PIF_TRX_DAC_MIN_H_RW+0x80);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,0);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,dac_min_msb);
    SPI_wr(0x10,0x00); <- read result : 0x00
    HAL_Delay(10);
    /* Set dac_min_msb _ end */

    /* Set dac_max_lsb _ begin */
    SPI_wr(0x10,0x00); <- read result : 0x00
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,ADDR_PIF_TRX_DAC_MAX_L_RW+0x80);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,0);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,dac_max_lsb);
    SPI_wr(0x10,0x00); <- read result : 0x81
    HAL_Delay(10);
    /* Set dac_max_lsb _ end*/

    /* Set dac_max_msb _ begin */
    SPI_wr(0x10,0x00); <- read result : 0x81
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,ADDR_PIF_TRX_DAC_MAX_H_RW+0x80);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,0);
    SPI_w(ADDR_SPI_TO_CPU_WRITE_DATA_WE,dac_max_msb);
    SPI_wr(0x10,0x00); <- read result : 0x81
    HAL_Delay(10);
    /* Set dac_max_msb _ end*/
    ---------------------------------------------------------------------------------------------------
    This spi_mb_fifo_status result is right?
    x4driver code is wait for to_cpu_fifio_empty bit High. (bit_is_set)
    bit_is_set(x4driver).JPG

    so, I try to wait bit_is_set. but result is only 0x00.

    Did I miss anything?

    Thank you for read my Question.
     
  2. Charlie Shao

    Charlie Shao Moderator Staff Member

    Hi Jaeho,
    It is hard to point out where is the problem since you just share part of the code and not everyone has a stm32f429 device on hand, but I think you work on the wrong way. Here I list some suggestions for your transplantation:
    1. Try to keep the source code of XEP as much as possible, or at least keep x4driver.c and x4driver.h as they are like RPI transplantation.
    2. Do not try to rewrite x4driver functions, or you have to spend much more time on debugging.
    3. Just replace the SPI driver with STM32 SPI functions like RPI example radar_hal.c does. Do not change high-level setting functions and sequence.
    4. Highly recommend you to use RTOS for your implementation, mutex mechanism is very important for program reliability.