STM32F1 CAN

Started by tha, January 29, 2021, 09:07:28 AM

Previous topic - Next topic

tha

24 Controller area network (bxCAN)

Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
High-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 256 and 512 Kbytes.
XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 768 Kbytes and 1 Mbyte.
Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.

ส่วนนี้ใช้กับ the connectivity line and STM32F103xx performance line เท่านั้น.

24.1 bxCAN introduction

The Basic Extended CAN peripheral, ชื่อ bxCAN, เชื่อมต่อ the CAN network. มันรองรับ the CAN protocols version 2.0A and B. มันถูกออกแบบเพื่อจัดการ a high number of incoming messages อย่างมีประสิทธิภาพด้วย a minimum CPU load. มันตรงตาม the priority requirements สำหรับ transmit messages อีกด้วย.

สำหรับ safety-critical applications, the CAN controller จัดให้มีทุก hardware functions สำหรับการรองรับ the CAN Time Triggered Communication option.

tha

24.2 bxCAN main features

•    รองรับ CAN protocol version 2.0 A, B Active
•    Bit rates สูงถึง 1 Mbit/s
•    รองรับ the Time Triggered Communication option

Transmission

•    3 transmit mailboxes
•    กำหนดค่าได้ transmit priority
•    Time Stamp on SOF transmission

Reception

•    2 receive FIFOs พร้อมด้วย 3 stages
•    ปรับขนาดได้ filter banks:
     –    28 filter banks ใช้ร่วมกันระหว่าง CAN1 and CAN2 ใน connectivity line devices
     –    14 filter banks ใน STM32F10xxx devices อื่นๆ
•    Identifier list คุณลักษณะ
•    กำหนดค่าได้ FIFO overrun
•    Time Stamp on SOF reception

Time-triggered communication option

•    ปิดการใช้งาน automatic retransmission mode
•    16-bit free running timer
•    Time Stamp ส่งใน last two data bytes

Management

•    Maskable(บังได้) interrupts
•    Software-efficient mailbox แม็ปที่ a unique address space

Dual CAN

•    CAN1: Master bxCAN สำหรับจัดการ the communication ระหว่าง a Slave bxCAN และ the 512-byte SRAM memory
•    CAN2: Slave bxCAN, พร้อมด้วยไม่มีการเข้าถึงโดยตรงไปยัง the SRAM memory.
•    The two bxCAN cells ใช้ร่วมกัน the 512-byte SRAM memory (ดู Figure 223)

Note: In low, medium-, high- and XL-density devices the USB and CAN ใช้ร่วมกัน a dedicated 512-byte SRAM
           memory สำหรับ data transmission and reception, และดังนั้นพวกมันไม่สามารถถูกใช้พร้อมกันy (the shared SRAM ถูก
           เข้าถึงผ่านทาง CAN and USB อย่างเฉพาะตัว). The USB and CAN สามารถถูกใช้ใน the same application แต่ไม่ในเวลา
           เดียวกัน.

tha

24.3 bxCAN general description

ใน CAN applications ปัจจุบันนี้, จำนวนของ nodes ใน a network กำลังเพิ่มขึ้นและบ่อยครั้งหลาย networks ถูกเชื่อมต่อเข้าด้วยกันโดยทาง gateways. โดยทั่วไปจำนวนของ messages ใน the system (และดังนั้นถูกรับมือโดยแต่ละ node) ถูกเพิ่มขึ้นอย่างมีนัยสำคัญ. นอกจากนี้ the application messages, Network Management and Diagnostic messages ถูกแนะนำมา.
•    An enhanced filtering mechanism ถูกต้องการเพื่อรับมือแต่ละชนิดของ message.

นอกจากนี้, application tasks ต้องการ CPU time ที่มากขึ้น, ดังนั้น real-time constraints ที่มีสาเหตุโดย message reception ต้องถูกลดลง.
•    A receive FIFO scheme ยอมให้ the CPU ทุ่มเทให้กับ application tasks เป็นเวลา a long time period โดยปราศจาก losing
      messages.

The standard HLP (Higher Layer Protocol) ที่ใช้ standard CAN drivers ต้องการอินเตอร์เฟซที่มีประสิทธิภาพไปยัง the CAN controller.




tha

24.3.1 CAN 2.0B active core

The bxCAN module จัดการ the transmission and the reception of CAN messages อย่างเต็มที่โดยอัตโนมัติ. Standard identifiers (11-bit) and extended identifiers (29-bit) ถูกรองรับอย่างเต็มที่โดย hardware.

24.3.2 Control, status and configuration registers

The application ใช้ registers เหล่านี้เพื่อ:
•    Configure CAN parameters, อย่างเช่น baud rate
•    Request transmissions
•    Handle receptions
•    Manage interrupts
•    Get diagnostic information

tha

24.3.3 Tx mailboxes

Three transmit mailboxes ถูกจัดให้กับ the software สำหรับตั้งค่า messages. The transmission Scheduler ตัดสินว่า mailbox ใดต้องถูกส่งเป็นอันดับแรก

