A bottom-layer driver design method based on a board interface
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-17
- Publication Date
- 2026-08-11
AI Technical Summary
[0003]但是该系统芯片提供的接口操作函数更偏向对硬件的设置和使用,无法灵活的满足通用性应用层软件的开发需求
[0022]上述技术方案所提供的基于板卡接口的底层驱动设计方法,在系统为通用性MCU的GD32系列的应用场景下,针对芯片特点,并结合芯片接口函数设计而实现;本发明为板卡为GD32系列下,首先使用板卡自带的接口函数对板卡进行初始化,然后针对应用层使用场景设计基于接口的驱动,为应用程序的开发设计提供封装接口,节省开发成本。
Abstract
Description
Technical Field
[0001] This invention belongs to the field of driver technology for microcontroller systems, and relates to a low-level driver design method based on board interface. Background Technology
[0002] The GD32F4xx series devices are based on Cortex TM - A 32-bit general-purpose microcontroller with an M4 processor. Cortex TM The M4 processor includes three AHB buses, referred to as the I-CODE bus, D-Code bus, and system bus. Cortex TM All memory accesses by the M4 processor, depending on the purpose and target memory space, are performed on these three buses. The memory organization adopts a Harvard architecture, with predefined memory mappings and up to 4GB of storage space, ensuring full system flexibility and scalability.
[0003] However, the interface operation functions provided by this system chip are more geared towards hardware settings and usage, and cannot flexibly meet the development needs of general-purpose application layer software. Therefore, it is necessary to further develop and encapsulate the board's interface operation functions to provide a convenient interface driver for upper-layer applications to call. Summary of the Invention
[0004] (I) Purpose of the Invention
[0005] The purpose of this invention is to provide a low-level driver design method based on board interface, which solves the interface driver problem on the ARM platform.
[0006] (II) Technical Solution
[0007] To address the aforementioned technical issues, this invention provides a low-level driver design method based on board interface. For development and design, users first need to initialize the board resources, and then, according to the application scenario, call the peripheral access operation driver interface.
[0008] S1: Initialize board interface
[0009] Configure the system clock for the board and divide the clock frequency for the delay function execution. Also, initialize the serial port interface, timer interface, Flash interface, and digital input / output interface.
[0010] S2: Peripheral access operation driver interface
[0011] This provides operation interfaces for the board's peripherals, eliminating the need for users to operate or configure the underlying hardware. Users simply need to call the operation interfaces according to the specific scenario to meet functional requirements. The operation interfaces are categorized as follows:
[0012] Serial port operation driver interface
[0013] First, provide a data sending interface; finally, provide a data receiving interface.
[0014] Timer operation driver function
[0015] Provides a timer interrupt interface.
[0016] Flash operation driver interface
[0017] First, it provides functions for initializing Flash operations; then, it provides functions for writing to Flash; and finally, it provides functions for reading from a fixed address in Flash.
[0018] Switching input driver interface
[0019] First, set up the switch status interface; then, obtain the switch status interface.
[0020] By following the steps above, you can implement the interface driver for the ARM system.
[0021] (III) Beneficial Effects
[0022] The underlying driver design method based on the board interface provided by the above technical solution is implemented in the application scenario of the GD32 series of general-purpose MCUs, taking into account the characteristics of the chip and combining the chip interface function design. The present invention is for the GD32 series of boards. First, the board is initialized using the interface functions built into the board. Then, the interface-based driver is designed for the application layer usage scenario, providing a packaged interface for the development and design of the application and saving development costs. Detailed Implementation
[0023] To make the objectives, contents, and advantages of the present invention clearer, the specific embodiments of the present invention will be described in further detail below with reference to examples.
[0024] To solve the interface driver problem under the ARM system, we adopted a method of secondary development based on the board's own interface functions, including the following steps:
[0025] Step 1: Initialize the board interface
[0026] Configure the system clock for the board and divide the clock frequency for the delay function execution. Simultaneously initialize the serial port, timer, Flash, and digital input interfaces. The specific steps are as follows:
[0027] S11: Sets the system clock to an interrupt with a frequency (e.g., 1000Hz). That is, when the system function sysTick_config executes a loop statement until an error is caught, it takes a certain value as input parameter (the value is the result of dividing the system clock SystemCoreClock by 1000) and the result is 1.
[0028] S12: Use the system function NVIC_SetPriority to configure the priority of system clock processing.
[0029] S13: Set initial serial port parameters. The specific steps are as follows:
[0030] S131: Set the initial serial port parameter interface name to InitUserSerial;
[0031] S132: Set the input parameters of the interface function InitUserSerial to the serial port number and baud rate;
[0032] S133: Sets the serial port name macro definition, assigning serial port numbers to both Uart and Usart types of board resources, and uniformly scheduling them to users as USER_COM_X (X being the serial number). Users do not distinguish between the two types of serial ports.
[0033] S134: Sets the reset clock macro definition for the transmitter's general purpose input / output (GPIO) pins;
[0034] S135: Sets the reset clock macro definition for the receiver's general purpose input / output (GPIO) pins;
[0035] S136: Set the serial port reset clock macro definition;
[0036] S137: Macro definition for setting the GPIO pin number sequence for serial port transmission;
[0037] S138: Sets the GPIO pin number sequence macro definition for serial port reception;
[0038] S139: Set the GPIO group macro definition for serial port transmission;
[0039] S1310: Sets the GPOO group macro definition for serial port reception;
[0040] S1311: Sets the macro definition for the GPIO spare function pins for serial port transmission and reception;
[0041] S1312: Set the macro definition for the serial port interrupt number;
[0042] S1313: Determine if the serial port number of the input parameter is out of bounds. If it is, return and exit; otherwise, proceed to the next step.
[0043] S1314: Enables the serial port's receive, transmit, and port reset clock;
[0044] S1315: Use system functions to set the spare GPIO function pins for serial port transmission and reception;
[0045] S1316: Sets the pin mode (input or output) of the serial port transmit and receive GPIO;
[0046] S1317: Configure the output options for the GPIO pin of the serial port transmit function;
[0047] S1318: Disabled serial port;
[0048] S1319: Set the serial port baud rate, data bits, stop bits, and parity bits;
[0049] S1320: Disable serial port hardware flow control operations (CTS / RTS);
[0050] S1321: Enable serial port transmit and receive functions;
[0051] S14: Initialize the timer interface void init_timer(uint8_t id, bool state, uint16_tn), implemented as follows:
[0052] S141: Enable the timer clock for the input ID number;
[0053] S142: Configure the timer's division ratio;
[0054] S143: Reset timer;
[0055] S144: Set timer mode;
[0056] S145: Set the timer frequency n;
[0057] S146: Configure the timer using configuration parameters;
[0058] S147: Enable Automatic Reload Shadow Register;
[0059] S148: Clear timer interrupt flag;
[0060] S149: Interrupt enable;
[0061] S1410: Enable timer based on input parameter state;
[0062] S15: The Flash operation interface function `void Flash_IF_Init(void)` is initialized, and its implementation is as follows:
[0063] S151: Use the library function fmc_unlock to unlock the flash address;
[0064] S152: Use the library function fmc_flag_clear to clear the operation flag;
[0065] S16: Initialize the switch operation interface. Initialize the switch: int8_t initGpio(uint8_tindex, uint8_t dir), the specific implementation is as follows:
[0066] S161: Macro definition of GPIO group clock, GPIO group type, and GPIO group sequence number;
[0067] S162: Determine if the input GPIO index is valid. If it is, proceed to the next step; otherwise, return 0.
[0068] S163: Use the index entered by the user to obtain the GPIO group and the index within the GPIO group;
[0069] S164: Enables the GPIO clock;
[0070] S165: Determine whether the GPIO direction value input by the user is an input or an output. If it is an input, use the library function gpio_mode_set to set the GPIO represented by the index as an input switch value. Otherwise, set the GPIO as an output switch value.
[0071] S166: Use the library function gpio_output_options_set to set gpio attributes;
[0072] a.S167: Returns 1;
[0073] Step 2: Serial port operation driver interface
[0074] S21: First, provide a data sending interface. Based on the application layer's data sending requirements, the following interfaces are provided:
[0075] S211: Send a single byte at a time: void SerialPutChar(uint8_t c), the specific steps are as follows:
[0076] S2111: Send a single byte using the library function usart_data_transmit;
[0077] S2112: Use the library function usart_flag_get to check in a loop whether the USART_FLAG_TC sending flag has been reset. If it has, wait in the loop; otherwise, exit the loop to indicate that the sending was successful.
[0078] S212: Send one string at a time: void Serial_PutString(uint8_t*s), the specific steps are as follows:
[0079] S2121: Loop through and check if the current character is the null terminator '\0'. If it is, exit the sending process; otherwise, proceed to the next step.
[0080] S2122: Send a single byte using the library function usart_data_transmit;
[0081] S2123: Use the library function usart_flag_get to check in a loop whether the transmission flag USART_FLAG_TC has been reset. If it has, wait in the loop; otherwise, exit the loop to indicate that the transmission was successful.
[0082] S2124: Move the string pointer and jump to step S2121;
[0083] S213: Send a fixed number of bytes each time: uint16_t serial_send(uint8_t ComNum, uint8_t*pWriteBuffer, uint16_tWriteSize), the specific steps are as follows:
[0084] S2131: The serial port name number that can be used by the macro definition;
[0085] a.S2132: Determine if the serial port number is valid. If it is, exit; otherwise, proceed to the next step.
[0086] S2133: Loop through and check if the number of writable bytes WriteSize is greater than 0. If WriteSize is greater than 0, subtract 1 from it. If it is, use the library function usart_data_transmit to send the character content pointed to by the current pWriteBuffer. Otherwise, jump to step S2138.
[0087] S2134: Use the library function usart_flag_get to check in a loop whether the transmission flag USART_FLAG_TC has been reset. If it has, wait in the loop; otherwise, exit the loop to indicate that the transmission was successful and proceed to the next step.
[0088] S2135: Record the number of bytes sent (count) and increment it by 1;
[0089] S2136: Move the data transmission pointer pWriteBuffer, i.e., increment it by 1;
[0090] S2137: Jump to step S2133;
[0091] S2138: Returns the count of bytes sent;
[0092] S214: DMA sends fixed bytes: usart_dma_send(uint8_t ComNum, uint8_t*pWriteBuffer, uint16_tWriteSize);
[0093] S2141: Clock that enables DMA transfer;
[0094] S2142: Fixed channel with DMA transfer disabled;
[0095] S2143: Set initial DMA parameters;
[0096] S2144: Configure DMA mode;
[0097] S2145: Disabled cyclic transmission function;
[0098] S2146: Set up the DMA channel;
[0099] S2147: Set the starting address for sending;
[0100] S2148: Set the length of data to be sent;
[0101] S2149: Use the library function dma_flag_get to get whether the DMA transfer flag DMA_INTF_FTFIF has been reset. If it has, continue the loop; otherwise, it means that the transmission is complete.
[0102] S22: Provides a data receiving interface. The specific steps are as follows:
[0103] S221: Receive one byte from the serial port device: `uint32_t serialKeyGet(unsigned char comNum, uint8_t *key)`. Implementation is as follows:
[0104] S2211: Determine if the serial port number is valid. If it is, proceed to the next step; otherwise, return 1 and exit the process.
[0105] S2212: Use the library function usart_flag_get to determine the value of the receive flag, i.e. whether data has been received. If yes, proceed to the next step; otherwise, return 2 and exit the process.
[0106] S2213: Use the library function usart_flag_clear to clear the receive flag;
[0107] S2214: Use the library function usart_data_receive to retrieve the received data and store it in the parameter key;
[0108] S2215: Returns 0;
[0109] S222: Read a fixed number of bytes from the serial port: uint16_t serial_recv(uint8_tComNum, uint8_t*pReadBuffer, uint16_t ReadSize), implemented as follows:
[0110] S2221: Initialize the receive data variable key to zero and the receive count to 0;
[0111] S2222: Determine if the serial port number is valid. If it is, proceed to the next step; otherwise, return 0 to exit the process.
[0112] S2223: Enter the receiving loop;
[0113] S2224: Use the receive function serialKeyGet to determine if there is data to be received. If so, store the currently received data content in key and proceed to the next step; otherwise, exit the receive loop and return the count of received data.
[0114] S2225: Place the received data key into the address pointed to by the receive buffer pointer pReadBuffer;
[0115] S2226: Move the receive buffer pointer pReadBuffer forward;
[0116] S2227: Add a value to the record for the number of received data entries;
[0117] S2228: Determine if the value of count is the number of reads specified by the user (ReadSize). If it is, exit the receiving loop and return the value of count; otherwise, jump to step S2221.
[0118] S223: DMA receive fixed bytes: usart_dma_recv(uint8_t ComNum, uint8_t*pReadBuffer, uint16_t ReadSize);
[0119] S2231: Clock that enables DMA transfer;
[0120] S2232: Set initial DMA parameters;
[0121] S2233: Configure DMA mode;
[0122] S2234: Disables the fixed channel for DMA receive transmission;
[0123] S2235: Set the receive start address pReadBuffer;
[0124] S2236: Set the length of received data (ReadSize);
[0125] S2237: Set the DMA receive channel;
[0126] S2238: Disable the loop function of the receive channel;
[0127] S2239: Peripheral sub-device for setting up the receiving channel;
[0128] S22310: Use the library function dma_flag_get to get whether the DMA transfer flag DMA_INTF_FTFIF has been reset. If it has, continue the loop; otherwise, it means that the reception is complete.
[0129] Step 3: Timer Interrupt Driver Interface
[0130] The timer interrupt handling interface is a function that is called for each interrupt, allowing users to manage time.
[0131] The timer interrupt handling interface voidtimer_handler() is implemented as follows:
[0132] S31: Use the library function timer_interrupt_flag_get to check if the interrupt flag TIMER_INT_UP is set. If it is, proceed to the next step; otherwise, exit the process and wait for the next interrupt.
[0133] S32: Use the library function timer_interrupt_flag_clear to clear the interrupt flag TIMER_INT_UP;
[0134] S33: Records the timer's flag incrementing;
[0135] S34: Divide the flag by integers according to user requirements to obtain the number of time intervals of other magnitudes;
[0136] Step 4: Flash operation driver functions
[0137] The specific implementation interface is as follows:
[0138] S41: The function for writing to a fixed address in Flash is: int16_t Flash_WriteByte(__IO uint32_t address, uint32_t *buffer, uint16_t length), implemented as follows:
[0139] S411: Use the library function fmc_sector_erase to erase the contents of a fixed sector region address;
[0140] S412: Determine if the length len of the data to be written is greater than 0. If it is, proceed to the next step; otherwise, return 1 and exit the process.
[0141] S413: Use the library function fmc_word_program to write data stored in the buffer starting from the fixed address of flash, and determine whether the write operation is successful. If it is, proceed to the next step; otherwise, return -1 and exit the process.
[0142] S414: Use the library function REG32 to read back the data stored at the address and determine whether it is consistent with the content stored at the address of the data buffer to be written. If it is, proceed to the next step; otherwise, return -2 and exit the process.
[0143] S415: Move the Flash address forward by 4 positions;
[0144] S416: The data buffer's head pointer moves one position;
[0145] S417: Subtract 1 from the length len of the data to be written;
[0146] S418: Return to step S412;
[0147] S42: Function to read Flash from a fixed address: uint32_tFlash_ReadByte(uint8_t*data, uint16_t len, __IO uint32_t address), implemented as follows:
[0148] S421: Check if the address is valid. If it is, proceed to the next step; otherwise, return 0.
[0149] S422: Check if the length len of the data to be read is greater than 0. If it is, proceed to the next step; otherwise, return 1.
[0150] S423: Use the library function REG32 to read data from a fixed address and store it at the address pointed to by the data storage buffer pointer data;
[0151] S424: Move to read address;
[0152] S425: Move storage data buffer;
[0153] S426: Decrement the data length by 1;
[0154] S427: Return to step S422;
[0155] Step 5: Switch operation driver interface
[0156] First, configure the switch status interface. Then, obtain the switch status interface.
[0157] S51: Interface for setting switch status: int8_t IoRelayWrite(uint8_t index, int8_t high_or_low), the specific implementation is as follows:
[0158] S511: Macro definition of GPIO group and GPIO group sequence number;
[0159] S512: Check if the index is valid. If it is, proceed to the next step; otherwise, return -1 and exit.
[0160] S513: Obtain the GPIO group and sequence number id based on the input sequence number index;
[0161] S514: Determine if the set value high_or_low is 1. If it is, use the library function gpio_bit_set to set the switch with the sequence number id in the current GPIO group to 1; otherwise, set it to 0.
[0162] S515: Returns 1;
[0163] S52: Interface for obtaining switch status: FlagStatus IoReadBack(uint8_t index), the specific implementation is as follows:
[0164] S521: Macro definition of GPIO group and GPIO group sequence number;
[0165] S522: Determine if the index is valid. If it is, proceed to the next step; otherwise, return -1 and exit.
[0166] S523: Obtain the GPIO group and sequence number id based on the input sequence number index;
[0167] S524: Use the library function gpio_input_bit_get to get the status value (status) of the switch quantity with the sequence number id in the current group;
[0168] S525: Returns status.
[0169] In this embodiment, a return value of 1 indicates that the serial port number parameter is invalid; a return value of -1 indicates that the write operation failed; a return value of 0 indicates that the program has ended; a return value of 2 indicates that no data has been received; and a return value of -2 indicates that the data is inconsistent.
[0170] Using the above technical solution and operating steps, this invention can solve the driver problem under the ARM system. The method has been verified through algorithm validation and experimental testing. Results show that this solution can provide a secondary encapsulated interface driver for applications within a single board, facilitating application operation of interface devices, saving development costs, and effectively shortening development time.
[0171] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A low-level driver design method based on board interface, characterized in that, Includes the following steps: Step 1: Initialize the board interface Configure the system clock for the board and divide the clock frequency for the delay function execution; at the same time, initialize the serial port, timer, Flash, and switch interface; Specifically, it includes the following sub-steps: S11: Sets the system clock to a frequency interrupt. That is, when the system function sysTick_config executes the system clock SystemCoreClock divided by 1000 and the result is 1, the loop statement is executed until an error is caught. S12: Configure the priority of system clock processing using the system function NVIC_SetPriority; S13: Set initial serial port parameters; S14: Initialize the timer interface void init_timer(uint8_t id, bool state, uint16_t n); S15: Initialize the Flash operation interface function void Flash_IF_Init(void); S16: Initialize the switch operation interface. Initialize the switch: int8_t initGpio(uint8_t index, uint8_t dir); Step 2: Serial port operation driver interface; Step S21: Provide a data sending interface; Step S22: Provide a data receiving interface; Step 3: Timer interrupt driver interface; The timer interrupt handling interface is a function that is called for each interrupt, allowing users to manage time through this interface. The timer interrupt handling interface void timer_handler() includes the following sub-steps: S31: Use the library function timer_interrupt_flag_get to check if the interrupt flag TIMER_INT_UP is set. If it is, proceed to the next step; otherwise, exit the process and wait for the next interrupt. S32: Use the library function timer_interrupt_flag_clear to clear the interrupt flag TIMER_INT_UP; S33: Records the timer's flag incrementing; S34: Divide the flag by integers according to user requirements to obtain the number of time intervals of other magnitudes; Step 4: Flash operation driver functions; First, provide interface functions for writing to Flash; then provide interface functions for reading from a fixed address in Flash. Specifically, it includes the following sub-steps: S41: Flash fixed address writing interface function: int16_t Flash_WriteByte(IO uint32_t address, uint32_t ... The buffer (uint16_t length) is implemented as follows: S411: Use the library function fmc_sector_erase to erase the contents of a fixed sector region address; S412: Determine if the length len of the data to be written is greater than 0. If it is, proceed to the next step; otherwise, return 1 and exit the process. S413: Use the library function fmc_word_program to write data stored in the buffer starting from the fixed address of flash, and determine whether the write operation is successful. If it is, proceed to the next step; otherwise, return -1 and exit the process. S414: Use the library function REG32 to read back the data stored at the address and determine whether it is consistent with the content stored at the address of the data buffer to be written. If it is, proceed to the next step; otherwise, return -2 and exit the process. S415: Move the Flash address forward by 4 positions; S416: The data buffer's head pointer moves one position; S417: Subtract 1 from the length len of the data to be written; S418: Return to step S412; S42: Function to read Flash fixed address: uint32_t Flash_ReadByte(uint8_t The implementation is as follows: (data, uint16_t len, __IO uint32_t address). S421: Check if the address is valid. If it is, proceed to the next step; otherwise, return 0. S422: Check if the length len of the data to be read is greater than 0. If it is, proceed to the next step; otherwise, return 1. S423: Use the library function REG32 to read data from a fixed address and store it at the address pointed to by the data storage buffer pointer data; S424: Move to read address; S425: Move storage data buffer; S426: Decrement the data length by 1; S427: Return to step S422; Specifically, a return value of 1 indicates that the serial port number parameter is invalid; a return value of -1 indicates that the write operation failed; a return value of 0 indicates that the program has ended; and a return value of -2 indicates that the data is inconsistent. Step 5: Switch operation driver interface First, set up the switch status interface; then, obtain the switch status interface. Specifically, it includes the following sub-steps: S51: Setting the switch status interface: int8_t IoRelayWrite(uint8_t index, int8_t high_or_low), implemented as follows: S511: Macro definition of GPIO group and GPIO group sequence number; S512: Check if the index is valid. If it is, proceed to the next step; otherwise, return -1 and exit. S513: Obtain the GPIO group and sequence number id based on the input sequence number index; S514: Determine if the set value high_or_low is 1. If it is, use the library function gpio_bit_set to set the switch with the sequence number id in the current GPIO group to 1; otherwise, set it to 0. S515: Returns 1; S52: Interface for obtaining switch status: FlagStatus IoReadBack(uint8_t index), the specific implementation is as follows: S521: Macro definition of GPIO group and GPIO group sequence number; S522: Determine if the index is valid. If it is, proceed to the next step; otherwise, return -1 and exit. S523: Obtain the GPIO group and sequence number id based on the input sequence number index; S524: Use the library function gpio_input_bit_get to get the status value (status) of the switch quantity with the sequence number id in the current group; S525: Returns status; The return value of 1 indicates that the serial port number parameter is invalid; the return value of -1 indicates that the write operation failed.
2. The low-level driver design method based on board interface as described in claim 1, characterized in that, The process of step S13 is as follows: S131: Set the initial serial port parameter interface name to InitUserSerial; S132: Set the input parameters of the interface function InitUserSerial to the serial port number and baud rate; S133: Sets the serial port name macro definition, assigns serial port numbers to the Uart and Usart types of board resources, and uniformly schedules them to users as USER_COM_X, where X is the serial number; users do not distinguish between the two types of serial ports. S134: Sets the reset clock macro definition for the transmitter's general purpose input / output (GPIO) pins; S135: Sets the reset clock macro definition for the receiver's general purpose input / output (GPIO) pins; S136: Set the serial port reset clock macro definition; S137: Macro definition for setting the GPIO pin number sequence for serial port transmission; S138: Sets the GPIO pin number sequence macro definition for serial port reception; S139: Set the GPIO group macro definition for serial port transmission; S1310: Sets the GPOO group macro definition for serial port reception; S1311: Sets the macro definition for the GPIO spare function pins for serial port transmission and reception; S1312: Set the macro definition for the serial port interrupt number; S1313: Determine if the serial port number of the input parameter is out of bounds. If it is, return and exit; otherwise, proceed to the next step. S1314: Enables the serial port's receive, transmit, and port reset clock; S1315: Use system functions to set the spare GPIO function pins for serial port transmission and reception; S1316: Sets the pin mode of the serial port transmit and receive GPIO: input or output; S1317: Configure the output options for the GPIO pin of the serial port transmit function; S1318: Disabled serial port; S1319: Set the serial port baud rate, data bits, stop bits, and parity bits; S1320: Disable serial port hardware flow control operation; S1321: Enable serial port transmit and receive functions.
3. The low-level driver design method based on board interface as described in claim 2, characterized in that, The process of step S14 is as follows: S141: Enable the timer clock for the input ID number; S142: Configure the timer's division ratio; S143: Reset timer; S144: Set timer mode; S145: Set the timer frequency n; S146: Configure the timer using configuration parameters; S147: Enable Automatic Reload Shadow Register; S148: Clear timer interrupt flag; S149: Interrupt enable; S1410: Enable timer based on input parameter state.
4. The low-level driver design method based on board interface as described in claim 3, characterized in that, The process of step S15 is as follows: S151: Use the library function fmc_unlock to unlock the flash address; S152: Use the library function fmc_flag_clear to clear the operation flag.
5. The low-level driver design method based on board interface as described in claim 4, characterized in that, The process of step S16 is as follows: S161: Macro definition of GPIO group clock, GPIO group type, and GPIO group sequence number; S162: Determine if the input GPIO index is valid. If it is, proceed to the next step; otherwise, return 0. S163: Use the index entered by the user to obtain the GPIO group and the index within the GPIO group; S164: Enables the GPIO clock; S165: Determine whether the GPIO direction value input by the user is an input or an output. If it is an input, use the library function gpio_mode_set to set the GPIO represented by the index as an input switch value. Otherwise, set the GPIO as an output switch value. S166: Use the library function gpio_output_options_set to set gpio attributes; S167: Return 1; The return value is 1, indicating that the serial port number parameter is invalid; and 0 indicates that the program has ended.
6. The low-level driver design method based on board interface as described in claim 5, characterized in that, In step S21, the following interfaces are provided according to the data sending requirements of the application layer: S211: Send a single byte at a time: void SerialPutChar(uint8_t c), the steps are as follows: S2111: Send a single byte using the library function usart_data_transmit; S2112: Use the library function usart_flag_get to check in a loop whether the USART_FLAG_TC sending flag has been reset. If it has, wait in the loop; otherwise, exit the loop to indicate that the sending was successful. S212: Send one string at a time: void Serial_PutString(uint8_t s), the steps are as follows: S2121: Loop through and check if the current character is the null terminator '\0'. If it is, exit the sending process; otherwise, proceed to the next step. S2122: Send a single byte using the library function usart_data_transmit; S2123: Use the library function usart_flag_get to check in a loop whether the transmission flag USART_FLAG_TC has been reset. If it has, wait in the loop; otherwise, exit the loop to indicate that the transmission was successful. S2124: Move the string pointer and jump to step S2121; S213: Send a fixed number of bytes each time: uint16_t serial_send(uint8_t ComNum, uint8_t ... pWriteBuffer, uint16_t WriteSize), the steps are as follows: S2131: The serial port name number that can be used by the macro definition; S2132: Check if the serial port number is valid. If it is, exit; otherwise, proceed to the next step. S2133: Loop through and check if the number of writable bytes WriteSize is greater than 0. If WriteSize is greater than 0, subtract 1 from it. If it is, use the library function usart_data_transmit to send the character content pointed to by the current pWriteBuffer. Otherwise, jump to step S2138. S2134: Use the library function usart_flag_get to check in a loop whether the transmission flag USART_FLAG_TC has been reset. If it has, wait in the loop; otherwise, exit the loop to indicate that the transmission was successful and proceed to the next step. S2135: Record the number of bytes sent (count) and increment it by 1; S2136: Move the data transmission pointer pWriteBuffer, i.e., increment it by 1; S2137: Jump to step S2133; S2138: Returns the count of bytes sent; S214: DMA sends fixed bytes: usart_dma_send(uint8_t ComNum, uint8_t ... pWriteBuffer, uint16_t WriteSize); S2141: Clock that enables DMA transfer; S2142: Fixed channel with DMA transfer disabled; S2143: Set initial DMA parameters; S2144: Configure DMA mode; S2145: Disabled cyclic transmission function; S2146: Set up the DMA channel; S2147: Set the starting address for sending; S2148: Set the length of data to be sent; S2149: Use the library function dma_flag_get to get whether the DMA transfer flag DMA_INTF_FTFIF has been reset. If it has, continue the loop; otherwise, it means that the transmission is complete. The process of step S22 is as follows: S221: Receive one byte from the serial port device: uint32_t serialKeyGet(unsigned char comNum, uint8_t The steps are as follows: S2211: Determine if the serial port number is valid. If it is, proceed to the next step; otherwise, return 1 and exit the process. S2212: Use the library function usart_flag_get to determine the value of the receive flag, i.e. whether data has been received. If yes, proceed to the next step; otherwise, return 2 and exit the process. S2213: Use the library function usart_flag_clear to clear the receive flag; S2214: Use the library function usart_data_receive to retrieve the received data and store it in the parameter key; S2215: Returns 0; S222: Read a fixed number of bytes from the serial port: uint16_t serial_recv(uint8_t ComNum, uint8_t ... pReadBuffer, uint16_t ReadSize), implemented as follows: S2221: Initialize the receive data variable key to zero and the receive count to 0; S2222: Determine if the serial port number is valid. If it is, proceed to the next step; otherwise, return 0 to exit the process. S2223: Enter the receiving loop; S2224: Use the receive function serialKeyGet to determine if there is data to be received. If so, store the currently received data content in key and proceed to the next step; otherwise, exit the receive loop and return the count of received data. S2225: Place the received data key into the address pointed to by the receive buffer pointer pReadBuffer; S2226: Move the receive buffer pointer pReadBuffer forward; S2227: Add a value to the record for the number of received data entries; S2228: Determine if the value of count is the number of reads specified by the user (ReadSize). If it is, exit the receiving loop and return the value of count; otherwise, jump to step S2221. S223: DMA receive fixed bytes: usart_dma_recv(uint8_t ComNum, uint8_t pReadBuffer, uint16_t ReadSize); S2231: Clock that enables DMA transfer; S2232: Set initial DMA parameters; S2233: Configure DMA mode; S2234: Disables the fixed channel for DMA receive transmission; S2235: Set the receive start address pReadBuffer; S2236: Set the length of received data (ReadSize); S2237: Set the DMA receive channel; S2238: Disable the loop function of the receive channel; S2239: Peripheral sub-device for setting up the receiving channel; S22310: Use the library function dma_flag_get to get whether the DMA transfer flag DMA_INTF_FTFIF has been reset. If it has, continue the loop; otherwise, it means that the reception is complete. The return value is 1, indicating that the serial port number parameter is invalid; 0 indicates that the program has ended; and 2 indicates that no data has been received.
Citation Information
Patent Citations
Method for realizing Bluetooth serial port based on converged communication terminal
CN101719774A
Video documentation for loss control
US20050283438A1