bouffalolab / bouffalo_sdk

BouffaloSDK is the IOT and MCU software development kit provided by the Bouffalo Lab Team, supports all the series of Bouffalo chips. Also it is the combination of bl_mcu_sdk and bl_iot_sdk
Apache License 2.0
349 stars 123 forks source link

SPI BL702 - no "Byte-inverse signal for FIFO" option - **SPI_BYTE_MSB** #40

Closed pvvx closed 1 year ago

pvvx commented 1 year ago

SPI BL702 - no "Byte-inverse signal for FIFO" option? SPI_BYTE_MSB https://github.com/bouffalolab/bl_mcu_sdk/blob/master/drivers/lhal/include/bflb_spi.h#L66

BL702/704/706 Reference Manual:

spi_config: 
Address:0x4000a200
bit7 - Byte-inverse signal for each FIFO entry data
0: Byte[0] is sent out first
1: Byte[3] is sent out first

With SPI_BYTE_MSB is set, SPI works correctly on the test board with BL702C10.

sakumisu commented 1 year ago

Only support 32bit, so disable it.

pvvx commented 1 year ago
unsigned int SPI_ReadInvBMode(unsigned int wrdata, unsigned int size) {
    bflb_spi_feature_control(uspi0, SPI_CMD_SET_DATA_WIDTH, size);
    unsigned int regval = bflb_spi_poll_send(uspi0, wrdata);
    unsigned int i = 4 - size;
    while (i--)
        regval >>= 8;
    return regval;
}

Otherwise, it is not convenient to work with AD717x type ADC. There, registers have different lengths (8, 16, 24 bits) and it is easier to set a command fixed in the high byte.

static unsigned int rdreg_ad717x(ad717x_st_reg *p) {
    bflb_spi_feature_control(uspi0, SPI_CMD_SET_DATA_WIDTH, p->size + 1);
    unsigned int rval = (bflb_spi_poll_send(uspi0, ((p->addr & 0x3f) << 24) | 0x40000000))
            & 0x00ffffff;
    unsigned int i = 3 - p->size;
    while (i--)
        rval >>= 8;
    p->value = rval;
    return rval;
}

As well as other applications.