AWS for Industries

Helping Accelerate AUTOSAR development for Software Defined Vehicles with HAQM Q Developer

The automotive industry is undergoing a transformative shift as vehicles evolve from purely mechanical systems into sophisticated computing platforms. At the heart of this evolution are software-defined vehicles (SDVs), where software capabilities increasingly drive innovation and differentiation in the industry. Modern vehicles now contain up to 100 million lines of code across multiple electronic control units (ECUs), managing everything from safety systems to driver assistance and infotainment features.

Managing hardware and software relationships in automotive systems is challenging, especially when ensuring safety, security, and conformity with industry standards like AUTOSAR (AUTomotive Open System ARchitecture). AUTOSAR serves as the foundation for standardizing automotive embedded software, providing a comprehensive framework that encompasses software architecture, communication protocols, and development methodologies. By adhering to AUTOSAR standards, automakers can help ensure their systems maintain interoperability and scalability while meeting rigorous functional safety requirements.

To help address these challenges, HAQM Q Developer offers a specialized AI-powered coding companion that integrates with popular integrated development environments (IDEs) and the HAQM Web Services, Inc. (AWS) Management Console. It can help automotive software developers by generating and explaining code snippets, providing contextual documentation, offering code suggestions, helping with code refactoring and optimization, assisting in debugging and troubleshooting, and supporting various programming languages including C, C++, and Python. Customers have reported efficiency improvements of 25% faster initial development and up to a 40% increase in developer productivity.

This blog will demonstrate practical examples of how automotive software developers can use HAQM Q Developer to help generate AUTOSAR classic code in C/C++. Additionally, it will explore how to use Python to help streamline the creation of extensible markup language (XML) models that define AUTOSAR software components, showing you how to accelerate your automotive software development workflow while maintaining industry standards.

Prerequisites:

To follow the demonstrations discussed in this blog within your own IDE, ensure that you:

  • Install the HAQM Q Developer plugin for your preferred IDE by following the installation guide; and
  • Set up the Python and C programming environments on your personal computer.
    **HAQM Q Developer is available to customers without an AWS account and falls within the free tier. Customers who are interested in upgrading their HAQM Q Developer license can learn more here.

It is important to note that HAQM Q Developer code generation does not guarantee conformity with any user-defined standard, and developers should check and validate code generated. Additionally, due to the non-deterministic nature of generative AI, HAQM Q Developer may produce different results from those shown in the examples below. Please also recognize that the code examples below are not for production purposes.

Accelerating AUTOSAR classic software development—Solution Overview

To demonstrate how HAQM Q Developer can assist developers, we will walk through three simple examples:

  • Use Case 1 – Making an LED blink and generating unit tests in AUTOSAR C/C++
  • Use Case 2 – Sending a CAN message via an ECU in AUTOSAR C/C++
  • Use Case 3 – Defining package components in AUTOSAR Python

These examples demonstrate common, yet beginner-friendly, use cases of AUTOSAR development. While simplified for learning purposes, they directly map to real-world automotive applications. For example, controlling an LED uses similar logic patterns found in production vehicle lighting systems, such as automatic headlight activation based on ambient light sensors. The CAN messaging example shows how vehicle data is transmitted, like sending speed from transmission ECU to instrument display.

Use Case 1 – Making an LED blink with test cases and generating unit tests in AUTOSAR C/C++

First, let’s demonstrate how HAQM Q Developer’s inline code completion and recommendations can help streamline AUTOSAR development of software developers by automatically generating both functional code and corresponding unit tests to be reviewed by the developer. Using a basic LED blink application as our example, we’ll show how the tool can create an AUTOSAR task and generate unit tests to help verify functionality.

To begin, open the IDE where you installed the HAQM Q Developer plugin as described in the “Prerequisites” section, above. After authenticating into HAQM Q Developer, create a new C file named “examplec1.c” in your project and copy the following sample code into it. This code includes the necessary headers and LED pin configurations for our AUTOSAR-based LED blink application and will provide HAQM Q Developer context as to the type and use case of the code it should generate.

Starting Sample Code:

#include "Dio.h" /* AUTOSAR DIO (Digital Input/Output) module header */
#include "Os.h" /* AUTOSAR OS (Operating System) module header */

/* AUTOSAR RTE (Runtime Environment) generated headers */
#include "Rte_Main.h" 

/* LED pin configuration */
#define LED_PIN 0x01U

Now that we have our basic setup with the LED pin configuration, let’s use HAQM Q Developer to create an AUTOSAR task that will make the LED blink. In your IDE, copy the following comment on a new line under the sample code we copied into the example1.c” file in the previous step as shown below in Figure 1.

Sample Comment:

/* Create an AUTOSAR task for a LED blinking */

Position your cursor at the end of this comment and hit enter. HAQM Q Developer will interpret this comment and generate the appropriate AUTOSAR-compliant code for a blinking LED task.

**Please note: HAQM Q Developer is non-deterministic, meaning there’s no guarantee you will get the same recommendation as shown below**

Figure 1: Using HAQM Q Developer to help generate the blinking LED taskFigure 1: Using HAQM Q Developer to help generate the blinking LED task

To accept the code recommendation, use the Tab key. With that, the file should now look similar to the below code:

Updated sample code:

#include "Dio.h" /* AUTOSAR DIO (Digital Input/Output) module header */
#include "Os.h" /* AUTOSAR OS (Operating System) module header */

/* AUTOSAR RTE (Runtime Environment) generated headers */
#include "Rte_Main.h" 

/* LED pin configuration */
#define LED_PIN 0x01U

/* Create an AUTOSAR task for a LED blinking*/
TASK(LedBlinkTask) {
    static boolean led_state = FALSE;

    /* Toggle LED state */
    led_state = !led_state;

    /* Set LED pin state */
    Dio_WriteChannel(LED_PIN, led_state);
}

Now that we have our AUTOSAR task defined, we need to create the main function that will initialize the required modules and set up the periodic execution of our LED blink task. Add the following comment to prompt HAQM Q Developer to generate the appropriate code:

Sample comment:

/* Create the AUTOSAR main function */ 

Similar to above, we will trigger the HAQM Q Developer inline code completion by going to the end of the comment and clicking enter.

Figure 2 Development of the main functionFigure 2: Development of the main function

As shown in Figure 2, HAQM Q Developer has successfully generated the necessary AUTOSAR initialization and scheduling code for review by the developer. The main function includes StartOS() to initialize AUTOSAR, integrates with LEDBlinkTask, and configures a 500ms timer for LED blinking.

Updated Sample code:

#include "Dio.h" /* AUTOSAR DIO (Digital Input/Output) module header */
#include "Os.h" /* AUTOSAR OS (Operating System) module header */

/* AUTOSAR RTE (Runtime Environment) generated headers */
#include "Rte_Main.h" 

/* LED pin configuration */
#define LED_PIN 0x01U

/* Create an AUTOSAR task for a LED blinking*/
TASK(LedBlinkTask) {
    static boolean led_state = FALSE;

    /* Toggle LED state */
    led_state = !led_state;

    /* Set LED pin state */
    Dio_WriteChannel(LED_PIN, led_state);
}

/* Create the AUTOSAR main function */ 
MAIN(void) {
    /* Initialize AUTOSAR modules */
    StartOS(MainOsInstConst);

    /* Create periodic task for LED blinking */
    GetTaskID(&LedBlinkTaskId);
    SetRelAlarm(LedBlinkTaskId, 500, 500); /* 500ms period */

    return 0;
}

In just minutes, using simple inline comments, we used HAQM Q Developer to help generate AUTOSAR code for an LED blinking task. This example shows how HAQM Q Developer can help accelerate automotive software development by automating tasks based on workspace context. Consider the numerous LEDs in modern SDVs—from hazard lights to dashboard indicators. Each requires specific timing and patterns, all while adhering to strict safety standards the automaker must meet. HAQM Q Developer help automakers accelerate software development by generating code, enabling rapid prototyping while reducing repetitive tasks and maintaining AUTOSAR standards.

Creating test cases

