본문 바로가기

RaspberryPi/RP2040

[RP2040_W5500] RP2040 C++ SDK 환경에서 GPIO 성능 측정, Arduino 개발환경과 속도 비교

RP2040 Arduino 개발환경에서 GPIO 속도 측정 결과와 비교하기위해 기본 예제 코드에서 GPIO 제어 코드를 이용해서 테스트 해보자

#include <stdio.h>
#include "pico/stdlib.h"

#define LED_PIN			2

int main() {
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);

	stdio_init_all();
	printf("RP2040 GPIO Speed Test\n");
    
    while (true) {
		gpio_put(LED_PIN, 1);
        gpio_put(LED_PIN, 0);
        
    }
    return 0;
}

 

GPIO토글 속도는 8.5ns(30Mhz)로 측정된다. Arduino에서처럼 루프 수행 지연없이 구동 되는것을 확인 할 수 있다.

 

 

레지스터 직업 제어로 속도가 더 빨라질 수 있을까 해서 테스트 해 봤는데 SDK가 inline 함수로 되어있어 이미 최적화 된것 같다. 동일한 속도가 출력이 된다.

 

#include <stdio.h>
#include "pico/stdlib.h"

#define LED_PIN			2

int main() {
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);

	stdio_init_all();
	printf("RP2040 GPIO Speed Test\n");
    
    while (true) {
		//gpio_put(LED_PIN, 1);
        //gpio_put(LED_PIN, 0);
		
		sio_hw->gpio_set = 0x01;
		sio_hw->gpio_clr = 0x01;		
    }
    return 0;
}

 

반응형