cancel
Showing results for 
Search instead for 
Did you mean: 

How do I convert a SPI register from a STM32F103 to a STM32L412?

RCooke88
Senior

Hi All,

I'm trying to convert deividAlfa's LCD library to use on a L412 micro but I'm having an issue that I don't understand.

He has a routine in the LCD.C file:

static void setSPI_Size(int8_t size){
  if(config.spi_sz!=size){
    __HAL_SPI_DISABLE(&LCD_HANDLE);
    config.spi_sz=size;
    if(size==mode_16bit){
      LCD_HANDLE.Init.DataSize = SPI_DATASIZE_16BIT;
      LCD_HANDLE.Instance->CR1 |= SPI_CR1_DFF;
    }
    else{
      LCD_HANDLE.Init.DataSize = SPI_DATASIZE_8BIT;
      LCD_HANDLE.Instance->CR1 &= ~(SPI_CR1_DFF);
    }
  }
}

The problem is there is no SPI_CR1_DFF register in the L412 code. I want to use 8 bits for the SPI bus.

Is there a way around this issue?

Thanks,

Richard

1 REPLY 1
christop
ST Employee

STM32F103 and STM32L412 are different MCUs and integrate different peripherals or peripheral revisions.

For instance the SPI is different so the registers are also different.

For STM32L412, the data size is defined in CR2 register in bitfield DS:

Bits 11:8 DS[3:0]: Data size

These bits configure the data length for SPI transfers.

0000: Not used

0001: Not used

0010: Not used

0011: 4-bit

0100: 5-bit

0101: 6-bit

0110: 7-bit

0111: 8-bit

1000: 9-bit

1001: 10-bit

1010: 11-bit

1011: 12-bit

1100: 13-bit

1101: 14-bit

1110: 15-bit

1111: 16-bit

To do the porting you need to check the reference manual RM0394 for STM32L412:

https://www.st.com/content/ccc/resource/technical/document/reference_manual/group0/b0/ac/3e/8f/6d/21/47/af/DM00151940/files/DM00151940.pdf/jcr:content/translations/en.DM00151940.pdf

It is likely there are other locations in the code where you have to apply changes due to register differences between the 2 MCUs.