Implement Versuch4 (functional, tested)
This commit is contained in:
parent
2e1f37bddf
commit
8eef31f3d8
File diff suppressed because one or more lines are too long
9
Versuch4/Core/Inc/versuch4_write-file.h
Normal file
9
Versuch4/Core/Inc/versuch4_write-file.h
Normal file
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* versuch4_write-file.c
|
||||
*
|
||||
* Created on: Dec 1, 2025
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
void versuch4_write_file(void);
|
||||
|
||||
@ -39,6 +39,9 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
|
||||
/* ToDo: Include headers for RTOS/mutex, declare mutex */
|
||||
|
||||
extern SRAM_HandleTypeDef hsram2;
|
||||
@ -49,19 +52,21 @@ extern SRAM_HandleTypeDef hsram2;
|
||||
#define DISPLAY_ABS(X) ((x) > 0 ? (x) : -(x))
|
||||
#define DISPLAY_LIMIT( x, min, max ) {if( x < min ) x = min; else if( x > max ) x = max; }
|
||||
|
||||
SemaphoreHandle_t Mutex_Display = NULL;
|
||||
|
||||
static char Display_LineBuffer[64]; // Buffer for printf
|
||||
|
||||
// Display_Select: Called before any access to the display.
|
||||
// Return: 0: Error, do not access the display
|
||||
// 1: OK, access the display
|
||||
uint8_t Display_Select( void ) {
|
||||
/* ToDo: Take mutex */
|
||||
xSemaphoreTake(Mutex_Display, portMAX_DELAY);
|
||||
return 1; // OK
|
||||
}
|
||||
|
||||
// Display_Deselect: Called after any access to the display.
|
||||
void Display_Deselect( void ) {
|
||||
/* ToDo: Give mutex */
|
||||
xSemaphoreGive(Mutex_Display);
|
||||
}
|
||||
|
||||
/*************************************************************************************************************
|
||||
@ -813,5 +818,5 @@ void Display_Init( void ) {
|
||||
Display_Clear_( LCD_COLOR_BLACK ); // Use variant without select/deselect to ignore OS and Mutex here!
|
||||
}
|
||||
|
||||
/* ToDo: Create Mutex */
|
||||
Mutex_Display = xSemaphoreCreateMutex();
|
||||
}
|
||||
|
||||
@ -136,10 +136,80 @@ void drawButton(bool isPressed){
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define BUTTON_PLUS 0
|
||||
#define BUTTON_MINUS 1
|
||||
#define BUTTON_PLAY 2
|
||||
#define BUTTON_PAUSE 3
|
||||
#define BUTTON_STOP 4
|
||||
|
||||
// helper to create all gui buttons at startup
|
||||
void createGuiElements(){
|
||||
printf("creating GUI elements\r\n");
|
||||
GUI_AddButton(5, 88, "+", BUTTON_PLUS);
|
||||
GUI_AddButton(5, 170, "-", BUTTON_MINUS);
|
||||
GUI_AddButton(110, 5, "PLAY", BUTTON_PLAY);
|
||||
GUI_AddButton(110, 88, "PAUSE", BUTTON_PAUSE);
|
||||
GUI_AddButton(110, 170, "STOP", BUTTON_STOP);
|
||||
}
|
||||
|
||||
|
||||
// helper to update volume value on display
|
||||
uint8_t volume = 70;
|
||||
void drawVolume(){
|
||||
Display_Printf( 0, 40,
|
||||
LCD_COLOR_WHITE, LCD_COLOR_BLACK,
|
||||
&FontBig,
|
||||
"%03d", volume
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//==========================
|
||||
//==== Task definitions ====
|
||||
//==========================
|
||||
|
||||
void Task9_receiveGuiEvents(void *){
|
||||
uint8_t gui_msg = 0;
|
||||
|
||||
//initially draw volume
|
||||
drawVolume();
|
||||
|
||||
// receive gui events
|
||||
while(1){
|
||||
if (xQueueReceive(GUIQueue, &gui_msg, portMAX_DELAY)){
|
||||
printf("Received GUI event %d\n", gui_msg);
|
||||
|
||||
switch(gui_msg){
|
||||
case BUTTON_PLUS:
|
||||
if (++volume > 100) volume = 100;
|
||||
drawVolume();
|
||||
break;
|
||||
|
||||
case BUTTON_MINUS:
|
||||
if (volume-- == 0) volume = 0;
|
||||
drawVolume();
|
||||
break;
|
||||
|
||||
case BUTTON_PLAY:
|
||||
printf("Play\r\n");
|
||||
break;
|
||||
|
||||
case BUTTON_PAUSE:
|
||||
printf("Pause\r\n");
|
||||
break;
|
||||
|
||||
case BUTTON_STOP:
|
||||
printf("Stop\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Task0_PrintStats(void *){
|
||||
while (1)
|
||||
@ -255,6 +325,20 @@ void Task7_receiveQueueEvents(void *){
|
||||
}
|
||||
|
||||
|
||||
// Task for printing CPU stats via uart and display
|
||||
void Task8_printLoad(void *){
|
||||
while(1){
|
||||
Display_Printf( 0, 0,
|
||||
LCD_COLOR_WHITE, LCD_COLOR_BLACK,
|
||||
&FontBig,
|
||||
"%03d", Usage_GetUsage()
|
||||
);
|
||||
|
||||
Usage_PrintStats();
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
@ -296,6 +380,8 @@ int main(void)
|
||||
Usage_Init();
|
||||
|
||||
Display_Init();
|
||||
|
||||
GUI_Init();
|
||||
// local variables
|
||||
uint32_t timestamp_lastCounted = HAL_GetTick();
|
||||
uint32_t timestamp_lastTouchRead = HAL_GetTick();
|
||||
@ -306,6 +392,8 @@ int main(void)
|
||||
int32_t xTouch, yTouch;
|
||||
|
||||
|
||||
// create gui elements (+ - PLAY PAUSE...)
|
||||
createGuiElements();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@ -335,17 +423,20 @@ int main(void)
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
xTaskCreate(Task1_blinkGreenLed, "Task1_green-led", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task2_blinkBlueLed, "Task2_blue-led", 256, NULL, 0, NULL);
|
||||
//xTaskCreate(Task1_blinkGreenLed, "Task1_green-led", 256, NULL, 0, NULL);
|
||||
//xTaskCreate(Task2_blinkBlueLed, "Task2_blue-led", 256, NULL, 0, NULL);
|
||||
|
||||
uint32_t delay1 = 150;
|
||||
xTaskCreate(Task3_4_blinkRedLed, "Task3_red-led-150", 256, (void *)&delay1, 0, NULL);
|
||||
uint32_t delay2 = 600;
|
||||
xTaskCreate(Task3_4_blinkRedLed, "Task4_red-led-600", 256, (void *)&delay2, 0, NULL);
|
||||
//uint32_t delay1 = 150;
|
||||
//xTaskCreate(Task3_4_blinkRedLed, "Task3_red-led-150", 256, (void *)&delay1, 0, NULL);
|
||||
//uint32_t delay2 = 600;
|
||||
//xTaskCreate(Task3_4_blinkRedLed, "Task4_red-led-600", 256, (void *)&delay2, 0, NULL);
|
||||
|
||||
xTaskCreate(Task5_readButton, "Task5_read-button", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task6_countButtonPresses, "Task6_countButtonPresses", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task7_receiveQueueEvents, "Task7_receiveQueueEvents", 256, NULL, 0, NULL);
|
||||
//xTaskCreate(Task5_readButton, "Task5_read-button", 256, NULL, 0, NULL);
|
||||
//xTaskCreate(Task6_countButtonPresses, "Task6_countButtonPresses", 256, NULL, 0, NULL);
|
||||
//xTaskCreate(Task7_receiveQueueEvents, "Task7_receiveQueueEvents", 256, NULL, 0, NULL);
|
||||
|
||||
xTaskCreate(Task8_printLoad, "Task8_stats", 256, NULL, 0, NULL);
|
||||
xTaskCreate(Task9_receiveGuiEvents, "Task9_GUI", 256, NULL, 0, NULL);
|
||||
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
||||
|
||||
85
Versuch4/Core/Src/versuch4_write-file.c
Normal file
85
Versuch4/Core/Src/versuch4_write-file.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* versuch4_write-file.c
|
||||
*
|
||||
* Created on: Dec 1, 2025
|
||||
* Author: jonny
|
||||
*/
|
||||
|
||||
#include "versuch4_write-file.h"
|
||||
#include "fatfs.h"
|
||||
|
||||
|
||||
void versuch4_write_file(void)
|
||||
{
|
||||
FATFS fs;
|
||||
FIL fp;
|
||||
FRESULT res;
|
||||
|
||||
// mount fs
|
||||
printf("1. mounting filesystem...\n");
|
||||
res = f_mount(&fs, "/", 0);
|
||||
if (res != FR_OK){
|
||||
printf("Fehler beim mounten vom dateisystem\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// open file
|
||||
printf("2. opening file...\n");
|
||||
res = f_open(&fp, "test-asd.txt", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (res != FR_OK)
|
||||
{
|
||||
printf("Fehler beim Oeffnen der Datei!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// write file
|
||||
printf("3. writing file...\n");
|
||||
UINT numBytesWritten = 0;
|
||||
char buf[] = "heute ist der 02.12.2025";
|
||||
res = f_write(&fp, buf, strlen(buf), &numBytesWritten);
|
||||
if (res != FR_OK || numBytesWritten == 0)
|
||||
printf("Fehler beim schreiben der datei\n");
|
||||
|
||||
printf("wrote %d bytes\n", numBytesWritten);
|
||||
|
||||
// close file
|
||||
printf("4. closing file...\n");
|
||||
f_close(&fp);
|
||||
|
||||
|
||||
// open file
|
||||
printf("5. opening file...\n");
|
||||
res = f_open(&fp, "test-asd.txt", FA_READ);
|
||||
if (res != FR_OK)
|
||||
{
|
||||
printf("Fehler beim Oeffnen der Datei!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// read file
|
||||
printf("6. reading file...\n");
|
||||
char bufRead[26];
|
||||
uint8_t numBytesRead = 0;
|
||||
|
||||
res = f_read(&fp, bufRead, 25, &numBytesRead);
|
||||
|
||||
printf("read bytes: %d\n", numBytesRead);
|
||||
bufRead[numBytesRead] = 0;
|
||||
//printf("read text: %s\n", bufRead);
|
||||
|
||||
if (res == FR_OK && numBytesWritten > 0){
|
||||
//bufRead[25] = 0;
|
||||
printf("Gelesene Zeichen: %s\n", bufRead);
|
||||
}
|
||||
else
|
||||
printf("Fehler beim lesen der Datei oder weniger als 25 Zeichen\n");
|
||||
|
||||
|
||||
// close file
|
||||
printf("4. closing file...\n");
|
||||
f_close(&fp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -24,6 +24,8 @@
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_msc.h"
|
||||
|
||||
#include "versuch4_write-file.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
@ -102,10 +104,13 @@ static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
|
||||
|
||||
case HOST_USER_DISCONNECTION:
|
||||
Appli_state = APPLICATION_DISCONNECT;
|
||||
printf("USB device disconnected\n\r");
|
||||
break;
|
||||
|
||||
case HOST_USER_CLASS_ACTIVE:
|
||||
Appli_state = APPLICATION_READY;
|
||||
printf("USB device ready\n\r");
|
||||
versuch4_write_file();
|
||||
break;
|
||||
|
||||
case HOST_USER_CONNECTION:
|
||||
|
||||
@ -748,7 +748,7 @@ ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART6_UART_Init-USART6-false-HAL-true,4-MX_FMC_Init-FMC-false-HAL-true,5-MX_I2C3_Init-I2C3-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART6_UART_Init-USART6-false-HAL-true,4-MX_FMC_Init-FMC-false-HAL-true,5-MX_I2C3_Init-I2C3-false-HAL-true,6-MX_FATFS_Init-FATFS-false-HAL-false,7-MX_USB_HOST_Init-USB_HOST-false-HAL-false,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||
RCC.AHBFreq_Value=216000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV4
|
||||
RCC.APB1Freq_Value=54000000
|
||||
@ -766,7 +766,7 @@ RCC.I2C1Freq_Value=54000000
|
||||
RCC.I2C2Freq_Value=54000000
|
||||
RCC.I2C3Freq_Value=54000000
|
||||
RCC.I2SFreq_Value=96000000
|
||||
RCC.IPParameters=AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SRoutputFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,PLLQoutputFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIoutputFreq_Value,PLLSourceVirtual,RNGFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMC2Freq_Value,SDMMCFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,UART7Freq_Value,UART8Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USART6Freq_Value,USBFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAIOutputFreq_Value
|
||||
RCC.IPParameters=AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SRoutputFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,PLLQoutputFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIoutputFreq_Value,RNGFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMC2Freq_Value,SDMMCFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,UART7Freq_Value,UART8Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USART6Freq_Value,USBFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAIOutputFreq_Value
|
||||
RCC.LPTIM1Freq_Value=54000000
|
||||
RCC.LSI_VALUE=32000
|
||||
RCC.MCO2PinFreq_Value=216000000
|
||||
@ -782,7 +782,6 @@ RCC.PLLQoutputFreq_Value=48000000
|
||||
RCC.PLLSAIPCLKFreq_Value=96000000
|
||||
RCC.PLLSAIQCLKFreq_Value=96000000
|
||||
RCC.PLLSAIoutputFreq_Value=96000000
|
||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||
RCC.RNGFreq_Value=48000000
|
||||
RCC.SAI1Freq_Value=96000000
|
||||
RCC.SAI2Freq_Value=96000000
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user