'ChibiOS/RT'에 해당되는 글 3건

  1. 2018.02.25 ChibiOS/RT의 특징
  2. 2017.12.19 Cortex-M4 환경에서 ChibiOS 사용한 기초 예제
  3. 2017.11.03 VESC – Open Source ESC(1)


ChibiOS/RT는 Giovanni Di Sirio에 의해서 개발하였으며, 임베디드(embedded) 애플리케이션을 위한 무료이자 효율적이고, 컴팩트하며 빠른 RTOS(Real Time Operating System)입니다. Kernel primitive의 이해가 쉬운 세트를 제공하며 다양한 아키텍처(ARM7, Cortex-M0, Cortex-M3, Cortex-M4, PowerPC e200z, STM8, AVR, MSP430, ColdFire, H8S, x86)를 지원합니다. ChibiOS/RT는 RTOS로 GPL3 라이센스 하에서 배포됩니다.


ChibiOS/RT는 8, 16, 32-bit 마이크로컨트롤러의 임베디드 애플리케이션을 위해서 설계되었습니다; 사이즈와 실행 효율이 주요 프로젝트의 목표입니다. 참고로 커널 사이즈는 STM32 Cortex-M3 프로세스에서 활성화된 모든 서브시스템에서 최소 1.2KB에서 최대 5.5KB입니다. 커널은 초당 220,000 이상의 스레딩을 생성시키거나 종료할 수 있고, 72MHz의 STM32에서 1.2ms 내에 컨텍스트 스위칭(context switch)을 실행할 수 있습니다.


특징

  • Tiny memory footprint, 고성능, 쉬운 이식성(portable), 깔끔하고 이해가 쉽습니다.

  • 선점형 마이크로커널이자 멀티스레딩(multithreading), 128 우선 순위 레벨, 신뢰성 있고 정적 아키텍처.

  • Semaphores, Mutexes, CondVars, Messages, Event Flags, Mailboxes, Virtual Timers를 위한 커널 지원.

      • Counting semaphores

      • Mutexes with support for the priority inheritance algorithm

      • Condition variables

      • Synchronous and asynchronous Messages

      • Event flags and handlers

  • IRQ abstraction, non-OS fast IRQ sources(zero latency buzzword) 지원.

  • ARM, ARM-CM0, ARM-CM3, ARM-CM4, PowerPC, STM8, MSP430, AVR, ColdFire, H8S, Linux/Win32/MacOS 시뮬레이터를 지원.

  • HAL(Hardware Abstraction Layer) 컴포넌트는 지원되는 플랫폼 간에 애플리케이션의 이식이 가능.

  • Port(GPIO), Serial, ADC, CAN, DAC, EXT, GPT(general-purpose timer), I2C, I2S, ICU, MAC, MMC/SD, PAL, PWM, RTC, SDC, SPI, UART, USB, WDG 디바이스 드라이버 모델을 위한 HAL 지원.

  • uIP과 lwIP TCP/IP stacks(demo 포함)를 위한 지원.

  • FatFS 파일 시스템 라이브러리(demo 포함)를 지원.

  • 동일한 우선 순위 레벨에서 스레드를 위해서 Round-robin 스케쥴링

  • Software timers

  • Queues

  • Synchronous and asynchronous I/O with timeout capability

  • Thread-safe memory heap and memory pool allocators.


스레드, semaphore, 타이머와 같은 모든 시스템 객체는 실행 중에 생성되고 삭제될 수 있습니다. 가능한 메모리를 제외하고 어떤 상한이 없습니다. 시스템 신뢰성을 개선하기 위해서, 커널 아키텍처는 전체적으로 정적이고, memory allocator가 요구되지 않습니다(그러나 옵션으로 가능합니다). 그리고 테이블 혹은 배열과 같은 상한 사이즈 제한과 함께 어떠한 데이터 구조가 존재하지 않습니다. 시스템 API는 에러 코드나 예외와 같은 에러 조건을 갖지 않도록 설계되었습니다.


RTOS는 임베디드 디바이스 애플리케이션을 위해서 설계되었고 다양한 마이크로컨트롤러를 위한 데모 애플리케이션을 포함합니다:

  • ST STM32F1xx, STM32F2xx, STM32F3xx, STM32F4xx, STM32L1xx, STM32F0xx

  • ST STM8S208x, STM8S105x, STM8L152x

  • ST/Freescale SPC56x / MPC56xx

  • NXP LPC11xx, LPC11Uxx, LPC13xx

  • NXP LPC2148

  • Atmel AT91SAM7S, AT91SAM7X

  • Atmel Mega AVR

  • TI MSP430x1611

  • TI TM4C123G and TM4C1294

  • Microchip PIC32MX


소프트웨어 I/O 에뮬레이션(emulation) 모드로 Win32 프로세스에서 커널을 실행시키는 것이 가능합니다. 이는 물리적인 하드웨어의 요구 없이 쉬운 애플리케이션 개발을 허용합니다.




'Embedded Programming > ChibiOS' 카테고리의 다른 글

ChibiOS/RT 설치  (1) 2018.02.25
Cortex-M4 환경에서 ChibiOS 사용한 기초 예제  (0) 2017.12.19
Posted by Nature & Life
Embedded Programming/ChibiOS2017. 12. 19. 19:29


http://www.playembedded.org/blog/en/2017/08/24/demos-chibios-stm32/

http://www.playembedded.org/blog/en/2016/10/29/explanation-multithreading-chibios/


Cortex-M4 MCU(ST32F4)를 환경에서 Real Time OS(RTOS)인 ChibiOS를 이용한 임베디드(embedded) 시스템의 코딩의 예제입니다. 참고하시기 바랍니다.

 

주요 헤더 파일입니다.

chconf.h

Kernel에 관련된 세팅이 포함되며 예를 들어 시스템 Timer와 Kernel 파라미터, 디버깅에 연관된 스위치 등입니다.

/*===========================================================================*/
/**
* @name Debug options
* @{
*/
/*===========================================================================*/
 
/**
* @brief   Debug option, kernel statistics.
*
* @note    The default is @p FALSE.
*/
#define CH_DBG_STATISTICS                   FALSE
 
/**
* @brief   Debug option, system state check.
* @details If enabled the correct call protocol for system APIs is checked
*          at runtime.
*
* @note    The default is @p FALSE.
*/
#define CH_DBG_SYSTEM_STATE_CHECK           FALSE
 
/**
* @brief   Debug option, parameters checks.
* @details If enabled then the checks on the API functions input
*          parameters are activated.
*
* @note    The default is @p FALSE.
*/
#define CH_DBG_ENABLE_CHECKS                FALSE
 
/**
* @brief   Debug option, consistency checks.
* @details If enabled then all the assertions in the kernel code are
*          activated. This includes consistency checks inside the kernel,
*          runtime anomalies and port-defined checks.
*
* @note    The default is @p FALSE.
*/
#define CH_DBG_ENABLE_ASSERTS               FALSE
 
/**
* @brief   Debug option, trace buffer.
* @details If enabled then the trace buffer is activated.
*
* @note    The default is @p CH_DBG_TRACE_MASK_DISABLED.
*/
#define CH_DBG_TRACE_MASK                   CH_DBG_TRACE_MASK_DISABLED
 
/**
* @brief   Trace buffer entries.
* @note    The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
*          different from @p CH_DBG_TRACE_MASK_DISABLED.
*/
#define CH_DBG_TRACE_BUFFER_SIZE            128
 
/**
* @brief   Debug option, stack checks.
* @details If enabled then a runtime stack check is performed.
*
* @note    The default is @p FALSE.
* @note    The stack check is performed in a architecture/port dependent way.
*          It may not be implemented or some ports.
* @note    The default failure mode is to halt the system with the global
*          @p panic_msg variable set to @p NULL.
*/
#define CH_DBG_ENABLE_STACK_CHECK           FALSE
 
/**
* @brief   Debug option, stacks initialization.
* @details If enabled then the threads working area is filled with a byte
*          value when a thread is created. This can be useful for the
*          runtime measurement of the used stack.
*
* @note    The default is @p FALSE.
*/
#define CH_DBG_FILL_THREADS                 FALSE
 
/**
* @brief   Debug option, threads profiling.
* @details If enabled then a field is added to the @p thread_t structure that
*          counts the system ticks occurred while executing the thread.
*
* @note    The default is @p FALSE.
* @note    This debug option is not currently compatible with the
*          tickless mode.
*/
#define CH_DBG_THREADS_PROFILING            FALSE
 

/** @} */


halconf.h

ChibiOS/HAL 드라이버에 관련된 특성을 포함합니다. 예를 들어, PAL, CAN, ADC, DAC, PWM, Serial 드라이버 등이 해당됩니다. 참고로 사용하지 않는 드라이버는 disable 시켜야 합니다.


/**
* @brief   Enables the PAL subsystem.
*/
#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
#define HAL_USE_PAL                 TRUE
#endif
 
/**
* @brief   Enables the ADC subsystem.
*/
#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
#define HAL_USE_ADC                 FALSE
#endif
 
/**
* @brief   Enables the CAN subsystem.
*/
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
#define HAL_USE_CAN                 TRUE
#endif
 
/**
* @brief   Enables the DAC subsystem.
*/
#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
#define HAL_USE_DAC                 FALSE

#endif


mcuconf.h

MCU에 관련된 모든 설정을 포함합니다. 따라서 MCU에 따라 다릅니다. Clock 트리, DMA, IRQ 우선순위 등이 예입니다.


ChibiOS의 가장 중요한 특성 중의 하나는 멀티스레딩(multi-threading)입니다. 이는 Kernel이 한가지 이상의 스레드를 독립적으로 나란히 동시에 실행하는 것입니다. 스레드는 실제의 함수이고 시작되었을 때 우선순위 레벨(priority level)과 working area에 연관됩니다. Working area는 스레드에 할당된 메모리의 부분이고 우선 순위는 상대적인 숫자로 나타냅니다.


모든 스레드는 그 루프 내에 sleep과 suspending 함수를 가져야 합니다. 이런 방식으로 CPU의 소유권은 여러 스레드 사이에서 스위치 되고 스케쥴은 진행될 수 있습니다. ChibiOS는 다른 sleep 함수를 제공합니다. 다음 함수는 XXX [ms] 시간 동안 스레드를 suspending 합니다. 이 함수는 ChibiOS 이하의 os\rt\include\chthreads.h에 선언되어 있습니다.


chThdSleepMilliseconds(<xxx>);


Makefile

Embitz와 같은 IDE 환경을 사용시 일일이 지정해야 하고 IDE 툴마다 다를 수 있지만, 전통적인 Unix 환경에서 Makefile을 이용한 방법이 일목요연하고 유지관리가 용이하기 때문에 Makefile을 이용한 빌드 기준으로 설명합니다.


ChibiOS를 사용하기 위해서는 ChibiOS가 설치된 상대 경로의 지정이 필요합니다. 

# Imported source files and paths
PROJECT = build
CHIBIOS = ../../..
MCU = cortex-m4
TRGT = arm-none-eabi-


참고로 'build'는 프로젝트 이름이며 MCU는 cortex-m4이고 TRGT는 GNU Toolchain을 사용함을 의미합니다.

main.c

static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {
 
  (void)arg;
  chRegSetThreadName("Thread1");
  while (true) {
    palTogglePad(GPIOA, GPIOA_LED_GREEN);
    chThdSleepMilliseconds(200);
  }
}
 
int main(void) {
  halInit();
  chSysInit();
 
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
  while (true) {
    palTogglePad(GPIOA, GPIOA_LED_RED);
    chThdSleepMilliseconds(375);
  }

}


위의 예제에서 128byte의 크기를 갖는 waThread1라는 이름의 working area를 선언하고 Thread1이라는 함수를 선언합니다. 위의 두 라인은 단지 메모리와 함수를 선언한 것이며 main() 함수에서 thread 생성을 시켜야 사용할 수 있습니다. THE_FUNCTION의 arg는 함수 내부 코드로 전달되는 인자입니다.


chRegSetThreadName("blinker");


위 함수는 루프 이전에 단 한번 실행됩니다. 이 함수는 ChibiOS 이하의 os\rt\include\chregistry.h에 선언되어 있습니다.



main()함수 내의 2가지 함수가 실행되는데 이는 시스템 초기화를 실행하는 것으로, hallnit()는 ChibiOS/HAL과 HAL 서브 시스템을 초기화 하는 것이며 chSysInit()는 ChibiOS/RT의 API와 Kernel을 초기화합니다. 이후에는 main() 함수의 스레드와 다른 모든 스레드가 실행될 준비가 되지 않았을 때 실행되는 idle 스레드가 생성됩니다. 또한 이들 초기화 이전에 어떤 API의 실행은 하지 말아야 합니다. ChibiOS/RT 그리고 ChibiOS/HAL에 근거한 모든 프로그램은 위와 동일한 방식으로 시작합니다. 여기서 halInit() 함수는 ChibiOS 이하의 os\hal\include\hal.h에 그리고 chSysInit() 함수는 ChibiOS 이하의 os\rt\include\chsys.h에 선언되어 있습니다.


palTogglePad() 함수는 ChibiOS 이하의 os\hal\include\hal_pal.h에 선언되어 있으며, 첫번째 인자는 포트이고 두번째 인자는 그 포트 내에서의 패드 숫자입니다. 따라서 이 함수는 해당 포트의 해당 패드에 그 논리적인 상태 즉, LED를 토글(toggle)합니다.



chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);


위의 스레드의 생성 함수는 5개의 인자가 필요하며 첫번째는 working area의 포인트이며 마지막 인자는 Thread1 함수로 전달될 파라미터로 이 경우에는 아무것도 보내지 않습니다. 이 함수는 ChibiOS 이하의 os\rt\include\chthreads.h에 선언되어 있습니다.


이 경우에 3개의 스레드인, Thead1, main, idle가 있으며 즉, Kernel은 3가지 스레드를 관리게 되는데 개념적인 timing 플로우는 다음과 같습니다.



위 그림에서 스레드는 y축 상에 우선순위에 따라 실행되고 x축은 시간이 됩니다. chSysInit()이 실행될 때 main() 함수는 main이라는 스레드가 되고 Thread1의 생성될 때까지 실행됩니다. Thread1이 생성된 후에는 main와 Thread1이 준비된 상태가 됩니다. 


ChibiOS의 우선순위는 정수이고 LOWPRIO와 HIGHPRIO의 범위를 가지며 main 스레드는 NORMALPRIO의 우선 순위를 가지며 전체 범위의 중간 값을 가집니다. Thread1과 main() 함수 내에 chThdSleepMilliseconds() 함수는 시간을 지연시키지만 그 동안 CPU의 소유권을 다음의 우선순위 스레드에 넘기게 됩니다.



'Embedded Programming > ChibiOS' 카테고리의 다른 글

ChibiOS/RT 설치  (1) 2018.02.25
ChibiOS/RT의 특징  (0) 2018.02.25
Posted by Nature & Life


출처 : By Benjamin Vedder

http://vedder.se/2015/01/vesc-open-source-esc/

http://vesc-project.com/

https://github.com/vedderb/bldc(bldc 펌웨어 설계) : 모든 하드웨어 버젼에 사용

https://github.com/vedderb/bldc-hardware(bldc 하드웨어 설계) : v4.12까지

http://vesc-project.com/node/311(bldc 하드웨어 설계) : v6.4부터

https://github.com/vedderb/bldc-tool(bldc-tool 설계) : v2.18까지

https://github.com/vedderb/vesc_tool(vesc-tool 설계, bldc-tool의 새로운 버젼)

https://github.com/vedderb/bldc-logger(bldc-logger 설계)

https://github.com/vedderb(기타 프로젝터 설계)


VESC – Open Source ESC

Posted on January 7, 2015 and Post updated 2016-01-22


About this project

I have made many updates to my custom motor controller recently and the old post is getting confusing with notes and updates, I decided to write a new post about it that hopefully is more clear, more complete and easier to follow. This might sound a bit ambitions, but my goal is to make the best ESC available. I really enjoy sharing knowledge, so I want to keep all the hardware and software open.

저는 최근에 제 모터 제어기에 많은 개선을 해왔습니다 그리고 이전에 게시된 내용은 설명과 업데이트에서 혼선을 일의키고 있고, 저는 좀더 분명하고 좀더 완전하며 좀더 이해하기 쉽게 하기 위해서 새로운 게시글을 작성하기로 하였습니다. 이는 약간 애매할 수도 있지만 저의 분명한 목표는 가장 좋은 ESC를 만드는 것입니다. 저는 사실 지식을 공유하는 것을 즐깁니다. 따라서 저는 모든 하드웨어와 소프트웨어를 공개하기를 원합니다.


This is an overview of the schematic (download a complete PDF here):


This is the front of the PCB:


The back:


3D render from KiCad:


Some screenshots of the configuration GUI (BLDC Tool):


Resources

All files are on github to keep them up to date, so check these links on a regular basis:


Related posts


Forums

Because information about the VESC is scattered all over the internet and a lot of information is in email conversations with me, I have created a forum dedicated to the VESC here.

