Accelerating Automotive Code Migration with Generative AI
Migrating automotive codebases is complex, but Generative AI can simplify the process. In this post, we explore how AI tools help developers navigate and adapt code for the Infineon AURIX TC4 microcontroller.
- Retrieve relevant code snippets based on a natural language query.
- Provide explanations or further context about the retrieved code, helping developers understand its purpose and functionality.
- Assist in migrating codebases by identifying and adapting key code segments for the AURIX TC4 microcontroller.
'bedrock-runtime'
and 'bedrock-agent-runtime'
. Finally, it starts an AWS session and retrieves the region name, preparing the script to perform operations with AWS Bedrock.1
2
3
4
5
6
7
8
9
10
11
!pip install boto3
import boto3
from botocore.client import Config
# Initialize configuration and Bedrock clients
bedrock_config = Config(connect_timeout=120, read_timeout=120, retries={'max_attempts': 0})
bedrock_client = boto3.client('bedrock-runtime')
bedrock_agent_client = boto3.client('bedrock-agent-runtime', config=bedrock_config)
boto3_session = boto3.session.Session()
region_name = boto3_session.region_name
retrieve_and_generate
API using a specified Knowledge Base ID (kb_id
). Please replace the dummy Knowledge Base ID with your actual one. It defines three example queries related to the configuration and usage of the VADC (Versatile Analog-to-Digital Converter) module of the Infineon AURIX microcontroller. For each query, it calls the retrieve_and_generate
function to obtain a response and associated citations. The script then prints the query and response, and iterates through the citations to extract and display the URIs of retrieved references from a nested JSON structure. This demonstrates how to interact with the API to retrieve information and references from the knowledge base for specific technical questions.By leveraging this functionality, developers can ask questions about specific information and code examples related to their codebase. It allows them to retrieve answers to their questions and gain a deeper understanding of complex modules without manually sifting through extensive documentation or code, accelerating the development process.The three queries below show how a developer can approach a specific question. They might start with a general question in the area where the answer is expected. With the first answer, the question can be further specified. As a final question, the developer might ask for a code sample.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Ensure you have defined the 'retrieve_and_generate' function in your notebook
# Example queries to test the RetrieveAndGenerate API with the knowledge base
kb_id = "YOUR_KNOWLEDGE_BASE_ID" # Replace with your actual knowledge base ID
# Example query
query = "What is the resolution of an input channel of the Analog-to-Digital Converter (VADC)?"
response_text, citations = retrieve_and_generate(query, kb_id)
print(f"Query: {query}\n\nResponse: {response_text}\nCitations:")
for citation in citations:
# Each citation may contain multiple retrieved references
retrieved_references = citation.get('retrievedReferences', [])
for reference in retrieved_references:
# Access the 'uri' from the nested structure
uri = reference.get('location', {}).get('s3Location', {}).get('uri', '').strip()
print(uri)
# Another query
query = "How do I configure the VADC module?"
response_text, citations = retrieve_and_generate(query, kb_id)
print(f"\nQuery: {query}\n\nResponse: {response_text}\nCitations:")
for citation in citations:
retrieved_references = citation.get('retrievedReferences', [])
for reference in retrieved_references:
uri = reference.get('location', {}).get('s3Location', {}).get('uri', '').strip()
print(uri)
# Another query
query = "Please show me a code example for the configuration of the VADC module."
response_text, citations = retrieve_and_generate(query, kb_id)
print(f"\nQuery: {query}\n\nResponse: {response_text}\nCitations:")
for citation in citations:
retrieved_references = citation.get('retrievedReferences', [])
for reference in retrieved_references:
uri = reference.get('location', {}).get('s3Location', {}).get('uri', '').strip()
print(uri)
s3://micro-controller-migration-dschlei/Infineon-AURIX_ADC_Background_Scan_1_KIT_TC275_LK-TR-Training-v01_00-EN.pdf
- Initialize an instance of the
IfxVadc_Adc_Config
structure with default values using theIfxVadc_Adc_initModuleConfig()
function. - Optionally modify the configuration parameters in the
IfxVadc_Adc_Config
structure as needed, such as setting the digital and analog frequencies, enabling startup calibration, or selecting the low supply voltage. - Apply the configuration to the VADC module using the
IfxVadc_Adc_initModule()
function, passing the VADC module handle and the configuredIfxVadc_Adc_Config
structure.
s3://micro-controller-migration-dschlei/code_examples/ADC_Background_Scan_1_KIT_TC275_LK/Libraries/iLLD/TC27D/Tricore/Vadc/Adc/IfxVadc_Adc.h
s3://micro-controller-migration-dschlei/Infineon-AURIX_ADC_Background_Scan_1_KIT_TC275_LK-TR-Training-v01_00-EN.pdf
- Create a configuration structure
IfxVadc_Adc_Config
and initialize it withIfxVadc_Adc_initModuleConfig()
. - Initialize the VADC module with
IfxVadc_Adc_initModule()
using the configuration from step 1. - Create a group configuration structure
IfxVadc_Adc_GroupConfig
and initialize it withIfxVadc_Adc_initGroupConfig()
. - Configure the group settings like group ID, trigger mode, arbitration, etc., in the group configuration structure.
- Initialize the VADC group with
IfxVadc_Adc_initGroup()
using the group configuration from step 4.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
IfxVadc_Adc_Config adcConfig;
IfxVadc_Adc_initModuleConfig(&adcConfig, &MODULE_VADC);
IfxVadc_Adc vadc;
IfxVadc_Adc_initModule(&vadc, &adcConfig);
IfxVadc_Adc_GroupConfig adcGroupConfig;
IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);
adcGroupConfig.groupId = IfxVadc_GroupId2;
adcGroupConfig.master = adcGroupConfig.groupId;
adcGroupConfig.scanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
adcGroupConfig.arbiter.requestSlotScanEnabled = TRUE;
adcGroupConfig.scanRequest.autoscanEnabled = TRUE;
IfxVadc_Adc_Group adcGroup;
IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
s3://micro-controller-migration-dschlei/code_examples/ADC_Background_Scan_1_KIT_TC275_LK/Libraries/iLLD/TC27D/Tricore/Vadc/Adc/IfxVadc_Adc.h
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.