I am trying to program my STM32f103c8 using STM32Cubemx, code::blocks and CubeMXMakefile.py. The compilation result shows 0 errors and 0 warnings and that flashing was successful but the code (blinking PC13) isn't running on the board.
I installed Stlink by cloning
"https://github.com/texane/stlink" repo, and running make on it and checked if it worked by running lsusb and confirmed that "STMicroelectronics ST-LINK/V2" was detected.
i also had already installed the arm compilers for codeblocks and they seem to work as well.
My issue was mainly at first that the code wouldn't flash to the board and when running " CubeMXMakefile.py . " i would get a warning that st-flash is not installed although it was built from running Make on the clone, and when trying to "make flash" i would get an error that st-flash can't be found in "/usr/local/bin". I solved this issue (i think) by manually copying the the st-flash file from the build/release directory in the clone repo to the path mentioned.
Now the code compiles with no errors in compiling or flashing but the code doesn't work still.
this is the code, all ofcourse generated by cubemx except for the while block:
/**
******************************************************************************
* #file : main.c
* #brief : Main program body
******************************************************************************
** This notice applies to any and all portions of this file
* that are not between comment pairs USER CODE BEGIN and
* USER CODE END. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* COPYRIGHT(c) 2019 STMicroelectronics
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_hal.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* #brief The application entry point.
*
* #retval None
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
/**
* #brief System Clock Configuration
* #retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
/*Configure GPIO pin : PC13 */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* #brief This function is executed in case of error occurrence.
* #param file: The file name as string.
* #param line: The line in file as a number.
* #retval None
*/
void _Error_Handler(char *file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* #brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* #param file: pointer to the source file name
* #param line: assert_param error line source number
* #retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/**
* #}
*/
/**
* #}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
this is the compilation output:
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
-------------- Clean: Release in testagain (compiler: GNU GCC Compiler for ARM)---------------
Executing clean command: make -f Makefile cleanRelease
rm -fR .dep build
Cleaned "testagain - Release"
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
-------------- Build: Release in testagain (compiler: GNU GCC Compiler for ARM)---------------
Scanned 0 files for #includes, cache used 0, cache updated 0
Checking if target is up-to-date: make -q -f Makefile Release
Running command: make -f Makefile Release
mkdir -p build
C. Compiling build/system_stm32f1xx.o...
C. Compiling build/stm32f1xx_hal.o...
C. Compiling build/stm32f1xx_hal_cortex.o...
C. Compiling build/stm32f1xx_hal_dma.o...
C. Compiling build/stm32f1xx_hal_flash.o...
C. Compiling build/stm32f1xx_hal_flash_ex.o...
C. Compiling build/stm32f1xx_hal_gpio.o...
C. Compiling build/stm32f1xx_hal_gpio_ex.o...
C. Compiling build/stm32f1xx_hal_pwr.o...
C. Compiling build/stm32f1xx_hal_rcc.o...
C. Compiling build/stm32f1xx_hal_rcc_ex.o...
C. Compiling build/stm32f1xx_hal_tim.o...
C. Compiling build/stm32f1xx_hal_tim_ex.o...
C. Compiling build/main.o...
C. Compiling build/stm32f1xx_hal_msp.o...
C. Compiling build/stm32f1xx_it.o...
S. Compiling build/startup_stm32f103xb.o...
2019-01-27T23:17:52 INFO common.c: Loading device parameters....
2019-01-27T23:17:52 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-01-27T23:17:52 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
C. Linking build/testagain.elf...
/usr/bin/arm-none-eabi-size build/testagain.elf
text data bss dec hex filename
3560 12 1572 5144 1418 build/testagain.elf
H. Linking build/testagain.hex...
B. Building build/testagain.bin...
Used gcc: 6.3.1
/usr/local/bin/st-flash erase
st-flash 1.5.1-12-g30de1b3
Mass erasing
/usr/local/bin/st-flash --reset write build/testagain.bin 0x8000000
2019-01-27T23:17:52 INFO common.c: Loading device parameters....
2019-01-27T23:17:52 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-01-27T23:17:52 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2019-01-27T23:17:52 INFO common.c: Attempting to write 3572 (0xdf4) bytes to stm32 address: 134217728 (0x8000000)
st-flash 1.5.1-12-g30de1b3
Flash page at addr: 0x08000000 erased
Flash page at addr: 0x08000400 erased
Flash page at addr: 0x08000800 erased
2019-01-27T23:17:52 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2019-01-27T23:17:52 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-01-27T23:17:52 INFO flash_loader.c: Successfully loaded flash loader in sram
Flash page at addr: 0x08000c00 erased
1/4 pages written
2/4 pages written
2019-01-27T23:17:52 INFO common.c: Starting verification of write complete
2019-01-27T23:17:52 INFO common.c: Flash written and verified! jolly good!
3/4 pages written
4/4 pages written
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))
try
st-flash reset
I found my MCU not running code after flashing.
It worked after resetting manually.
If it does not work for you, try this with openOCD.
Tried with OpenOCD, didn't re-flash the device, just "reset run" - and device started working.
https://github.com/texane/stlink/issues/532#issuecomment-286882627
Related
It is code snippet from Linux kernel (arch/arm64/kernel/kaslr.c) how kaslr seeed is obtained:
u64 __init kaslr_early_init(u64 dt_phys)
{
...
/*
* Retrieve (and wipe) the seed from the FDT
*/
seed = get_kaslr_seed(fdt);
/*
* Mix in any entropy obtainable architecturally if enabled
* and supported.
*/
if (arch_get_random_seed_long_early(&raw))
seed ^= raw;
...
}
Does someone can explain why seed is xor'ed with output of arch random instruction (RNDR instruction that appears in ARMV8.5 Random extensions). If we already have bootloader's entropy then why need additionally get arch random?
I'm new to STM32 and I followed the instructions here in order to program my first stm32f103c8t6 board in Ubuntu.
Here is the code which I added to the source code:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
And of course, I have set PA0 port as GPIO_output in STM32CubeMX.
Here is the output of function MX_GPIO_Init:
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
The code builds and uploads successfully to the board. Here is the output for rebuilding the code which builds and uploads the code:
-------------- Clean: Release in sample1 (compiler: GNU GCC Compiler for ARM)---------------
Executing clean command: make -f Makefile cleanRelease
rm -fR .dep build
Cleaned "sample1 - Release"
-------------- Build: Release in sample1 (compiler: GNU GCC Compiler for ARM)---------------
Checking if target is up-to-date: make -q -f Makefile Release
Running command: make -f Makefile Release
mkdir -p build
C. Compiling build/system_stm32f1xx.o...
C. Compiling build/stm32f1xx_hal.o...
C. Compiling build/stm32f1xx_hal_cortex.o...
C. Compiling build/stm32f1xx_hal_dma.o...
C. Compiling build/stm32f1xx_hal_flash.o...
C. Compiling build/stm32f1xx_hal_flash_ex.o...
C. Compiling build/stm32f1xx_hal_gpio.o...
C. Compiling build/stm32f1xx_hal_gpio_ex.o...
C. Compiling build/stm32f1xx_hal_pwr.o...
C. Compiling build/stm32f1xx_hal_rcc.o...
C. Compiling build/stm32f1xx_hal_rcc_ex.o...
C. Compiling build/stm32f1xx_hal_tim.o...
C. Compiling build/stm32f1xx_hal_tim_ex.o...
C. Compiling build/main.o...
C. Compiling build/stm32f1xx_hal_msp.o...
C. Compiling build/stm32f1xx_it.o...
S. Compiling build/startup_stm32f103xb.o...
2018-06-21T10:32:46 INFO usb.c: -- exit_dfu_mode
C. Linking build/sample1.elf...
/usr/bin/arm-none-eabi-size build/sample1.elf
text data bss dec hex filename
3560 20 1572 5152 1420 build/sample1.elf
H. Linking build/sample1.hex...
B. Building build/sample1.bin...
Used gcc: 6.3.1
/usr/local/bin/st-flash erase
2018-06-21T10:32:46 INFO common.c: Loading device parameters....
2018-06-21T10:32:46 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-06-21T10:32:46 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2018-06-21T10:32:46 INFO common.c: Loading device parameters....
2018-06-21T10:32:46 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-06-21T10:32:46 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
st-flash 1.4.0-39-g6db0fc2
Mass erasing
/usr/local/bin/st-flash --reset write build/sample1.bin 0x8000000
2018-06-21T10:32:46 INFO common.c: Attempting to write 3580 (0xdfc) bytes to stm32 address: 134217728 (0x8000000)
st-flash 1.4.0-39-g6db0fc2
Flash page at addr: 0x08000000 erased
Flash page at addr: 0x08000400 erased
Flash page at addr: 0x08000800 erased
2018-06-21T10:32:46 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2018-06-21T10:32:46 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2018-06-21T10:32:46 INFO flash_loader.c: Successfully loaded flash loader in sram
Flash page at addr: 0x08000c00 erased
1/4 pages written
2/4 pages written
2018-06-21T10:32:46 INFO common.c: Starting verification of write complete
2018-06-21T10:32:46 INFO common.c: Flash written and verified! jolly good!
3/4 pages written
4/4 pages written
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
However, the LED does not start to blink as expected. LED works fine when I connect it to 5volt. I have checked the board's pins by AVO meter and they are all connected to the micro-controller.
After a few research, I thought that it has to do something with Boot0 and Boot1 pins so I tried different options from here but none of them worked.
Here is the image of my board:
How can I fix it?
I believe the HAL_Delay function is using systick to count time in ms, systick must be set to 1ms to get the right delay, did you configure that ?
I am not sure how you do this.
If the time between the output toggles is very low, the output will not toggle because you set GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;, try GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; then you can use an oscilloscope to check if it toggles.
If you do not have an oscilloscope at hand, you could try to insert a "while loop" counting towards a high number, instead of the HAL_Delay function.
Counter=0;
while (Counter<500000000)
{
Counter++;
}
Assuming your clock frequency is set at 72MHz, this will give a time in the range of 0.5 to 1 sec.
Remember to declare the variable as integer 32 bit or higher, e.g. uint32_t counter = 0;
If it does not work, set a breakpoint at the HAL_GPIO_Togglepin line, it will then pause at the breakpoint line and every time you click "RUN", it should then run to the breakpoint again and the output should toggle.
I was dealing with the same problem for a week. a simple program for blinking the LED diode in the arduino environment with stm32f103c8t6 was working, the combination of stm32f103c8t6, stm32CubeMX, ubuntu's gcc-arm (gcc-arm-none-eabi version:15:6.3.1+svn253039-1build1) and ubuntu 18.04 does not.
After I installed GNU Embedded Toolchain for Arm the things started to work.
GNU Arm Embedded Toolchain Version 8-2018-q4-major Linux 64 solved my problem.
Your code should work, but you are only toggling an unconnected µC pin.
If you look at the schematics from the "black pill" homepage the LED is connected to
PB12
The BOOT0 pin should be connected to GND if you want to run your firmware (from flash) the BOOT1 pin doesn't matter.
One thing in your image: you don't have a resistor for your LED to limit the current, depending on the LED type this could damage the LED and/or the µC pin.
Maybe you should first try to use D2 from the board and if that works you could switch over to your on LED.
I don't know if you've done a correct initialization of the pin:
PB12 Setup
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
/*Configure GPIO pin : PB12 */
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
The Clock enable is very important for each peripheral.
I had the same problem and I solved that by connecting BOOT0 pin to the ground...
I'm stat()'ing this symlink (on Kubuntu GNU/Linux 16.04), and am getting the weird value of 0100600 octal (33152 decimal). If I bitwise-and it with S_IFMT (which is 0170000 octal), I get 0600 octal. What does that mean? stat.h lists the following values:
/* File types. */
#define __S_IFDIR 0040000 /* Directory. */
#define __S_IFCHR 0020000 /* Character device. */
#define __S_IFBLK 0060000 /* Block device. */
#define __S_IFREG 0100000 /* Regular file. */
#define __S_IFIFO 0010000 /* FIFO. */
#define __S_IFLNK 0120000 /* Symbolic link. */
#define __S_IFSOCK 0140000 /* Socket. */
I'm expecting to see 0120000, not 0600 (all octal). What gives?
Based on #dave_thompson_085's observation: Indeed, stat() follows symlinks; I should be calling lstat() - which does exactly the same thing, but doesn't follow the link.
I have a simple kernel extension:
kern_return_t HelloWorld_start (kmod_info_t *ki, void * d) {
printf("Hello World\n");
return KERN_SUCCESS;
}
kern_return_t HelloWorld_stop (kmod_info_t * kid, void * d) {
printf("Goodbye World\n");
return KERN_SUCCESS;
}
Which I'm compiling and loading via:
sudo kextload HelloWorld.kext
And it appears in the kextstat listing:
...
129 0 0xffffff7f80fac000 0x4000 0x4000 com.apple.driver.AppleProfileThreadInfoAction (85.2) <123 6 4 3 1>
130 0 0xffffff7f80fb0000 0x4000 0x4000 com.apple.driver.AppleProfileTimestampAction (85.2) <123 5 4 3 1>
132 0 0xffffff7f807c6000 0x2000 0x2000 sk-r-d.HelloWorld (1) <4>
However, I have nothing in kernel.log (or system.log) - I should be seeing my printf() statements. Any idea why?
For some reason the console app doesn't seem to display printf messages from kexts, but the log console program does.
I've had success with the following magic words...
log stream --predicate 'eventMessage contains "YourMatchingPatternHere"'
This will produce a filtered stream showing only messages that match your predefined pattern.
sudo nvram boot-args="kext-dev-mode=1 debug=0x22"
I - an embedded beginner - am fighting my way through the black magic world of embedded programming. So far I won already a bunch of fights, but this new bug seems to be a hard one.
First, my embedded setup:
Olimex STM32-P207 (STM32F207)
Olimex ARM-USB-OCD-H JTAG
OpenOCD
Eclipse (with CDT and GDB hardware debugging)
Codesourcery Toolchain
Startup file and linker script (adapted memory map for the STM32F207) for RIDE (what uses GCC)
STM32F2xx_StdPeriph_Lib_V1.1.0
Using the many tutorials and Q&As out there I was able to set-up makefile, linker and startup code and got some simple examples running using STM's standard library (classic blinky, using buttons and interrupts etc.). However, once I started playing around with the SysTick interrupts, things got messy.
If add the SysTick_Config() call to my code (even with an empty SysTick_Handler), ...
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
[...]
*/
if (SysTick_Config(SystemCoreClock / 120000))
{
// Catch config error
while(1);
}
[...]
... then my debugger starts at the (inline) function NVIC_SetPriority() and once I hit "run" I end up in the HardFault_Handler().
This only happens, when using the debugger. Otherwise the code runs normal (telling from the blinking LEDs).
I already read a lot and tried a lot (modifying compiler options, linker, startup, trying other code with SysTick_Config() calls), but nothing solved this problem.
One thing could be a hint:
The compiler starts in both cases (with and without the SysTick_Config call) at 0x00000184. In the case without the SysTick_Config call this points at the beginnig of main(). Using SysTick_Config this pionts at NVIC_SetPriority().
Does anybody have a clue what's going on? Any hint about where I could continue my search for a solution?
I don't know what further information would be helpful to solve this riddle. Please let me know and I will be happy to provide the missing pieces.
Thanks a lot!
/edit1: Added results of arm-none-eabi-readelf, -objdump and -size.
/edit2: I removed the code info to make space for the actual code. With this new simplified version debugging starts at
08000184: stmdaeq r0, {r4, r6, r8, r9, r10, r11, sp}
readelf:
[ 2] .text PROGBITS 08000184 008184 002dcc 00 AX 0 0 4
...
2: 08000184 0 SECTION LOCAL DEFAULT 2
...
46: 08000184 0 NOTYPE LOCAL DEFAULT 2 $d
main.c
/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint16_t counter = 0;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void assert_failed(uint8_t* file, uint32_t line);
void Delay(__IO uint32_t nCount);
void SysTick_Handler(void);
/**
* #brief Main program
* #param None
* #retval None
*/
int main(void)
{
if (SysTick_Config(SystemCoreClock / 12000))
{
// Catch config error
while(1);
}
/*
* Configure the LEDs
*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); // LEDs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIOF->BSRRL = GPIO_Pin_6;
while (1)
{
if (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_9) == SET)
{
GPIOF->BSRRH = GPIO_Pin_9;
}
else
{
GPIOF->BSRRL = GPIO_Pin_9;
}
Delay(500000);
}
return 0;
}
#ifdef USE_FULL_ASSERT
/**
* #brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* #param file: pointer to the source file name
* #param line: assert_param error line source number
* #retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* #brief Delay Function.
* #param nCount:specifies the Delay time length.
* #retval None
*/
void Delay(__IO uint32_t nCount)
{
while (nCount > 0)
{
nCount--;
}
}
/**
* #brief This function handles Hard Fault exception.
* #param None
* #retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* #brief This function handles SysTick Handler.
* #param None
* #retval None
*/
void SysTick_Handler(void)
{
if (counter > 10000 )
{
if (GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_8) == SET)
{
GPIOF->BSRRH = GPIO_Pin_8;
}
else
{
GPIOF->BSRRL = GPIO_Pin_8;
}
counter = 0;
}
else
{
counter++;
}
}
/edit3:
Soultion:
Because the solution is burrowed in a comment, I put it up here:
My linker file was missing ENTRY(your_function_of_choice); (e.g. Reset_Handler). Adding this made my debugger work again (it now starts at the right point).
Thanks everybody!
I have a strong feeling that the entry point isn't specified correctly in the compiler options or linker script...
And whatever code comes first at link time in the ".text" section, it gets to have the entry point.
The entry point, however, should point to a special "init" function that would set up the stack, initialize the ".bss" section (and maybe some other sections as well), initialize any hardware that's necessary for basic operation (e.g. the interrupt controller and maybe some system timer) and any remaining portions of the and standard libraries before actually transferring control to main().
I'm not familiar with the tools and your hardware, so I can't say exactly what that special "init" function is, but that's pretty much the problem. It's not being pointed to by the entry point of the compiled program. NVIC_SetPriority() doesn't make any sense there.