- Looked into best ways to handle and log/output (HAL) errors:
- Google Gemini: Handling HAL Error in Embedded C
- Researched handling non-recoverable hardwre failures
- Learned usefullness of tokens __FILE__ and __LINE__ for loggiing and debugging
- Google Gemini: Understanding Executable Programs Sections
- Gained deeper understanding of the <project name>.list file, as well as where and how program file (.elf file) is transfered to the microcontroller
- Section of notice - Using Flash Memory for Persistent Logging I think this was when I confirmed I would store errors and meta data in FLASH
- Important functions HAL_FLASH_UNLOCK(), HAL_FLASH_Program(), HAL_FLASH_ErasePage()
- Realized I need to make a struct to combine all the data I want to log
- First learned that I need to and how to modify the .ld (linker script) file
- STM32CubeIDE user guide - User manual also contained info on modifying Linker script to reserve sections of Flash memory
- Gained deeper understanding of the <project name>.list file, as well as where and how program file (.elf file) is transfered to the microcontroller
- Google Gemini: STM32 HAL Flash Programming Explained
- Helped me address issues with storing data in Flash
- Gave me a fix on how to re-order elements in my log_struct to avoid padding with member values, allowing all of the data to fit within 8 bytes
- Google Gemini: Handling HAL Error in Embedded C
- ***For a long time my original completed program size was nearly 32KB, due to that there wasn't enough space for me to reserve the last page for error logging. Then I removed the pow(...) function from the math.h library from my float2string API, and the size of the program reduced by about 10kB, allowing me to reserve the last page of FLASH**
- Google Gemini: Debugging Flash Erase Error
- Learned I could look and modify the memory of the microcontroller with the STM32CubeProgrammer
- Target not halted error:
- Once I realized I had 10kB of space to work with I tried to debug with openOCD
- unfortunately, due to the fact that "STM32G030/G031/G041 family multiplexes BOOT0 with SWCLK (PA14) to save pins on smaller packages" ... "That means every time the debugger toggles SWCLK (PA14), it risks altering BOOT0’s logic level during reset or startup."
- So even though the ST-LINK successfully connected to the microcontroller, OpenCD and CubeIDE couldn't halt the microcontroller
- a Grounding Resistor at Boot0/SWCLK could solve the problem, but it is not guaranteed
- Google Gemini: Debugging Flash Erase Error
- Page 8 of stm32g030c6 data sheet stated that " Information on memory mapping and control registers is object of reference manual RM0454"
- From RM0454 learned/confirmed that that:
- Flash memory size: 32 KB, page size: 2KB
- Flash memory starts at 0x08000000
- Last page of Flash memory: 0x0800F800
- One 'word' is 32 bits, 4 bytes
- It is only possible to program Flash memory with a double word (2x32 bits = 64 bits = 8 bytes) at a time
- Also, each double word must be aligned with a double word address
- Made new structure - typedef struct log_struct_t
- char b0: will always equal 'I' indicates that this double word Index of Flash does store an error log, also to show then the next value will be the log index
- uint8_t error_count: 2KB/ 8 bytes = 256 possible indexes, value should match the index long is stored at
- char source: 'M' for taking place in beginninig of main function, 'O' if error takes place during 'regular operation', possible values are subject to changed
- char b2: will always be 'T', indicates that the next value will be the code for the type of error that is stored
- uint8_t err_type: One of the possible NHD_LCDstatus_t values
- char b1: will always be 'L' indicates that the next value will be the line number
- uint16_t: the value of __LINE__ where the error took place
Ghani Lawal
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.