Hey guys I am a new comer in this embedded era.So I need some support regarding code debugging. I am using embedded pi(stm32f103rbt6) board and keil tool. While debugging in some places of my code I am getting hard fault.
Generally it is coming after calling some function.If I am making parameters of that called function global(declaring and defining above to main()) then code is working fine.
But if those parameters definitions are inside main then its giving hard fault.
Can anyone suggest me how to resolve this issue.
Below I am providing main.c file
/** * Sample program that reads tags for a fixed period of time (500ms) * and prints the tags found. * @file read.c */ #include <tm_reader.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <inttypes.h> //global declaration/definition TMR_Reader r, *rp; TMR_Status ret; TMR_ReadPlan plan; TMR_Region region; TMR_Region region ; uint8_t *antennaList = NULL; uint8_t antennaCount = 0x0; TMR_String model; char str[64]; int main(int argc, char *argv[]) { rp = &r; ret = TMR_create(rp, "tmr:///com1"); ret = TMR_connect(rp); region = TMR_REGION_NA; ret = TMR_paramSet(rp, TMR_PARAM_REGION_ID, ®ion); model.value = str; model.max = 64; TMR_paramGet(rp, TMR_PARAM_VERSION_MODEL, &model); if (((0 == strcmp("Sargas", model.value)) || (0 == strcmp("M6e Micro", model.value)) ||(0 == strcmp("M6e Nano", model.value))) && (NULL == antennaList)) { // fprintf(stdout, "Module doesn't has antenna detection support please provide antenna list\n"); // usage(); } /** * for antenna configuration we need two parameters * 1. antennaCount : specifies the no of antennas should * be included in the read plan, out of the provided antenna list. * 2. antennaList : specifies a list of antennas for the read plan. **/ // initialize the read plan ret = TMR_RP_init_simple(&plan, antennaCount, antennaList, TMR_TAG_PROTOCOL_GEN2, 1000); /* Commit read plan */ ret = TMR_paramSet(rp, TMR_PARAM_READ_PLAN, &plan); ret = TMR_read(rp, 500, NULL); if (TMR_ERROR_TAG_ID_BUFFER_FULL == ret) { /* In case of TAG ID Buffer Full, extract the tags present * in buffer. */ while (TMR_SUCCESS == TMR_hasMoreTags(rp)) { TMR_TagReadData trd; char epcStr[128]; char timeStr[128]; ret = TMR_getNextTag(rp, &trd); } TMR_destroy(rp); return 0; }
Thanks in advance. I am eagerly waiting for getting some positive solutions.
Understand how much space the local/auto variables need, and make the stack large enough to accommodate them. Stack size usually defined in startup.s, and is usually very small.
Delays in milliseconds?
Configure a timer to tick one tick per millisecond.
Then write a delay function that polls this timer value in a busy-loop until the timer has ticked the required number of milliseconds.
Or implement an interrupt handler and configure the timer to generate an interrupt after the number of milliseconds you want to wait - then let the interrupt handler set a flag that your main loop may look at.