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


STM32F4 USART DMA RECEIVE

Hello everyone.

I’m just starting stm32f4. I’m try to use USART DMA, with Transmit it’s ok. But with Receive, when I send characters from Terminal to Board first, for example ‘aaa’, it’s ok. But the second characters I send, for example ‘bbb’, so the characters result is ‘aaabbb’ but I want the characters just ‘bbb’. I’m try to clear the buffer but it’s doesn’t work.
In case of Receive, I’m using flag IDLE to nodify that the characters was done.
I think the best way is return the address of memory address from current address to start address, but I’m not sure how to return it.

Here is my code.

Pleas help me. Thank you so much.

int main(void)

{

USART_Config();


if (USART_GetFlagStatus(USART3, USART_FLAG_IDLE)==RESET)

{

/* clear buffer */

for (i=0; iAHB1ENR = RCC_AHB1ENR_GPIOCEN;



RCC->APB1ENR = RCC_APB1ENR_USART3EN;



RCC->AHB1ENR = RCC_AHB1ENR_DMA1EN;



/* USART3 GPIO configuration -------------------*/

/* Connect USART pins to AF7 */

GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);



/* Configure USART Tx and Rx as alternate function push-pull */

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;



GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_Init(GPIOC, &GPIO_InitStructure);



GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_Init(GPIOC, &GPIO_InitStructure);



USART_InitStructure.USART_BaudRate = 56000;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART3, &USART_InitStructure);



/* Configure DMA Initialization Structure */

DMA_InitStructure.DMA_BufferSize = 100;

DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ;

DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;

DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;


DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(USART3->DR)) ;

DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

/* Configure TX DMA */

DMA_InitStructure.DMA_Channel = DMA_Channel_4 ;

DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral ;

DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)aTxBuffer ;

DMA_Init(DMA1_Stream4,&DMA_InitStructure);

/* Configure RX DMA */

DMA_InitStructure.DMA_Channel = DMA_Channel_4 ;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ;

DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&(aRxBuffer);

DMA_Init(DMA1_Stream1,&DMA_InitStructure);

}


 

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