24.3.4 Acceptance filters

The bxCAN จัดให้มี 28 scalable/configurable identifier filter banks สำหรับการเลือก the incoming messages ที่ the software ต้องการและละทิ้งข้อความอื่น. ใน devices อื่นจะมี 14 scalable/configurable identifier filter banks.

Receive FIFO

Two receive FIFOs ถูกใช้โดย hardware เพื่อเก็บ the incoming messages. Three complete messages สามารถถูกเก็บในแต่ละ FIFO. The FIFOs ถูกจัดการอย่างสมบูรณ์โดย hardware.


tha

24.4 bxCAN operating modes

bxCAN มี three main operating modes: initialization, normal and Sleep. หลังจาก a hardware reset, bxCAN อยู่ใน Sleep mode เพื่อลด power consumption และ an internal pullup จะ active บน CANTX. The software ร้องขอ bxCAN เพื่อเข้าสู่ initialization หรือ Sleep mode โดยการเซ็ต the INRQ หรือ SLEEP bits ใน the CAN_MCR register. เมื่อ the mode นั้นได้ถูกเข้าสู่แล้ว, bxCAN ยืนยันมันโดยการเซ็ต the INAK หรือ SLAK bits ใน the CAN_MSR register และ the internal pull-up ถูกปิดการใช้งาน. เมื่อไม่มี INAK หรือ SLAK ถูกเซ็ต, bxCAN อยู่ใน normal mode. ก่อนการเข้าสู่ normal mode bxCAN ต้อง synchronize เสมอบน the CAN bus. เพื่อ synchronize, bxCAN คอยจนกระทั่ง the CAN bus เป็น idle, นี้หมายถึง 11 consecutive recessive bits ถูกมอนิเตอร์แล้วบน CANRX.

tha

24.4.1 Initialization mode

The software initialization สามารถถูกทำในขณะที่ the hardware อยู่ใน Initialization mode. เพื่อเข้าสู่โหมดนี้ the software เซ็ต the INRQ bit ใน the CAN_MCR register และคอยจนกระทั่ง the hardware ถูกยืนยันการร้องขอโดยการเซ็ต the INAK bit ใน the CAN_MSR register.

เพื่อออกจาก Initialization mode, the software เคลียร์ the INQR bit. bxCAN ถูกออกจาก Initialization mode เมื่อ the INAK bit ถูกเคลียร์แล้วโดย hardware.

ขณะใน Initialization Mode, message ทั้งหมดส่งถ่ายถึงและจาก the CAN bus ถูกหยุดและสถานะของ the CAN bus output CANTX ถอน (high).

การเข้าสู่ Initialization Mode ไม่ได้เปลี่ยนแปลง the configuration registers ใดๆ.

เพื่อเริ่มต้น the CAN Controller, software ต้องตั้งค่า the Bit Timing (CAN_BTR) และ CAN options (CAN_MCR) registers

เพื่อเริ่มต้น the registers ที่เกี่ยวข้องกับ the CAN filter banks (mode, scale, FIFO การกำหนดค่า, การเปิดใช้งาน และ filter values), software ต้องเซ็ต the FINIT bit (CAN_FMR). Filter initialization สามารถถูกทำภายนอก the initialization mode ได้อีกด้วย.

Note: เมื่อ FINIT=1, CAN reception จะถูกปิดใช้งาน

            The filter values สามารถถูกแก้ไขโดยปิดใช้งาน the associated filter activation bits (ใน the CAN_FA1R register)
            ได้อีกด้วย.

             ถ้า a filter bank ไม่ถูกใช้, ขอแนะนำให้ปล่อยมันไม่ให้ทำงาน (ปล่อยให้ the corresponding FACT bit เคลียร์).

tha

24.4.2 Normal mode

เมื่อ the initialization เสร็จสมบูรณ์, the software ต้องร้องอ the hardware เพื่อเข้าสู่ Normal mode เพื่อให้สามารถ synchronize บน the CAN bus และสตาร์ท reception and transmission.

การร้องขอเพื่อเข้าสู่ Normal mode ถูกปล่อยออกโดยการเคลียร์ the INRQ bit ใน the CAN_MCR register. The bxCAN เข้าสู่ Normal mode และพร้อมที่จะมีส่วนร่วมใน bus activities เมื่อมันได้ synchronized กับ the data transfer บน the CAN bus. นี้ทำได้โดยการรอการเกิดลำดับของ 11 consecutive recessive bits (Bus Idle state). การสวิทช์ไปยัง Normal mode ถูกยืนยันโดย the hardware โดยการเคลียร์ the INAK bit in the CAN_MSR register.

การเริ่มต้นของ the filter values เป็นอิสระจาก Initialization Mode แต่ต้องถูกทำในขณะที่ the filter ไม่ active (corresponding FACTx bit ถูกเคลียร์). The filter scale และ mode configuration ต้องถูกกำหนดค่าก่อนการเข้าสู่ Normal Mode.