cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 is not fast enough

parisa
Senior

Hello,

Here is my code,

#include <stdio.h>
#include <string.h>
 
 
void GPIOSYS(void){
		GPIO_InitTypeDef GPIOSt;
	
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
		//GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);
		GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
		GPIOSt.GPIO_Mode=GPIO_Mode_Out_PP;
		GPIOSt.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_0|GPIO_Pin_1;
		GPIOSt.GPIO_Speed=GPIO_Speed_50MHz;
		GPIO_Init(GPIOB,&GPIOSt);	
	
	
	
		GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
		GPIOSt.GPIO_Mode=GPIO_Mode_Out_PP;
		GPIOSt.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3;
		GPIOSt.GPIO_Speed=GPIO_Speed_50MHz;
		GPIO_Init(GPIOA,&GPIOSt);	
	
}
 
void CLOCK(void){
	RCC_HSEConfig(RCC_HSE_ON);
	while(RCC_WaitForHSEStartUp()==ERROR);
	
	RCC_PLLConfig(RCC_PLLSource_HSE_Div1,9);
	RCC_PLLCmd(ENABLE);
	
	while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)!=SET);
	
	RCC_ClockSecuritySystemCmd(ENABLE);
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
	RCC_HCLKConfig(RCC_SYSCLK_Div1);
	
	while (RCC_GetSYSCLKSource() != 0x08);
	
}
 
void Delay(){
	int i,j;
	for(i=0;i<10000;i++)
	for(j=0;j<250;j++);
}
 
int main(void){
	CLOCK();
	GPIOSYS();
	
	while(1){
			GPIO_ResetBits(GPIOB,GPIO_Pin_6);
			GPIO_ResetBits(GPIOB,GPIO_Pin_7);
		
			GPIO_ResetBits(GPIOA,GPIO_Pin_2);
			GPIO_ResetBits(GPIOA,GPIO_Pin_3);
		
			//Delay();		
			GPIO_SetBits(GPIOB,GPIO_Pin_6);
			GPIO_SetBits(GPIOB,GPIO_Pin_7);			
		
			GPIO_SetBits(GPIOA,GPIO_Pin_2);
			GPIO_SetBits(GPIOA,GPIO_Pin_3);
			//Delay();
	}
	
}
 

I see a 500Khz pulse train on my oscilloscope which is below my expectations( for a 72Mhz MCU). Did I make a mistake or it is usual?

Thanks

14 REPLIES 14
parisa
Senior

Thank you so much.

I need to know there is no way to speed up setting ports more than 1Mhz on Stm32f103 because my board is fixed and I can't changed any hardware.

GPIO input/output is filtered. Select a different (higher) speed maximum.

See the reference manual, sect. 9.1, Table 21 (output MODE bits).

Write directly to the BSRR register of the GPIO port (sect. 9.2.5, port set/reset register) of the reference manual.

https://www.st.com/resource/en/reference_manual/cd00171190.pdf

Yes there is, using a timer to trigger a DMA stream which reads from GPIO.

If it's possible to assign the clock line to a timer output, then it can provide the clock signal in PWM mode, and the DMA trigger to read GPIO. When the MCU runs at 72 MHz, the timer frequency can be 72 MHz divided by any integer between 2-65535, so 1 or 2 MHz are definitely possible (I think you could go up to 9 MHz, not sure if DMA can handle 18 or 36).

Program the DMA channel that belongs to the timer to transfer 20 x 32 bits from the GPIO IDR register to a memory buffer. When the DMA is complete, you'll have the 20 GPIO readings (mask out the uninteresting pins).

If it's not possible to assign the clock line to a timer output, then set up another timer channel and DMA stream to transfer a 01010101 sequence from a memory buffer to the GPIO output register.

Thank you so much, could you provide me some references to deepen my understanding?

Thank you very much, Did not I set the maximum speed? (GPIOSt.GPIO_Speed=GPIO_Speed_50MHz;) or it is something else?