Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver.

Similar presentations


Presentation on theme: "Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver."— Presentation transcript:

1 Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver and Stm32CubeMx Embedded System Design Techniques™

2 Presented by: © 2015 Jacob Beningo All Rights Reserved Course Overview Portable C Concepts Doxygen and PC-Lint Uart Driver and Stm32CubeMx Assertions and printf Robust Firmware Concepts 2

3 Presented by: © 2015 Jacob Beningo All Rights Reserved Session Overview STM32CubeMx Uart Driver Architecture Uart Driver HAL Uart Driver Implementation Uart Application Code 3

4 Presented by: © 2015 Jacob Beningo All Rights Reserved Setup Stm32CubeMx 4 USART Settings Keil from Project- >Settings GENERATE CODE!

5 Presented by: © 2015 Jacob Beningo All Rights Reserved Architecture of a UART Driver 5 Many different ways to organize code Break the code up into different layers – Driver Layer Contains MCU peripheral drivers Generic initialization functions Mcu start-up code and copy down Possibly BSP for external chips

6 Presented by: © 2015 Jacob Beningo All Rights Reserved UART Driver - Design 6 Step 1 – Identify WHAT the module needs to do USART Driver Initialize USART Pins and Peripheral Transmit byte data Receive byte data Step 2 – Identify WHAT is needed by each module task USART Driver Initialize USART Pins and Peripheral Input: configuration data Transmit byte data Input: char byte Input: USART channel Receive byte data Input: USART channel Output: char byte

7 Presented by: © 2015 Jacob Beningo All Rights Reserved UART Driver - Design 7 Step 3 – Determine the data types USART Driver Initialize USART Pins and Peripheral Input: configuration data Type: UartConfig_t Transmit byte data Input: char byte uint8_t / char Input: USART channel UartChannel_t Receive byte data Input: USART channel Type: UartChannel_t Output: char byte Type: chart / uint8_t

8 Presented by: © 2015 Jacob Beningo All Rights Reserved UART Driver HAL 8 void Uart_Init(const UartConfig_t *Config); uint8_t Uart_PutChar(UartChannel_t Channel, char Ch ); uint8_t Uart_GetChar(UartChannel_t Channel); void Uart_SetBaud(const UartConfig_t *Config, uint8_t Channel); uint8_t Uart_IsDataPresent(UartChannel_t Channel); void Uart_PrintString( char *Str, UartChannel_t Channel ); void Uart_PutDec(uint8_t Dec, UartChannel_t Channel ); void Uart_PutHex( int ToPrint, UartChannel_t Channel ); void Uart_PutHexWord( unsigned int ToPrint, UartChannel_tChannel ); void Uart_PutHexDWord( unsigned long ToPrint, UartChannel_t Channel ); uint8_t Uart_Char2Hex(char Ch); uint8_t Uart_Hex2Char(char Hex); void Uart_TxIFClear(UartChannel_t Channel); Step 4 – Convert interface to a header file

9 Presented by: © 2015 Jacob Beningo All Rights Reserved UART Driver - Design 9 typedef enum { UART1, UART2, UART_MAX_CHANNEL }UartChannel_t; typedef struct { UartChannel_t UartChannel; UartState_t UartState;. UartStop_t StopBits; }UartConfig_t; Step 5 – Define underlying types and definitions typedef enum { UART_DISABLE, UART_ENABLE, UART_MAX_STATE }UartState_t; typedef enum { UART_STOP1, UART_STOP2, UART_MAX_STOP }UartStop_t; Consult the Datasheet!

10 Presented by: © 2015 Jacob Beningo All Rights Reserved Uart Driver Init 10

11 Presented by: © 2015 Jacob Beningo All Rights Reserved Uart Driver Tx 11

12 Presented by: © 2015 Jacob Beningo All Rights Reserved Uart Driver Rx 12

13 Presented by: © 2015 Jacob Beningo All Rights Reserved Driver Testing 13 // Add to Task_100ms.c static uint8_t Buffer[14] = "Hello World!\n"; static uint8_t Index = 0; Uart_PutChar(UART1, Buffer[Index]); Index = (Index + 1) % 14; TxPin = PA_9 RxPin = PA_10

14 Presented by: © 2015 Jacob Beningo All Rights Reserved A Ring Buffer Application 14

15 Presented by: © 2015 Jacob Beningo All Rights Reserved A Ring Buffer Application 15

16 Presented by: © 2015 Jacob Beningo All Rights Reserved Testing the Application 16 // tsk_100ms.c Uart_AppTx(Buffer, 14); // main.c Uart_AppInit();

17 Presented by: © 2015 Jacob Beningo All Rights Reserved Additional Resources Download Course Material for – Updated C Doxygen Templates (May 2015) – Example source code – Templates Microcontroller API Standard EDN Embedded Basics Articles Embedded Bytes Newsletter From www.beningo.com underwww.beningo.com - Blog and Articles > Software Techniques > CEC Writing Portable and Robust Firmware in C 17

18 Presented by: © 2015 Jacob Beningo All Rights Reserved Jacob Beningo Principal Consultant P.O. Box 400 Linden, Michigan 48451 www.beningo.com : jacob@beningo.com : 810-844-1522 : Jacob_Beningo : Beningo Engineering : JacobBeningo : Embedded Basics Newsletters Embedded Bytes http://bit.ly/1BAHYXm Training MicroPython Bootloaders Low Power Design Real-time Software C/C++ Embedded 18


Download ppt "Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver."

Similar presentations


Ads by Google