Another valuable feature of HAQM Q Developer is its ability to generate unit tests, helping the software developer ensure that the code meets required specifications and handles edge cases effectively. To demonstrate this capability, we’ll use the LED blink code we generated earlier as a basis for creating comprehensive unit tests. In this process, we will cover both the LEDBlinkTask and the main function. To leverage this feature, we’ll use the HAQM Q Developer chat functionality, which allows for more interactive and context-aware code generation. By prompting HAQM Q Developer with our existing code and specifying our testing requirements, we can quickly generate relevant unit tests that cover various scenarios and edge cases.

To use the HAQM Q Developer chat functionality, highlight the selected code we generated in the previous step and right click. From the dropdown of options select HAQM Q → Send to prompt as shown below in Figure 3.

Figure 3 Sending code to HAQM Q Developer chatFigure 3: Sending code to HAQM Q Developer chat

In the chat enter the following prompt and click Enter:

Create unit test cases for the functions in this file

Figure 4 Generated test cases from HAQM Q Developer chatFigure 4: Generated test cases from HAQM Q Developer chat

HAQM Q Developer is able to generate test cases for the LedBlinkTask and for the main function. This is the updated code below for the test cases for the main function and unit tests generated by HAQM Q Developer:

#include "unity.h"
#include "mock_Dio.h"

void setUp(void) {
    // Initialize any necessary setup
}

void tearDown(void) {
    // Clean up after each test
}

void test_LedBlinkTask_ToggleState(void) {
    // Arrange
    boolean initial_state = FALSE;
    Dio_WriteChannel_Expect(LED_PIN, TRUE);

    // Act
    LedBlinkTask();

    // Assert
    TEST_ASSERT_EQUAL(TRUE, led_state);

    // Act again
    Dio_WriteChannel_Expect(LED_PIN, FALSE);
    LedBlinkTask();

    // Assert
    TEST_ASSERT_EQUAL(FALSE, led_state);
}

void test_LedBlinkTask_CallsDioWriteChannel(void) {
    // Arrange
    Dio_WriteChannel_Expect(LED_PIN, TRUE);

    // Act
    LedBlinkTask();

    // Assert
    // The expectation of Dio_WriteChannel being called is checked implicitly
}
_______
#include "unity.h"
#include "mock_Os.h"
#include "mock_Rte_Main.h"

void setUp(void) {
    // Initialize any necessary setup
}

void tearDown(void) {
    // Clean up after each test
}

void test_MAIN_InitializesOS(void) {
    // Arrange
    StartOS_Expect(MainOsInstConst);
    GetTaskID_Expect(&LedBlinkTaskId);
    SetRelAlarm_Expect(LedBlinkTaskId, 500, 500);

    // Act
    int result = MAIN();

    // Assert
    TEST_ASSERT_EQUAL(0, result);
}

void test_MAIN_CreatesPeriodicTask(void) {
    // Arrange
    StartOS_Ignore();
    GetTaskID_Expect(&LedBlinkTaskId);
    SetRelAlarm_Expect(LedBlinkTaskId, 500, 500);

    // Act
    MAIN();

    // Assert
    // The expectations of GetTaskID and SetRelAlarm being called are checked implicitly
}

Use Case 2 – ECU sending a CAN message

In this example, we’ll use HAQM Q Developer to create a voltage monitoring system, a common requirement in modern vehicles for tracking electrical component health. Specifically, we’ll generate AUTOSAR C code that periodically checks voltage on a pin and sends a controller area network (CAN) message when levels drop below a threshold. This type of functionality is commonly found in automotive systems to monitor the health of electrical components and help detect potential issues.

Open a new HAQM Q Developer chat window and enter the following prompt as shown below (another way to go about this would be using the AWS Command Line Interface (CLI)):

Generate AUTOSAR classic code which will make the ECU send a CAN message with the 4th bit set to 1 when the voltage on pin 1 drops

Figure 5 Opening a new chat window and prompting HAQM QFigure 5: Opening a new chat window and prompting HAQM Q

