Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Using CMSIS

Hi,

I have set up a Nucleo with three EasySpin boards and have two way communications working fine by coding the GPIO pins bit by bit. However, I want to take advantage of the on-chip SPI h/w. Ironically this much harder to set up than coding it all by hand.

SPI_TypeDef
SPI_InitTypeDef SPI_InitStruct;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); // release SPI1 from reset state

SPI_Cmd(SPI1, DISABLE); // some configs must be done when disabled.

SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex ;
SPI_InitStruct.SPI_Mode=SPI_Mode_Master;
SPI_InitStruct.SPI_CPOL=SPI_CPOL_High; // SCK=1 s idle
SPI_InitStruct.SPI_CPHA=1; //SPI_CPHA : 2nd transition is data capture edge.
SPI_InitStruct.SPI_NSS=SPI_NSS_Soft;
SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_32; // 32,64,128,256
SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB;

SPI_Init(SPI1,&SPI_InitStruct);

SPI_Cmd(SPI1, ENABLE);


When I try to send a byte by writing to the DR and polling TXE it never happens. Where can I find a thorough guide that tells ALL I need to to know configure the device using CMSIS without going to the chip reference manual and programming each register bit by bit ?

Thanks.

There is no alternate way than studying the reference manual.
If you don’t want to programm on register-level, why don’t you use HAL?
Specialy the clock-system is fairly complex, and with CubeMX it’s very easy to get a working configuration.
That does the most magic you need, but dosn’t suspend you from understanding the reference-manual.

Harry


Thanks, I found somethings in StdPerif_Driver/src/stm32f4xx_spi.c that I had overlooked.

I have the output send working and TXE event happens., however I still don’t seem to have control over the NSS line.

GPIO_SetBits(SPI1NSS) does not seem to be having any effect.

Can you advise on what I need to look at? Thanks.





void set_as_AF(GPIO_TypeDef* port, uint32_t pin)
{
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // push-pull PP or open drain OD
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; // 2 25 50 100
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(port, &GPIO_InitStructure);
}

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); // release SPI1 from reset state

GPIO_PinAFConfig(GPIOA,GPIO_Pin_5, GPIO_AF_SPI1); // Connect SPI1 pins to AF5
GPIO_PinAFConfig(GPIOA,GPIO_Pin_7, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA,GPIO_Pin_6, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOB,GPIO_Pin_6, GPIO_AF_SPI1);
set_as_AF(GPIOA,GPIO_Pin_5);
set_as_AF(GPIOA,GPIO_Pin_7);
set_as_AF(GPIOA,GPIO_Pin_6);
set_as_AF(GPIOB,GPIO_Pin_6);


SPI_InitTypeDef SPI_InitStruct;

SPI_Cmd(SPI1, DISABLE); // some configs must be done when disabled.

SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex ;
SPI_InitStruct.SPI_Mode=SPI_Mode_Master;
SPI_InitStruct.SPI_CPOL=SPI_CPOL_High; // SCK=1 s idle
SPI_InitStruct.SPI_CPHA=1; //SPI_CPHA : 2nd transition is data capture edge.
SPI_InitStruct.SPI_NSS=SPI_NSS_Hard; // enable using ext hardware NSS line
SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_32; // 32,64,128,256
SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB;

SPI_Init(SPI1,&SPI_InitStruct);
SPI1->CR2 |= (uint16_t) SPI_CR2_SSOE; // NSS line as output (the only CR2 reqd is not using INTs)

SPI_Cmd(SPI1, ENABLE);

GPIO_SetBits(GPIOB,GPIO_Pin_6);