VESC에 대한 정보는 인터넷 상에서 퍼져있기 때문에 많은 정보는 저와 이메일로 대화합니다. 저는 여기에 VESC에 대한 포럼을 만들었습니다.


Live Chat

I have created an IRC channel on freenode where you can live chat with me and other users about VESC and my other projects. Feel free to join: http://webchat.freenode.net/?channels=vedder


Features

    • 하드웨어와 소프트웨어는 오픈소스입니다. 다양한 CPU 리소스가 남았기 때문에 사용자 최적화는 무한합니다.

    • STM32F4 microcontroller.

    • DRV8302 MOSFET driver / buck converter / current shunt amplifier.

    • IRFS7530 MOEFETs (other FETs in the same package also fit).

    • DRV8302에 집적화된 buck converter로부터 외부 전자장치를 위한 5V 1A 출력.

    • Voltage: 8V – 60V (Safe for 3S to 12S LiPo).

    • Current: 수 초동안 250A까지 혹은 온도와 PCB 주변에 공기 순환에 의존하여 연속적인 약 50A.

    • Sensored and sensorless FOC wich auto-detection of all motor parameters is implemented since FW 2.3.

    • Firmware based on ChibiOS/RT.

    • PCB size: slightly less than 40mm x 60mm.

    • Current and voltage measurement on all phases.

    • Regenerative braking.

    • DC motors are also supported.

    • Sensored or sensorless operation.

    • A GUI with lots of configuration parameters.

    • Adaptive PWM frequency to get as good ADC measurements as possible.

    • RPM-based phase advance (or timing/field weakening).

    • Good start-up torque in the sensorless mode (and obviously in the sensored mode as well).

    • The motor is used as a tachometer, which is good for odometry on modified RC cars.

    • Duty-cycle control(voltage control), speed control or current control.

    • Seamless 4-quadrant operation.

    • Interface to control the motor: PPM signal (RC servo), analog, UART, I2C, USB  or CAN-bus.

    • Wireless wii nunchuk (Nyko Kama) control through the I2C port. This is convenient for electric skateboards.

    • Consumed and regenerated amp-hour and watt-hour counting.

    • Optional PPM signal output. Useful when e.g. controlling an RC car from a raspberry pi or an android device.

    • USB포트는 모뎀 프로파일을 사용합니다. 그래서 안드로이드 디바이스는 루팅 없이 모터 제어기에 연결할 수 있습니다. 서보 출력, 주행거리계(odometry) 그리고 여분의 ADC 입력(센서를 위하여 사용될 수 있슴) 때문에 이것은 안드로이드( 혹은 raspberry pi)로 제어되는 RC 카를 개조하기에 완벽합니다.

    • Adjustable protection against

        • Low input voltage

        • High input voltage

        • High motor current

        • High input current

        • High regenerative braking current (separate limits for the motor and the input)

        • Rapid duty cycle changes (ramping)

        • High RPM (separate limits for each direction).

    • 전류 한계에 도달했을 때 모터가 동작을 유지하면서 soft back-off 전략이 사용됩니다. 만일 전류가 너무 높다면, 모터는 완전하게 OFF 됩니다.

    • RPM limit은 또한 soft back-off 전략을 갖습니다.

    • Commutation은 모터 속도가 급격하게 변동할 때 조차도 완벽하게 동작합니다. 이는 이전 속도에 근거하여 지연을 추가하는 것 대신에 zero crossing 후에 자속을 적분한다는 사실 때문입니다. 

    • 제어기가 커진 동안에 모터가 회전할 때 commutation과 회전방향은 추적됩니다. 같은 속도를 얻기 위해서 듀티 싸이클이 또한 계산됩니다. 이는 모터가 이미 회전중일 때 부드러운 출발을 얻게 합니다. 

    • 모든 하드웨어는 센서 없는 자속 기준 제어(field-oriented control; FOC)를 위해서 준비되었습니다. 소프트웨어를 작성하는 것이 남아있습니다. 그러나 저는 FOC가 조금 정숙하게 동작한다는 것 외에 저 인덕턱스 고속 모터에 대하여 많은 이득을 갖는 것인지 아닌지 확신하지 못합니다. 센서 그리고 센서 없는 FOC는 FW 2.3 이후에 완전하게 구현되었습니다.



Posted by Nature & Life