Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

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);


 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs