본문 바로가기

[ST_MICRO]/STM32F1

USB2CAN 보드 제작

USB2CAN 보드 제작



Main features
● Supports CAN protocol version 2.0 A, B Active
● Bit rates up to 1 Mbit/s
● Supports the Time Triggered Communication option
Transmission
● Three transmit mailboxes
● Configurable transmit priority
● Time Stamp on SOF transmission
Reception
● Two receive FIFOs with three stages
● 14 scalable filter banks/CAN cell - shared between CAN cells
● Identifier list feature
● Configurable FIFO overrun
● Time Stamp on SOF reception
Time Triggered Communication Option
● Disable automatic retransmission mode
● 16-bit free running timer
● Configurable timer resolution
● Time Stamp sent in last two data bytes
Management
● Maskable interrupts
● Software-efficient mailbox mapping at a unique address space
 
 
 
 
STM32 CAN 통신 모듈 블록도
3개의 Mailbox로 구성된 2개의 FIFO가 있어 총 6개의 Mailbox가 있다.



STM32 CAN인터럽트
인터럽트 소스는 여러가지 있지만 가장 많이 사용하게 될 소스는 CAN_RF0R, CAN_RF1R 이다. CAN 데이터가 Mailbox에 정상적으로 저장되면 이벤트를 발생하게 된다. 인터럽트 발생 하면 CAN FIFO에서 데이터를 꺼내오면 된다. 아래 코드를 보면 아주 간단하다는 것을 알 수 있다.




인터럽트 Handler 부분 
[stm32f10x_it.c]
void USB_LP_CAN_RX0_IRQHandler(void)
{
   wIstr = USB_Istr();
  
  if(CAN_GetITStatus(CAN_IT_FMP0) == SET)
  {
    CAN_Receive(CAN_FIFO0, &gRxMessage);
  
   gFlagCanInt = 1;  
  }
}
인터럽트 발생하면CAN_Receive() 함수를 이용해 데이터를 가져오면 된다.



USB와 CAN은 동일한 인터럽트 핸들러를 공유 하므로 고려할 부분이 있는데... 일단 USB, CAN을 동시에 사용하면 문제가 있는것 같다.

메뉴얼을 살펴보니 USB와 CAN은 512-SRAM을 사용하고 있는데... 이를 동시에 사용할 수 없다고 되어 있다. 버퍼를 잘 관리해서 쓰면 불가능 하지는 않겠지만 USB드라이버 쪽을 다시 제작해야 하는 아주 큰 문제가 발생할것 같다...
The USB and CAN share a dedicated 512-byte SRAM memory for data transmission and reception, and so they cannot be used concurrently (the shared SRAM is accessed through CAN and USB exclusively). The USB and CAN can be used in the same application but not at the same time.

물론 CAN포트가 2개 있는 칩으로 하면 문제 없지만 그러면 가격이 상승된다. 저렴한 CAN to USB 장치를 만드는 것이 목적 이었기 때문에 결국 이 문제를 해결하기 위해 다른칩(LM3S5x)으로 해결해야 했다.

USB2CAN 보드(http://nexp.tistory.com/966) 참고
반응형