2023-07-28 05:41 AM
I am trying to implement a driver for an EEPROM. I created as follows:
typedef struct
{
uint16_t address;
uint16_t size;
uint8_t *data;
} test_t;
And create a structure array as:
test_t test[] = {{0x0000, 50, NULL}, {0x00AB, 70, NULL}, {0x0AB0, 98, NULL}, {0x7F0C, 64, NULL}, {0x24AB, 200, NULL}}
I create 5 uint8_t arrays give their address to the pointers inside the structure as:
// Assume I create 5 arrays via a function here
test[0].data = array1;
test[1].data = array2;
.
.
.
Now, I am trying my drivers with this test array,
for(uint8_t var = 0; var 5; ++var)
{
write_function(test[var].address, test[var].data, test[var].size);
read_function(test[var].address, test[var].size, output_array);
}
Assume output is defined somewhere else in the main function and is big enough to hold the data. My intention is that I wanna look at the value of the output_array so that I can deduce whether my driver works or not. In debug mode, if I go over the code step-by-step by using step over button, then eveything works perfectly. However, if I try to use resume button to download the whole code in one shot, then the code gets stucked in HardFault_Handler function, I can understand from the STM32CubeIDE that in HAL_SPI_Transmit function, it is due to the timeout. What is the problem and how can I solve it?
Thanks in advance for your comments.
2023-07-28 06:15 AM
HardFault_Handler indicates there's a bug in your code. The bug doesn't appear to be in the code you provided. Step through your code to find out where it happens, diagnose the issue, and fix the bug.
2023-07-28 06:17 AM
It looks as though your problem is within the write / read functions, so you better show these.
Maybe your read access come too shortly after the write? Maybe you should put these into 2 for loops, or add a delay between write / read.
2023-07-28 06:49 AM - edited 2023-07-28 06:50 AM
Yeah I thought this way, but when I change the code as:
uint16_t addresses[] = {0x0000, 0x00AB, 0x0AB0, 0x7F0C};
uint16_t byte_numbers[] = {50, 70, 98, 200};
uint8_t data0[byte_numbers[0]], data1[byte_numbers[1]], data2[byte_numbers[2]], data3[byte_numbers[3]];
uint8_t* data_ptrs[] = {data0, data1, data2, data3};
uint8_t output_array0[byte_numbers[0]], output_array1[byte_numbers[1]], output_array2[byte_numbers[2]], output_array3[byte_numbers[3]];
uint8_t *output_ptrs[] = {output_array0, output_array1, output_array2, output_array3};
// Assume I fill the arrays via a function here.
for(uint8_t var = 0; var < 4; ++var)
{
write_function(addresses[var], data_ptrs[var], byte_numbers[var]);
read_function(addresses[var], byte_numbers[var], output_ptrs[var]);
}
This time, the code works as expected even I hit the resume.