1 / 18

Writing Portable and Robust Firmware in C

Embedded System Design Techniques™. Writing Portable and Robust Firmware in C. Class 3: Uart Driver and Stm32CubeMx. September 2, 2015 Jacob Beningo, CSDP. Course Overview. Portable C Concepts Doxygen and PC-Lint Uart Driver and Stm32CubeMx Assertions and printf Robust Firmware Concepts.

lisagharris
Download Presentation

Writing Portable and Robust Firmware in C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Embedded System Design Techniques™ Writing Portable and Robust Firmware in C Class 3: Uart Driver and Stm32CubeMx September 2, 2015Jacob Beningo, CSDP

  2. Course Overview • Portable C Concepts • Doxygen and PC-Lint • Uart Driver and Stm32CubeMx • Assertions and printf • Robust Firmware Concepts

  3. Session Overview • STM32CubeMx • Uart Driver Architecture • Uart Driver HAL • Uart Driver Implementation • Uart Application Code

  4. Setup Stm32CubeMx USART Settings Keil from Project->Settings GENERATE CODE!

  5. Architecture of a UART Driver • 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. UART Driver - Design 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. UART Driver - Design 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. UART Driver HAL Step 4 – Convert interface to a header file void Uart_Init(constUartConfig_t *Config); uint8_t Uart_PutChar(UartChannel_t Channel, char Ch ); uint8_t Uart_GetChar(UartChannel_t Channel); void Uart_SetBaud(constUartConfig_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( intToPrint, UartChannel_t Channel ); void Uart_PutHexWord( unsigned intToPrint, 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);

  9. UART Driver - Design Step 5 – Define underlying types and definitions typedefenum { UART1, UART2, UART_MAX_CHANNEL }UartChannel_t; typedefenum { UART_STOP1, UART_STOP2, UART_MAX_STOP }UartStop_t; Consult the Datasheet! typedefstruct { UartChannel_tUartChannel; UartState_tUartState; . . UartStop_tStopBits; }UartConfig_t; typedefenum { UART_DISABLE, UART_ENABLE, UART_MAX_STATE }UartState_t;

  10. Uart Driver Init

  11. Uart Driver Tx

  12. Uart Driver Rx

  13. Driver Testing // 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. A Ring Buffer Application

  15. A Ring Buffer Application

  16. Testing the Application // main.c Uart_AppInit(); // tsk_100ms.c Uart_AppTx(Buffer, 14);

  17. 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 under - Blog and Articles > Software Techniques > CEC Writing Portable and Robust Firmware in C

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

More Related