2015-05-06 04:10 AM
Hi All,
I am attempting to update my STM32L152 board over USB using the DFU driver (STM32_USB-FS-Device_Lib_V4.0.0). I generated a .dfu file using ''DFU file Manager'' and the supplied binary_template project. I left all options as default when creating the image.I then uploaded the DFU example project to my board. Held the joystick in the up position and reset the board. Windows detects my board as a ''STM Device in DFU mode'' correctly. I then fired up ''DfuSe Demo'' which detects the dev board and its target memory (i.e. Internal Flash). Again I leave everything at default, choose my .hex image and hit upload. After a couple of seconds I get the message ''Target 00: Upload successful!''. I then click ''Leave DFU mode'' and power cycle my board.However the image I expected to be loaded (a blinking LED demo) does not start! I have tested this demo separately and it works correctly if flashed using a J-LINK.Am I missing anything? Do the boot0 and boot1 switches need to be set in any particular configuration? (I have Boot0 =0 and Boot1 =0 which is correct for User Flash). Does it matter if the board is powered over USB or external? (I am using external PSU).Is it important to set the Vendor, Product and Version ID when generating the .dfu image? I have these set as default (Vendor = 0483, Product = 0000, Version = 0000) Target ID = 0, target Name = ST...2015-05-28 03:43 AM
One thing to point out about the L151. You can not program the Flash memory while running from Flash memory. The code that copies the 32 long's from RAM to Flash to program the Flash must be running from RAM. If you are using IAR EWARM, you can declare a function with the qualifier ''__ramfunc'' and the compiler will copy it to RAM during initialization (just like initializing static variables) and will link it for the destination address in RAM. Nothing special is required to call it. After you have set up everything, you can just call that function to do the deed to one half-page.
The code will look something like this:__ramfunc void __PageWrite(uint32_t *RAM, uint32_t *Flash, uint32_t *FLASH_SR)
{ register int i; for(i=0; i<32; i++) { *Flash++ = *RAM++; } while(*FLASH_SR&1); } This is not finished code, just some high level ideas. For reasons I do not recall, in my code I actually pass a pointer to the FLASH->SR register, rather than using the standard FLASH->SR interface. I think I was trying to minimize the amount of code in RAM. On the EWARM compiler, the arguments automatically become register variables. This means this function does not use any space on the stack and runs completely out of registers. Using only minimal optimization enabled in the compiler, the generated assembly code is as compact as any code written natively in assembly. Now for the potentially fatal flaw in the code. If any code called by an interrupt is running from Flash, this code must be called with interrupts disabled. This means that you either have to relocate your entire DFU application to RAM, or have interrupts disabled for an extended period of time which will make USB extremely unhappy. I hope this helps.2015-05-29 12:46 AM
>One thing to point out about the L151
Thanks for the tips. I am working with a L152, not the L151. I am not sure if this limitation extends to the L152 family?However, as a sanity check. I reserved a portion of flash for my intended downloaded dfu image. I then successfully erased and wrote data to this reserved block while running from flash. Using our debug tools I checked the flash memory and the data is correct.I still believe the problem lies in the flash write routines.
2015-06-01 04:35 AM
hwasti,
I was being naive. Your point was correct, you can not program the Flash memory for any of the L15xx families while running from Flash memory. My flash routines are in fact running from ram. I hadn't played any attention to the qualifier ''__ramfunc'' which is define for the lowest level flash routines being called.However, my previous sanity checks still hold true. I can successfully erase, write and read data from flash memory. I believe my problem lies in correctly aligning the incoming data from USB so that it can be written using half-page programming. Thanks again for the tips!