/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stdio.h" #include "sni.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); /* USER CODE BEGIN PFP */ static int32_t java_thread_id; int buttonIRQ(int button_index); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ //--------------------------------------------------------------------------------- // EXTI Line9 External Interrupt ISR Handler CallBackFun void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == GPIO_PIN_9) // If The INT Source Is EXTI Line9 (A9 Pin) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_8); // Toggle The Output (LED) Pin printf("Hello, World! printf function is working.\n"); buttonIRQ(10); } } //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- int _write(int file, char *ptr, int len) { HAL_UART_Transmit(&huart2,(uint8_t*)ptr,len,HAL_MAX_DELAY); char newline[] = "\r\n"; HAL_UART_Transmit(&huart2,(uint8_t*)newline,2,HAL_MAX_DELAY); return len; } //--------------------------------------------------------------------------------- //********** MicroEJ Initialize ************** //----------------------------------------------------------------- void javaWorldTask() { int32_t err; int32_t exitCode; void* myVM; myVM = SNI_createVM(); if (myVM == NULL) { printf("Failed to create the Java world\n"); } else { err = SNI_startVM(myVM, 0, NULL); if(err < 0) { printf("VM ends with error (%ld)\n", err); } else { exitCode = SNI_getExitCode(myVM); printf("Java exit code = %ld\n", exitCode); } SNI_destroyVM(myVM); } } //----------------------------------------------------------------- int buttonIRQ(int button_index){ SNI_resumeJavaThreadWithArg(java_thread_id, (void*)button_index); return 0; } jint waitButton_callback() { int button_index; SNI_getCallbackArgs(NULL, (void*)&button_index); return (jint)button_index; // Actual value returned to Java } jint Java_com_mycompany_Main_waitButton(){ java_thread_id = SNI_getCurrentJavaThreadID(); SNI_suspendCurrentJavaThreadWithCallback(0, (SNI_callback)waitButton_callback, NULL); return SNI_IGNORED_RETURNED_VALUE; // Returned value not used } int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ //-------------------------------------------------------------- /* Invoke MicroEJ Core Engine */ javaWorldTask(); //SNI_startVM(SNI_createVM(), 0, NULL); //_____________________ //Java_com_mycompany_Main_waitButton(); //waitButton_callback(); //--------------------------------------------------------------- /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }