7 years ago.

My delay function in mbed

Dear All

I have started working on Nucleo-F103RB and started with simple blinky program. I three questions here please f someone came answer. Many thankd in advance: Q1- Why my own delay function like following is not working:

unsigned int i;

void delay(void) { unsigned int x; for(x=0;x<32000;x=x+1); }

Q2- How can I access the functions like I want to know how to initialise the GPIO and other registers on ARM MCU. Q3- I have tried to transfer the project to Keil-MDK but it is not building there as it is saying there is one file missing.

Could you please show us the complete code of your program?

EDITING TIP: You can copy and paste your code here as text and enclose it within <<code>> and <</code>> markers as below (each marker on its own separate line). Then it's going to be shown as code in a frame.

<<code>>
#include "mbed.h"

DigitalOut led1(LED1);

int main()
{
    while (1) {
        led1 = !led1;
        wait(0.5);
    }
}
<</code>>
posted by Zoltan Hudak 11 Apr 2017

1 Answer

7 years ago.

Q1:

The compiler is probably optimizing your delay loop out. Either that or your method of measuring it isn't up to the job, I would expect that to create a delay in the order of 300us on most mbeds. Make X volatile and it will prevent the loop from being optimized out.

However be careful creating delays like this, the length of time you get will depend on the target CPU and its clock speed. using wait_us() for short delays is a far more controlled way of getting a short delay.

Q2:

Look in the mbed-src library, the library will define all of the register names as given in the MCU user manual. Talking directly to the hardware is just a case of setting the registers to the correct value. e.g. on the LPC11U24

LPC_SYSCON->PDSLEEPCFG |= 0x01;

will set the least significant bit of the power down sleep config register within the LPC system config module of the LPC MCU.

Q3:

It would probably help if you told us which file.

When I build the transfered project in MDK, it has one error as below: When build: * Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'NucleoF103RB_Lab2_Ex1-1' compiling main.cpp... mbed/./CAN.h(235): error: #70: incomplete type is not allowed can_t _can; main.cpp: 0 warnings, 1 error ".\BUILD\NucleoF103RB_Lab2_Ex1-1.axf" - 1 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:04

When I run Debeug session, it gives message "Error:Flash Download failed - Could not load file 'C:\Users\ashakil\Documents\MDk\Examples\F103RB\NucleoF103RB_Lab2_Ex1-1\BUILD\NucleoF103RB_LAB2_Ex1-1.axf".

posted by amjad shakil 24 Apr 2017