Using just a simple prompt, HAQM Q Developer generates a complete AUTOSAR classic application for voltage monitoring—no sample code needed. The generated code handles everything from pin monitoring to CAN message transmission, demonstrating HAQM Q Developer’s deep understanding of AUTOSAR architecture and automotive systems. Take a look at the code structure below:

Figure 6 Generated code from the HAQM Q Developer chatFigure 6: Generated code from the HAQM Q Developer chat

Now copy and paste the copy and paste the code into a fresh C file:

/* Include necessary AUTOSAR headers */
#include "Std_Types.h"
#include "Can.h"
#include "CanIf.h"
#include "Com.h"
#include "Dio.h"
#include "Adc.h"

/* Define constants */
#define PIN_1_ADC_CHANNEL 0
#define VOLTAGE_THRESHOLD 2000 // Assuming 2V threshold, adjust as needed
#define CAN_MESSAGE_ID 0x100
#define CAN_MESSAGE_DLC 1

/* Global variables */
static uint8 g_canMessageData = 0x00;
static boolean g_voltageDropDetected = FALSE;

/* Function prototypes */
void InitializeModules(void);
void CheckVoltage(void);
void SendCanMessage(void);

/* Main function */
void MainFunction(void)
{
    InitializeModules();
    
    while(1)
    {
        CheckVoltage();
        if (g_voltageDropDetected)
        {
            SendCanMessage();
        }
    }
}

/* Initialize required modules */
void InitializeModules(void)
{
    /* Initialize ADC */
    Adc_Init(NULL);
    
    /* Initialize CAN */
    Can_Init(NULL);
    CanIf_Init(NULL);
    Com_Init(NULL);
}

/* Check voltage on pin 1 */
void CheckVoltage(void)
{
    Adc_ValueGroupType adcResult;
    
    /* Start ADC conversion */
    Adc_StartGroupConversion(PIN_1_ADC_CHANNEL);
    
    /* Wait for conversion to complete */
    while (Adc_GetGroupStatus(PIN_1_ADC_CHANNEL) == ADC_BUSY) {}
    
    /* Read ADC result */
    Adc_ReadGroup(PIN_1_ADC_CHANNEL, &adcResult);
    
    /* Check if voltage has dropped below threshold */
    if (adcResult < VOLTAGE_THRESHOLD)
    {
        g_voltageDropDetected = TRUE;
    }
    else
    {
        g_voltageDropDetected = FALSE;
    }
}

/* Send CAN message with 4th bit set to 1 */
void SendCanMessage(void)
{
    PduInfoType pduInfo;
    
    /* Set the 4th bit (index 3) to 1 */
    g_canMessageData |= (1 << 3);
    
    /* Prepare PDU info */
    pduInfo.SduDataPtr = &g_canMessageData;
    pduInfo.SduLength = CAN_MESSAGE_DLC;
    
    /* Send CAN message */
    Com_SendSignal(CAN_MESSAGE_ID, &pduInfo);
}

Examining the code generated by HAQM Q Developer, we see a comprehensive structure including variable definitions, a main function, and specialized functions for voltage checking and CAN message transmission. This example demonstrates how HAQM Q Developer can help automotive software developers jumpstart innovation by providing code recommendations. While this code is not production-ready and still requires developer intervention, such as unit testing, checking malformed responses, and more, it provides developers a solid starting point, helping significantly reduce initial development time and helping automotive software development teams focus on customization and optimization for their specific vehicle requirements.

Use Case 3 – Defining Package Components in AUTOSAR Python

Let’s explore our final use case: using HAQM Q Developer to help create AUTOSAR XML files using Python. These XML files are important as they define the building blocks for AUTOSAR Classic components. By starting with a simple Python script that imports the ‘os’ and ‘autosar.xml’ libraries, we’ll demonstrate how HAQM Q Developer can help automate the often-tedious process of AUTOSAR component configuration. We will be using the “AUTOSAR” repository for our sample code.

Open a new Python file in your IDE where you’ve installed HAQM Q Developer. Begin by importing the necessary Python libraries:

Starting Sample Code:

import os
import autosar.xml

Next, using the following sample comment, we can create an entry point for our code by creating an AUTOSAR workspace and package.

