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


TXE flag isn't cleared after a SPI send

STM32F411 nucleo board is connected to AMT203 encoder via level-shifte (5V->3.3V).
I have a logic analyzer and TotalPhase Beagle connected to the level-shifter in addition to the encoder on the 3.3V side. The Beagle show no legitimate SPI transactions and the logic analyzer doesn’t pick up any SCK either since data isn’t going out of MOSI, I believe. I have checked and re-checked several times that all necessary clocks are turned on and to be absolutely sure USART isn’t messing with my SPI config, I commented all of that out. I still doubt the configuration.

Please let me know if anyone has ideas that I could try out! Thanks!
------
Current config is given below —
SPI (SPI2) init has been made as follows:

Set up Slave Sel (SS) GPIO pins as follows after enabling GPIOB:

__HAL_RCC_GPIOB_CLK_ENABLE();

/*Configure GPIO pin : SPI2_SS1_Pin */
GPIO_InitStruct.Pin = SPI2_SS1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(SPI2_SS1_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pin : SPI2_SS2_Pin */
GPIO_InitStruct.Pin = SPI2_SS2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SPI2_SS2_GPIO_Port, &GPIO_InitStruct);


Setup GPIO-pins - MOSI, MISO, SCK - using following function:
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{

GPIO_InitTypeDef GPIO_InitStruct;
if(hspi->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspInit 0 */

/* USER CODE END SPI2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI2_CLK_ENABLE();

/**SPI2 GPIO Configuration
PC2 --> SPI2_MISO
PC3 --> SPI2_MOSI
PB10 --> SPI2_SCK
*/
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP; //tried pulldown too
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP; // tried pulldown too
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}


/* SPI2 init function */
static void MX_SPI2_Init(void)
{
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
}

Can anyone help? I added some more debug into hardfault_handler() and found I hit a Bus fault.
TXE (TX empty) is a hardware control register and will always be set as long as you are not transmitting. If you finished sending stuff and have nothing else to send you should disable the interrupt TXIE (TX interrupt enable bit (I think it’s in CR1 register).

 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  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. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs