### Complete Interrupt Setup Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Interrupts-and-Events.md A comprehensive example demonstrating the setup of GPIO, UART, and Timer interrupts, including global interrupt enabling and a main loop to handle events. ```c #include "ti_msp_dl_config.h" #include "zf_driver_gpio.h" #include "zf_driver_uart.h" #include "zf_driver_timer.h" // Global interrupt flags volatile uint8_t button_pressed = 0; volatile uint32_t timer_tick = 0; // GPIO interrupt (external) void GPIO_A_IRQHandler(void) { uint32_t status = DL_GPIO_getRawInterruptStatus(GPIO_A, DL_GPIO_PIN_3); if (status & DL_GPIO_PIN_3) { button_pressed = 1; DL_GPIO_clearInterruptStatus(GPIO_A, DL_GPIO_PIN_3); } } // Timer interrupt (periodic) void timer_handler(void) { timer_tick++; } // UART interrupt (data received) void uart_handler(uint32_t state, void *ptr) { if (state & UART_INTERRUPT_STATE_RX) { uint8_t byte; if (uart_query_byte(UART_0, &byte) == ZF_TRUE) { // Echo received byte uart_write_byte(UART_0, byte); } } } int main(void) { SYSCFG_DL_init(); // Setup GPIO gpio_init(A3, GPI, 0, GPI_PULL_UP); // Button input DL_GPIO_enableInterrupt(GPIO_A, DL_GPIO_PIN_3); // Setup UART uart_init(UART_0, 115200, UART0_TX_A0, UART0_RX_A1); uart_set_callback(UART_0, uart_handler, NULL); uart_set_interrupt_config(UART_0, UART_INTERRUPT_CONFIG_RX_ENABLE); // Setup Timer timer_init(TIMER_TIM_A0, 1000); // 1 kHz timer_set_callback(TIMER_TIM_A0, timer_handler); timer_set_interrupt(TIMER_TIM_A0, 1); timer_start(TIMER_TIM_A0); // Setup GPIO LED output gpio_init(A5, GPO, 0, GPO_PUSH_PULL); // Enable all interrupts __enable_irq(); // Main loop while (1) { // Handle button press if (button_pressed) { button_pressed = 0; uart_write_string(UART_0, "Button pressed\r\n"); gpio_toggle_level(A5); } // Handle periodic timer if (timer_tick >= 1000) { // Every 1 second timer_tick = 0; uart_write_string(UART_0, "Tick\r\n"); } // Other main loop tasks } return 0; } ``` -------------------------------- ### Basic FreeRTOS Task Creation and Scheduler Start Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/System-Overview.md Demonstrates the fundamental setup for using FreeRTOS within the SDK. It includes creating a simple task and starting the RTOS scheduler. Ensure SYSCFG_DL_init() is called before task creation. ```c #include "FreeRTOS.h" #include "task.h" void task1(void *param) { while (1) { // Task work vTaskDelay(pdMS_TO_TICKS(100)); } } int main(void) { SYSCFG_DL_init(); // Create tasks xTaskCreate(task1, "Task1", 256, NULL, 1, NULL); // Start scheduler vTaskStartScheduler(); return 0; } ``` -------------------------------- ### I2C Controller Example Initialization Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/i2c_controller/README.md Indicates that the I2C driver initialization is complete by turning on LED0. This is the initial output when the example starts. ```text Starting the i2ccontroller example ``` -------------------------------- ### SPI Controller Example Output Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/spi_controller/README.html This is the expected output when running the SPI controller example. It shows the initialization of the controller and the messages exchanged with the peripheral. ```text Starting the SPI controller example Controller SPI initialized Controller received: Hello from peripheral, msg#: 0 Controller received: Hello from peripheral, msg#: 1 Controller received: Hello from peripheral, msg#: 2 Controller received: Hello from peripheral, msg#: 3 Controller received: Hello from peripheral, msg#: 4 Controller received: Hello from peripheral, msg#: 5 Controller received: Hello from peripheral, msg#: 6 Controller received: Hello from peripheral, msg#: 7 Controller received: Hello from peripheral, msg#: 8 Controller received: Hello from peripheral, msg#: 9 Done ``` -------------------------------- ### GPIO Toggle Output Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/gpio_toggle_output/README.html This example demonstrates how to toggle a GPIO output pin. It requires initialization of the GPIO module and the specific pin as an output. ```c #include int main(void) { // Initialize the device and board peripherals Device_init(); // Enable the GPIO peripheral GPIO_enableModule(); // Configure GPIO Port A, Pin 0 as an output GPIO_setAsOutputPin(GPIOA0); // Loop forever while(1) { // Toggle the output pin GPIO_toggleOutputPin(GPIOA0); // Delay for a short period for(volatile int i = 0; i < 100000; i++); } } ``` -------------------------------- ### Example Output Snippet Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/adc_singlechannel/README.html This snippet shows the expected output format when running the ADC single channel example, including raw and converted results for ADC channels. ```text Starting the adcsinglechannel example CONFIG_ADC_0 raw result: 4095 CONFIG_ADC_0 convert result: 3300000 uV CONFIG_ADC_1 raw result (0): 0 CONFIG_ADC_1 convert result (0): 0 uV . . . . . . . . . CONFIG_ADC_1 raw result (9): 0 CONFIG_ADC_1 convert result (9): 0 uV ``` -------------------------------- ### Timer Callback Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Common-Types.md Example of implementing and setting a void callback for timer interrupts. ```c void timer_interrupt(void) { // Called on timer overflow } timer_set_callback(TIMER_TIM_A0, timer_interrupt); ``` -------------------------------- ### SPI Controller Example Output Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/spi_controller/README.md This is the expected output when running the SPI controller example. It shows the initialization, received messages from the peripheral, and completion of the communication loop. Ensure the controller runs before the peripheral for proper synchronization. ```text Starting the SPI controller example Controller SPI initialized Controller received: Hello from peripheral, msg#: 0 Controller received: Hello from peripheral, msg#: 1 Controller received: Hello from peripheral, msg#: 2 Controller received: Hello from peripheral, msg#: 3 Controller received: Hello from peripheral, msg#: 4 Controller received: Hello from peripheral, msg#: 5 Controller received: Hello from peripheral, msg#: 6 Controller received: Hello from peripheral, msg#: 7 Controller received: Hello from peripheral, msg#: 8 Controller received: Hello from peripheral, msg#: 9 Done ``` -------------------------------- ### Correcting Missing SYSCFG_DL_init() Call Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/System-Overview.md Illustrates the correct sequence for initializing GPIO pins. The wrong example shows direct initialization without system configuration, while the correct example first calls SYSCFG_DL_init() to set up clocks and system settings. ```c // Wrong - clocks not initialized gpio_init(A5, GPO, 0, GPO_PUSH_PULL); // Correct - initialize system first SYSCFG_DL_init(); gpio_init(A5, GPO, 0, GPO_PUSH_PULL); ``` -------------------------------- ### Main Function - OPA Inverting PGA with DAC Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/opa_inverting_pga_with_dac/README.html The main function orchestrates the OPA inverting PGA with DAC example. It initializes the system, configures the OPA and DAC, and then continuously sets the gain using the DAC. ```c int main(void) { // Initialize system clock and peripherals SYSCFG_init(); GPIO_init(); OPA_initInvertingPGADAC(); // Set initial gain using DAC OPA_setInvertingPGADACGain(DAC_VOLTAGE_HALF_SCALE); // Main loop while (1) { // Example: Cycle through different gain settings OPA_setInvertingPGADACGain(DAC_VOLTAGE_HALF_SCALE); SYSTICK_delayMs(1000); OPA_setInvertingPGADACGain(DAC_VOLTAGE_FULL_SCALE); SYSTICK_delayMs(1000); OPA_setInvertingPGADACGain(DAC_VOLTAGE_ZERO_SCALE); SYSTICK_delayMs(1000); } } ``` -------------------------------- ### Multi-Channel Scanning Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/ADC-Driver.md Shows how to initialize and read multiple ADC channels sequentially. This pattern is useful for monitoring several analog inputs. ```c void scan_analog_inputs(void) { // Initialize multiple channels adc_init(ADC0_CH0_A27, ADC_12BIT); // Temperature sensor adc_init(ADC0_CH1_A26, ADC_12BIT); // Voltage monitor adc_init(ADC0_CH2_A25, ADC_12BIT); // Current sensor // Read all channels uint16_t temp_raw = adc_convert(ADC0_CH0_A27); uint16_t voltage_raw = adc_convert(ADC0_CH1_A26); uint16_t current_raw = adc_convert(ADC0_CH2_A25); // Process readings float temperature = convert_temp(temp_raw); float supply_voltage = convert_voltage(voltage_raw); float current = convert_current(current_raw); } ``` -------------------------------- ### SPI Peripheral Example Output Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/spi_peripheral/README.md This is the expected output when running the SPI peripheral example. It shows the initialization, received messages from the controller, and completion of the communication loop. ```text Starting the SPI peripheral example Peripheral SPI initialized Peripheral received: Hello from controller, msg#: 0 Peripheral received: Hello from controller, msg#: 1 Peripheral received: Hello from controller, msg#: 2 Peripheral received: Hello from controller, msg#: 3 Peripheral received: Hello from controller, msg#: 4 Peripheral received: Hello from controller, msg#: 5 Peripheral received: Hello from controller, msg#: 6 Peripheral received: Hello from controller, msg#: 7 Peripheral received: Hello from controller, msg#: 8 Peripheral received: Hello from controller, msg#: 9 Done ``` -------------------------------- ### POSIX Threads Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/kernel/posix_demo/README.html Demonstrates the creation and management of POSIX threads. This snippet is useful for understanding concurrent execution within the RTOS. ```c #include #include #include #include void *thread_function(void *arg) { printf("Thread started.\n"); // Simulate some work sleep(2); printf("Thread finished.\n"); return NULL; } int main() { pthread_t tid; int ret; printf("Creating thread...\n"); ret = pthread_create(&tid, NULL, thread_function, NULL); if (ret != 0) { perror("pthread_create failed"); return 1; } printf("Waiting for thread to complete...\n"); pthread_join(tid, NULL); printf("Main thread exiting.\n"); return 0; } ``` -------------------------------- ### Main Function with ADC12 Initialization Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/adc12_window_comparator/README.html The main function that initializes the system, configures the ADC12 for window comparator operation, and starts a conversion. ```C int main(void) { /* Stop Watchdog Timer */ WDT_A_hold(WDT_A_BASE); /* Initialize system clock */ Clock_init(); /* Initialize GPIO for LED */ GPIO_setAsOutputPin(LED_PORT, LED_PIN_0); /* Initialize ADC12 for window comparator */ ADC12_initWindowComparator(); ADC12_initInterrupt(); /* Start ADC12 conversion */ ADC12_startConversion(ADC12_BASE, ADC12_MEM_IDX_0, ADC12_START_CONVERSION_NOW); while (1) { /* Enter LPM0 mode */ PCM_gotoLPM0(); } } ``` -------------------------------- ### Typical GPIO Initialization and Usage Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/GPIO-Driver.md Example demonstrating system initialization, LED output, and button input configuration using the ZF wrapper layer. ```c #include "ti_msp_dl_config.h" #include "zf_driver_gpio.h" int main(void) { SYSCFG_DL_init(); // System initialization // Initialize LED output on pin A5 gpio_init(A5, GPO, 0, GPO_PUSH_PULL); // Initialize button input on pin B3 with pull-up gpio_init(B3, GPI, 0, GPI_PULL_UP); while (1) { // Read button state if (gpio_get_level(B3) == 0) { // Button pressed (active low) gpio_high(A5); // Turn on LED } else { gpio_low(A5); // Turn off LED } } return 0; } ``` -------------------------------- ### I2C Controller Initialization for Repeated Start and FIFO Interrupts Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/i2c_controller_rw_repeated_start_fifo_interrupts/README.html Initializes the I2C controller for master mode, configuring clock speed, FIFO thresholds, and enabling interrupts for transmit and receive events. This setup is crucial for handling repeated start conditions and interrupt-driven data transfers. ```C void I2C_controller_init(void) { // Enable I2C controller I2C_enable(I2C_CONTROLLER_0); // Configure I2C controller for master mode I2C_setMasterMode(I2C_CONTROLLER_0, I2C_MASTER_MODE_ENABLE); // Set I2C clock speed to 100 kHz I2C_setClock(I2C_CONTROLLER_0, I2C_CLOCK_100_KHZ); // Configure FIFO thresholds for transmit and receive interrupts I2C_setTxFifoThreshold(I2C_CONTROLLER_0, I2C_TX_FIFO_THRESHOLD_4); I2C_setRxFifoThreshold(I2C_CONTROLLER_0, I2C_RX_FIFO_THRESHOLD_4); // Enable transmit and receive interrupts I2C_enableInterrupt(I2C_CONTROLLER_0, I2C_INT_TX_FIFO_THRESHOLD | I2C_INT_RX_FIFO_THRESHOLD); // Enable I2C controller I2C_enable(I2C_CONTROLLER_0); } ``` -------------------------------- ### Typical Application Initialization Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/System-Overview.md A common pattern for initializing the system and peripherals using the ZF wrapper API. Includes system configuration and essential peripheral setup. ```c #include "ti_msp_dl_config.h" // System configuration #include "zf_driver_gpio.h" // ZF GPIO wrapper #include "zf_driver_uart.h" // ZF UART wrapper // ... other ZF headers as needed int main(void) { SYSCFG_DL_init(); // Initialize system clocks and power // Initialize peripherals using ZF API gpio_init(A5, GPO, 0, GPO_PUSH_PULL); uart_init(UART_0, 115200, UART0_TX_A0, UART0_RX_A1); // Optional: enable interrupts __enable_irq(); // Main application loop while (1) { // Application code } return 0; } ``` -------------------------------- ### Driver Configuration Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/empty_freertos/README.html Illustrates how to configure driver parameters. This typically involves setting up hardware registers or internal data structures based on user-defined settings. ```c typedef struct { uint32_t baudRate; uint8_t dataBits; uint8_t stopBits; } Driver_Config; void Driver_Configure(Driver_Config *config) { // Apply configuration settings to the driver } ``` -------------------------------- ### CRC Calculate Checksum DMA Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/crc_calculate_checksum_dma/README.html This snippet shows the main logic for setting up and running the CRC calculation using DMA. It initializes the CRC module, configures DMA for data transfer, and starts the CRC calculation. ```c #include "ti_drivers_config.h" #include #include #include #include #include /* * * The CRC driver is used to calculate checksums. The DMA driver is used to * transfer data from memory to the CRC peripheral. * * The CRC peripheral is configured to calculate a 16-bit checksum using the * standard CRC-16-CCITT polynomial. The DMA is configured to transfer data * from a source buffer to the CRC peripheral's data input register. * * The example calculates the checksum of a small data buffer and prints the * result to the console. */ /* CRC configuration structure */ static CRC_Handle crcHandle; static CRC_Config crcConfig = { .crcConfig = { .crcMode = CRC_MODE_16_BIT, .polynomial = CRC_POLYNOMIAL_CRC_16_CCITT, .initValue = 0, .xorOut = 0, .dataReverse = false, .remainderReverse = false } }; /* DMA configuration structure */ static DMA_Handle dmaHandle; static DMA_Config dmaConfig = { .dmaChannel = 0, .transferMode = DMA_TRANSFER_MODE_BLOCK, .transferWidth = DMA_TRANSFER_WIDTH_8_BIT, .transferSize = 0, .srcAddr = NULL, .destAddr = (void *) CRC_BASE + CRC_O_DIN, .triggerType = DMA_TRIGGER_TYPE_PERIPHERAL, .triggerSource = DMA_TRIGGER_SOURCE_CRC }; /* Source data buffer */ static uint8_t srcBuffer[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 }; void main(void) { /* Call driver init functions */ CRC_init(); DMA_init(); /* Open CRC driver */ crcHandle = CRC_open(0, &crcConfig); if (crcHandle == NULL) { // Handle error while (1); } /* Open DMA driver */ dmaHandle = DMA_open(0, &dmaConfig); if (dmaHandle == NULL) { // Handle error while (1); } /* Set DMA transfer size and source address */ dmaConfig.transferSize = sizeof(srcBuffer); dmaConfig.srcAddr = srcBuffer; DMA_control(dmaHandle, DMA_CMD_CONFIGURE, &dmaConfig); /* Start CRC calculation */ CRC_calculateChecksum(crcHandle, dmaHandle); /* Wait for CRC calculation to complete */ while (CRC_isBusy(crcHandle)); /* Get the calculated checksum */ uint16_t checksum = CRC_getChecksum(crcHandle); /* Print the checksum (example: using UART or other output) */ // printf("Calculated Checksum: 0x%04X\n", checksum); /* Close drivers */ CRC_close(crcHandle); DMA_close(dmaHandle); while (1); } ``` -------------------------------- ### Basic LED Toggle with SysConfig Initialization Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/README.md This snippet demonstrates a basic 'hello world' style LED toggle using the SysConfig-generated initialization function and a simple delay. It assumes the necessary SysConfig setup for GPIO and delay has been performed. ```c #include "ti_msp_dl_config.h" int main(void) { SYSCFG_DL_init(); while (1) { DL_GPIO_togglePins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN); delay_cycles(32000000); } } ``` -------------------------------- ### Main Function with ADC12 Setup and Loop Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/adc12_triggered_by_timer_event_stop/README.html The main function sets up the system clock, initializes the ADC12 and timer, and then enters an infinite loop. The ADC conversions are handled by interrupts. ```C int main(void) { // Initialize system clock SYSCTL_initClock(SYSCTL_CLOCK_16MHZ); // Initialize ADC12 and Timer ADC12_init(); // Enable global interrupts NVIC_enableInterrupt(NVIC_ADC12); NVIC_enableInterrupt(NVIC_TIMER); CPU_enableInt(); // Main loop while (1) { // ADC conversions are handled by the ISR } } ``` -------------------------------- ### ADC Single Channel Example Output Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/adc_singlechannel/README.md This is an example of the output generated by the adcsinglechannel example. It shows the raw and converted results for ADC0 and ADC1. The actual conversion values may vary based on reference voltage settings. ```text Starting the adcsinglechannel example CONFIG_ADC_0 raw result: 4095 CONFIG_ADC_0 convert result: 3300000 uV CONFIG_ADC_1 raw result (0): 0 CONFIG_ADC_1 convert result (0): 0 uV . . . . . . . . . CONFIG_ADC_1 raw result (9): 0 CONFIG_ADC_1 convert result (9): 0 uV ``` -------------------------------- ### Start Single ADC Conversion Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/ADC-Driver.md Triggers a single ADC conversion start. This function initiates a measurement on the configured channel. ```c void DL_ADC12_startConversion(ADC12_Regs *adc) ``` -------------------------------- ### AES Initialization and Configuration Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/aes_cbc_256_enc_dec/README.html This snippet shows the necessary steps to initialize and configure the AES module for operation. It includes enabling the module and setting the operating mode. ```c void AES_init(void) { // Enable the AES module AES_enableModule(); // Set the operating mode to CBC AES_setMode(AES_MODE_CBC); } ``` -------------------------------- ### Control Timer Start and Stop Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/INDEX.md Starts or stops the operation of a timer instance. Use these functions to manage timer execution. ```c timer_start(); timer_stop(); ``` -------------------------------- ### UART Callback with uint32 Parameter Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Common-Types.md Example of implementing and setting a callback that receives interrupt state via a uint32 parameter. ```c void uart_interrupt(uint32 state) { if (state & UART_INTERRUPT_STATE_RX) { // RX interrupt occurred } } uart_set_callback(UART_0, uart_interrupt, NULL); ``` -------------------------------- ### Initialize System Configuration Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Quick-Start.md Call `SYSCFG_DL_init()` before initializing GPIO to ensure proper system configuration. This is a common solution for GPIO not working. ```c SYSCFG_DL_init() ``` -------------------------------- ### Start Timer Counting Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Timer-Driver.md Starts the specified timer module from its initial value. Use this function to begin timer operations after initialization. ```c timer_start(TIMER_TIM_A0); ``` -------------------------------- ### Basic Driver Initialization Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/rtos/drivers/empty_freertos/README.html This snippet shows the fundamental steps for initializing a driver within the FreeRTOS environment. Ensure all necessary includes and configurations are in place before calling this function. ```c void Driver_Init(void) { // Initialize driver specific structures // Configure hardware peripherals // Register driver with the RTOS } ``` -------------------------------- ### SPI Controller Initialization with DMA and Interrupts Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/spi_controller_fifo_dma_interrupts/README.html This snippet shows the basic setup for the SPI controller, enabling DMA and interrupts. Ensure necessary clocking and pin configurations are done prior to this. ```C void SPI_Controller_FIFO_DMA_Interrupts_init(void) { // Enable SPI controller clocks ClockP_distribute(true); SPI_Controller_init(SPI_CONTROLLER_0); // Configure SPI controller SPI_Controller_setConfiguration(SPI_CONTROLLER_0, &gSPI_Controller_Config); // Enable SPI controller interrupts SPI_Controller_enableInterrupt(SPI_CONTROLLER_0, SPI_CONTROLLER_INTERRUPT_MASK_RX_DMA_DONE | SPI_CONTROLLER_INTERRUPT_MASK_TX_DMA_DONE); // Enable DMA controller and configure channels for SPI DMA_init(); DMA_configureChannel(DMA_CHANNEL_SPI_RX, &gDMA_SPI_RX_Config); DMA_configureChannel(DMA_CHANNEL_SPI_TX, &gDMA_SPI_TX_Config); // Enable SPI controller SPI_Controller_enable(SPI_CONTROLLER_0); } ``` -------------------------------- ### UART Callback with uint32 and Pointer Parameters Example Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Common-Types.md Example demonstrating a callback that handles UART interrupts and accesses user-defined context data via a void pointer. ```c void uart_handler(uint32 state, void *context) { // context points to user data my_struct_t *data = (my_struct_t *)context; if (state & UART_INTERRUPT_STATE_RX) { // Process received byte uint8 byte; if (uart_query_byte(UART_0, &byte) == ZF_TRUE) { data->rx_count++; } } } // Set up callback with context my_struct_t my_data = {0}; uart_set_callback(UART_0, uart_handler, &my_data); ``` -------------------------------- ### GPIO Get Level Function Signature Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Common-Types.md Shows the function signature for getting the current level of a GPIO pin. The function returns a uint8 representing the level (0 or 1). ```c uint8 gpio_get_level(gpio_pin_enum pin); // Returns uint8 (0 or 1) ``` -------------------------------- ### Main Function Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/spi_controller_repeated_fifo_dma_interrupts/README.html The main function sets up the SPI controller, DMA, and interrupts, then initiates a data transfer. It serves as the entry point for the example application. ```c int main(void) { uint32_t txBuffer[16] = {0}; uint32_t rxBuffer[16] = {0}; uint32_t i; // Initialize system clock and peripherals SYSCFG_ClockEnable(SYSCFG_CLOCK_SPI0); SYSCFG_ClockEnable(SYSCFG_CLOCK_DMA); SYSCFG_ClockEnable(SYSCFG_CLOCK_NVIC); // Initialize SPI Controller, DMA, and Interrupts SPI_Controller_Repeated_FIFO_DMA_Interrupts_init(); // Prepare data for transmission for (i = 0; i < 16; i++) { txBuffer[i] = i; } // Configure DMA for TX and RX SPI_DMA_TX_Channel_Config(txBuffer, 16); SPI_DMA_RX_Channel_Config(rxBuffer, 16); // Enable SPI module SPI_enableModule(SPI0_INST); // Start SPI transfer SPI_setSoftwareReset(SPI0_INST, SPI_SOFTWARE_RESET_ENABLE); SPI_setSoftwareReset(SPI0_INST, SPI_SOFTWARE_RESET_DISABLE); while (1) { // Main loop } } ``` -------------------------------- ### I2C Controller Read Operation after Repeated Start Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/TI_examples/nortos/driverlib/i2c_controller_rw_repeated_start_fifo_interrupts/README.html Performs a read operation from an I2C slave device after a repeated start condition. It sends the slave address with the read bit and then reads the specified number of bytes from the I2C bus. ```C void I2C_controller_read_after_repeated_start(uint8_t slaveAddress, uint8_t *data, uint16_t dataLen) { uint16_t i; // Send slave address with read bit I2C_sendSlaveAddress(I2C_CONTROLLER_0, slaveAddress, I2C_READ); // Read data bytes for (i = 0; i < dataLen; i++) { // Wait for receive FIFO to have data while (I2C_isRxFifoEmpty(I2C_CONTROLLER_0)); data[i] = I2C_receiveData(I2C_CONTROLLER_0); } // Generate stop condition I2C_sendStop(I2C_CONTROLLER_0); } ``` -------------------------------- ### Correcting Missing __enable_irq() Call Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/System-Overview.md Highlights the importance of enabling global interrupts for peripheral interrupts to function. The incorrect example sets up the UART interrupt but fails to enable global interrupts, while the correct example includes the necessary __enable_irq() call. ```c // Wrong - interrupts don't fire uart_set_callback(UART_0, handler); uart_set_interrupt_config(UART_0, UART_INTERRUPT_CONFIG_RX_ENABLE); // Correct - enable global interrupts contentInset(UART_0, handler); uart_set_interrupt_config(UART_0, UART_INTERRUPT_CONFIG_RX_ENABLE); __enable_irq(); ``` -------------------------------- ### Initialize and Set GPIO Pin Source: https://github.com/a-m-o-r-f-a-t-i/mspm0g3507-sdk/blob/main/_autodocs/Quick-Start.md Verify pin configuration by initializing it as a general-purpose output (GPO) and setting it high. This helps confirm voltage output on the pin. ```c // Verify pin is initialized gpio_init(A5, GPO, 0, GPO_PUSH_PULL); gpio_high(A5); // Should see voltage on pin ```