Sample Comment:

# Create workspace and packages

Following the previous use case, copy the comment above and press enter to see the HAQM Q Developer code suggestion. Hit tab to accept the code suggestion.

Figure 7 HAQM Q completing the commented section for defining a uint8 base typeFigure 7: HAQM Q completing the commented section for defining a uint8 base type

Updated Sample Code:

import os
import autosar.xml
# Create workspace and packages
ws = autosar.xml.Workspace()

Now that our workspace is set up, let’s update our code to the following

import os
import autosar.xml
# Create workspace and packages
ws = autosar.xml.Workspace()
# Create a package map with parameters base types and implementation data types
ws.create_package_map({"BaseTypes": "DataTypes/BaseTypes",
                            "ImplementationDataTypes": "DataTypes/ImplementationDataTypes"})
print(ws.get_package("BaseTypes").name)

With this code, we’ve created a package map for base types and implementation data types. To accelerate the rest of the functionality, we are printing the base types to allow HAQM Q Developer to learn from previous patterns in the code and autocomplete a new print statement for the implementation data types.

Figure 8 HAQM Q Developer completing the commented sectionFigure 8: HAQM Q Developer completing the commented section for defining a uint8 base type learning from the previous code, HAQM Q Developer can help accelerate repetitive tasks and processes

Updated Sample Code:

import os
import autosar.xml
# Create workspace and packages
ws = autosar.xml.Workspace()
# Create a package map with parameters base types and implementation data types
ws.create_package_map({"BaseTypes": "DataTypes/BaseTypes",
                            "ImplementationDataTypes": "DataTypes/ImplementationDataTypes"})
print(ws.get_package("BaseTypes").name)
print(ws.get_package("ImplementationDataTypes").name)

This example, while simplified for demonstration purposes, shows how HAQM Q Developer can help automotive software developers accelerate the creation of AUTOSAR XML files in Python. Most notably, it demonstrates HAQM Q Developer’s pattern recognition capabilities, By learning from existing code, HAQM Q Developer can provide intelligent suggestions for similar operations, significantly reducing development time. While you’ll need to expand upon this foundation for production use, it illustrates how HAQM Q Developer can help streamline the often-complex process of AUTOSAR component configuration.

Clean up

HAQM Q Developer has a free tier that allows up to 50 interactions with your IDE per month. This demonstration stays below those limits but if you are interested in cleaning up what we did today follow these steps:

  • Delete the files created in your preferred IDE; and
  • Uninstall the HAQM Q Developer extension according to your IDE.

Conclusion

In this blog post, we explored how HAQM Q Developer can help automotive manufacturers accelerate their software development process through AI-powered code recommendations. Through practical examples, we demonstrated three key approaches: (a) using inline comments to help generate AUTOSAR code; (b) using HAQM Q chat to create comprehensive unit tests; and (c) defining AUTOSAR package components in Python. While these examples showcase HAQM Q Developer’s powerful capabilities in reducing development time, it’s important to remember that generated code requires thorough review and customization for production environments. HAQM Q Developer serves as an intelligent assistant to help speed up development cycles and reduce repetitive coding tasks, but it’s designed to complement, not replace, expert software developer judgment and automotive industry best practices.

Learn more about HAQM Q Developer today at the HAQM Q Developer getting started page, or contact your AWS team today.

Brendan Jenkins

Brendan Jenkins

Brendan Jenkins is a solutions architect working with enterprise AWS customers, providing them with technical guidance and helping them achieve their business goals. He specializes in DevOps and machine learning technology.

Eldyn Castillo

Eldyn Castillo

Eldyn Castillo is a Solutions Architect at AWS who works with Automotive and Manufacturing enterprise customers to help them align strategic business needs with technology. He specializes in Developer Experience and DevOps.

Paige Broderick

Paige Broderick

Paige Broderick is a Solutions Architect at AWS who works with enterprise customers to help them achieve their AWS objectives. She specializes in Cloud Operations, focusing on governance and leveraging AWS to develop Smart Manufacturing solutions. Outside of work, Paige is an avid runner and is likely training for her next marathon.